CN103150200A - Computer language transformation system and transformation method from C language to MSVL (Modeling, Simulation and Verification Language) - Google Patents

Computer language transformation system and transformation method from C language to MSVL (Modeling, Simulation and Verification Language) Download PDF

Info

Publication number
CN103150200A
CN103150200A CN2013101201821A CN201310120182A CN103150200A CN 103150200 A CN103150200 A CN 103150200A CN 2013101201821 A CN2013101201821 A CN 2013101201821A CN 201310120182 A CN201310120182 A CN 201310120182A CN 103150200 A CN103150200 A CN 103150200A
Authority
CN
China
Prior art keywords
statement
language
msvl
exp
expression
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Granted
Application number
CN2013101201821A
Other languages
Chinese (zh)
Other versions
CN103150200B (en
Inventor
段振华
于妍
田聪
王小兵
张南
韩萌
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Xidian University
Original Assignee
Xidian University
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Xidian University filed Critical Xidian University
Priority to CN201310120182.1A priority Critical patent/CN103150200B/en
Publication of CN103150200A publication Critical patent/CN103150200A/en
Application granted granted Critical
Publication of CN103150200B publication Critical patent/CN103150200B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Landscapes

  • Devices For Executing Special Programs (AREA)
  • Stored Programmes (AREA)

Abstract

The invention relates to a computer language transformation system. The computer language transformation system is used for transforming C language program into MSVL (Modeling, Simulation and Verification Language) program, and comprises a lexical analysis module, a syntax analysis module and a transformation processing module, wherein the lexical analysis module is used for transforming character sequences into word sequences; the character sequences comprise definitions of key words, identification characters, constants, operators, header files and comment lines in C language; the syntax analysis module is used for identifying specific sentences in C language based on related lexical rules of C language specified in yacc (Yet Another Compiler Compiler); and the transformation processing module is used for transforming C language into MSVL language according to a language transformation rule between C language and MSVL language.

Description

一种计算机语言转换系统及C语言到MSVL语言的转换方法A computer language conversion system and conversion method from C language to MSVL language

技术领域technical field

本发明涉及计算机程序设计语言C语言技术领域,尤其涉及一种C语言结构化语句到MSVL对应语句的转换方法。The invention relates to the technical field of computer programming language C language, in particular to a conversion method from a C language structured statement to an MSVL corresponding statement.

背景技术Background technique

C语言是一种通用的、过程式的编程语言,广泛用于系统与应用软件的开发。具有高效、灵活、功能丰富、表达力强和较高的移植性等特点,在程序员中备受青睐。2011ISO正式公布的C语言新的国际标准草案C11,提高了对C++的兼容性,并将新的特性增加到C语言中。新功能包括支持多线程,基于ISO/IEC TR19769:2004规范下支持Unicode,提供更多用于查询浮点数类型特性的宏定义和静态声明功能。虽然C语言广泛适用于各类系统与软件的开发,但是保证其正确性和安全性成为一个巨大的挑战。模型检测是验证系统正确性的一个有效手段,但要抽取C语言程序的抽象模型成为目前面对的一个难点和挑战。C language is a general-purpose, procedural programming language widely used in the development of systems and application software. It has the characteristics of high efficiency, flexibility, rich functions, strong expressive power and high portability, and is very popular among programmers. The new international standard draft C11 of C language officially announced by ISO in 2011 improves the compatibility with C++ and adds new features to C language. New features include support for multi-threading, support for Unicode based on the ISO/IEC TR19769:2004 specification, and provide more macro definitions and static declaration functions for querying the characteristics of floating-point numbers. Although the C language is widely used in the development of various systems and software, it is a huge challenge to ensure its correctness and security. Model checking is an effective means to verify the correctness of the system, but it has become a difficulty and challenge to extract the abstract model of the C language program.

时序逻辑作为一种系统建模与验证工具已广泛应用于软件工程、数字电路设计等领域。投影时序逻辑(PTL)对ITL进行了扩展,时序逻辑语言MSVL是PTL的一个可执行子集,是一个集建模(Modeling)、仿真(Simulation)和验证(Verification)为一体的时序逻辑程序设计语言,它将系统的建模与性质的描述统一于同一逻辑框架内,通过模型检测技术验证系统的性质。投影时序逻辑在实时和混合系统,特别是安全危急系统的形式描述和验证方面也是极其有用的,例如,载人航天系统是一个复杂的混合实时系统,为了保证系统的安全性和可靠性,传统的测试方法远远不能满足要求,采用形式化的验证技术是十分有用的。As a system modeling and verification tool, sequential logic has been widely used in software engineering, digital circuit design and other fields. Projected Temporal Logic (PTL) extends ITL. Temporal logic language MSVL is an executable subset of PTL. It is a sequential logic programming that integrates modeling (Modeling), simulation (Simulation) and verification (Verification). Language, which unifies the modeling and property description of the system in the same logical framework, and verifies the nature of the system through model checking technology. Projected sequential logic is also extremely useful in formal description and verification of real-time and hybrid systems, especially safety-critical systems. For example, the manned spaceflight system is a complex hybrid real-time system. In order to ensure the safety and reliability of the system, traditional The test method of the test is far from meeting the requirements, and it is very useful to adopt formal verification technology.

另外,投影时序逻辑程序设计语言MSVL的语言结构和C语言极其类似,很容易产生对应的转换关系。通过实现从C语言向MSVL语言的转化,对转化后的目标程序进行验证,利用等价转化的思想,可以实现对C语言形式化模型的抽取,并且可以对该模型进行模型检测,这将大大提高C语言程序的安全性和可靠性。In addition, the language structure of the projected sequential logic programming language MSVL is very similar to the C language, and it is easy to generate the corresponding conversion relationship. By realizing the conversion from C language to MSVL language, and verifying the converted target program, using the idea of equivalent conversion, the extraction of the formal model of C language can be realized, and the model can be tested for the model, which will greatly improve the Improve the security and reliability of C language programs.

发明内容Contents of the invention

本发明提供一种计算机语言转换系统,其能将C语言转换成MSVL语言,以对C语言的程序进行检测。其具体包括,一种计算机语言转换系统,其用于将C语言程序转换成MSVL语言程序,其特征在于:其包括,The invention provides a computer language conversion system, which can convert C language into MSVL language to detect programs in C language. It specifically includes, a computer language conversion system, which is used to convert a C language program into an MSVL language program, characterized in that: it includes,

词法分析模块,其将字符序列转换为单词序列,所述字符序列包括C语言中的关键字、标识符、常数、运算符、头文件以及注释行的定义;A lexical analysis module, which converts the character sequence into a word sequence, and the character sequence includes definitions of keywords, identifiers, constants, operators, header files and comment lines in the C language;

语法分析模块,其基于yacc中所规定的C语言的相关词法规则,进而识别出C语言中特定的语句;The grammatical analysis module, which is based on the relevant lexical rules of the C language specified in yacc, and then identifies specific sentences in the C language;

转换处理模块,其根据C语言与MSVL语言之间的语言转换规律将C语言转换成MSVL语言。The conversion processing module converts the C language into the MSVL language according to the language conversion rule between the C language and the MSVL language.

本发明还提供一种C语言到MSVL语言的转换方法,其提供词法分析模块、语法分析模块及转换处理模块,其特征在于:所述方法包括以下步骤;The present invention also provides a conversion method from C language to MSVL language, which provides a lexical analysis module, a syntax analysis module and a conversion processing module, and is characterized in that: the method includes the following steps;

第一步:将C语言程序导入词法分析模块,该步骤包括将字符序列转换为单词序列,所述字符序列包括C语言中的关键字、标识符、常数、运算符、头文件以及注释行的定义;The first step: the C language program is imported into the lexical analysis module, and this step includes converting the character sequence into a word sequence, and the character sequence includes keywords, identifiers, constants, operators, header files and comment lines in the C language definition;

第二步:将步骤一中得到的单词流导入语法分析模块,该步骤包括基于yacc中所规定的C语言的相关词法规则,进而识别出C语言中特定的语句;Step 2: import the word stream obtained in step 1 into the syntax analysis module, which step includes identifying specific sentences in the C language based on the relevant lexical rules of the C language specified in the yacc;

第三步:将第二步语法分析识别出的C语言语句序列在转换处理模块中根据相应的转换规则转换成对应的MSVL语句;The third step: convert the C language statement sequence identified by the second step grammatical analysis into a corresponding MSVL statement in the conversion processing module according to the corresponding conversion rules;

第四步:用时序操作符“;”连接得到的MSVL语句序列,得到MSVL程序。Step 4: Connect the obtained MSVL statement sequence with the sequence operator ";" to obtain the MSVL program.

在上述技术方案的基础上,语法分析模块中所述的C语言中的结构化语句包括基本表达式语句、while语句、if语句、if-else语句、for语句、switch语句、printf语句以及scanf语句。On the basis of the above technical solution, the structured statements in the C language described in the syntax analysis module include basic expression statements, while statements, if statements, if-else statements, for statements, switch statements, printf statements and scanf statements .

在上述技术方案的基础上,所述语法分析模块中所述的C语言中结构化语句的while语句、for语句的循环体和if语句、if-else语句的条件语句是一个语句块。On the basis of the above technical solution, the while statement of the structured statement in the C language described in the syntax analysis module, the loop body of the for statement, the if statement, and the conditional statement of the if-else statement are a statement block.

在上述技术方案的基础上,所述C语言与MSVL语言之间的语言转换规律包括表达式转换规则、语句转换规则和语句块转换规则。。On the basis of the above technical solution, the language conversion rules between the C language and the MSVL language include expression conversion rules, sentence conversion rules and sentence block conversion rules. .

在上述技术方案的基础上,所述表达式的转化规则如下:On the basis of the above-mentioned technical scheme, the transformation rule of described expression is as follows:

对表达式进行转化,假设x和y是标准符号,e代表一个常量或变量,参照规则如下:Convert the expression, assuming that x and y are standard symbols, and e represents a constant or variable, the reference rules are as follows:

如果表达式为e,则转化为MSVL表达式返回e;If the expression is e, convert it to MSVL expression and return e;

如果表达式为[x++|x--],则转化为MSVL语句x:=x+1and skip或者x:=x-1and skip;If the expression is [x++|x--], it will be transformed into MSVL statement x:=x+1and skip or x:=x-1and skip;

如果表达式为x=y,则转化为MSVL语句x:=y and skip;If the expression is x=y, it will be transformed into MSVL statement x:=y and skip;

如果表达式为x==y,则转化为MSVL语句x==y;If the expression is x==y, it will be transformed into MSVL statement x==y;

如果表达式为x[+,-,*,/,%,!=]y,转化为MSVL表达式x[+,-,*,/,%,!=]y;If the expression is x[+,-,*,/,%,!=]y, it will be converted to MSVL expression x[+,-,*,/,%,!=]y;

如果表达式为x*=y(*=[<|>]),则转化为MSVL表达式x=y或者x*y;If the expression is x*=y(*=[<|>]), it will be converted to MSVL expression x=y or x*y;

如果表达式为x[+|-|*|/|%]=y,则转化为x:=x[+|-|*|/|%]y and skip;If the expression is x[+|-|*|/|%]=y, it is transformed into x:=x[+|-|*|/|%]y and skip;

如果表达式为x&&y,则转化为MSVL语句x and skip;If the expression is x&&y, it will be transformed into MSVL statement x and skip;

如果表达式为x||y,则转化为MSVL语句x or y;If the expression is x||y, it is transformed into the MSVL statement x or y;

如果表达式为x,y,则转化为MSVL语句x,y;If the expression is x, y, it will be converted into MSVL statement x, y;

如果表达式为(x),则转化为MSVL语句为(x);If the expression is (x), it is converted into an MSVL statement as (x);

在上述技术方案的基础上,On the basis of the above technical solutions,

对基本语句进行转化,假设exp是一个常量表达式,block是一个语句块,s代表一个完整的声明,x是一个变量,parameter代表一个字符串,规则参照如下:To convert the basic statement, assuming that exp is a constant expression, block is a statement block, s represents a complete statement, x is a variable, and parameter represents a string, the rules are as follows:

如果语句为空语句,则转化为空语句;If the statement is an empty statement, it is converted to an empty statement;

如果语句为exp,则转化为exp;If the statement is exp, it is converted to exp;

如果语句为x=exp,则转化为x:=exp and skip;If the statement is x=exp, it is transformed into x:=exp and skip;

如果语句为if语句,使用IF语句的转化规则对语句进行转换;If the statement is an if statement, use the conversion rules of the IF statement to convert the statement;

如果语句为while(exp){block},则转化为MSVL语句while(exp){block};If the statement is while(exp){block}, it will be converted into MSVL statement while(exp){block};

如果语句为int声明语句,则使用声明语句的转换规则对语句进行转换;If the statement is an int declaration statement, use the conversion rules of the declaration statement to convert the statement;

如果语句为for(s exp1;exp2){block},则转化为s while(exp){block;exp2};If the statement is for(s exp1;exp2){block}, it will be transformed into s while(exp){block;exp2};

如果语句为printf(“parameter”,exp),则转化为output(exp);If the statement is printf("parameter", exp), it will be converted to output(exp);

如果语句为scanf(“parameter”,exp),则转化为input(exp);If the statement is scanf("parameter", exp), it will be converted to input(exp);

其中,对IF语句的转换规则如下:Among them, the conversion rules for the IF statement are as follows:

若语句形如if(exp)s,转化为if(exp)then{s}If the statement is in the form of if(exp)s, it is transformed into if(exp)then{s}

若语句形如if(exp){block},转化为if(exp)then{s}If the statement is in the form of if(exp){block}, it will be converted into if(exp)then{s}

若语句形如if(exp){block1}else{block2},转化为if(exp)then{block1}else{block2}If the statement is in the form of if(exp){block1}else{block2}, it is transformed into if(exp)then{block1}else{block2}

若语句形如if(exp1){block1}else if(exp2){block2},转化为if(exp1)then{block1}else if(exp2){block2}If the statement is in the form of if(exp1){block1}else if(exp2){block2}, it is converted into if(exp1)then{block1}else if(exp2){block2}

假设var_list代表一列以“,”连接的变量,exp_list代表一列以“,”连接的表达式,ei是在exp_list中出现的一个符号,则声明语句的转换规则如下:Assuming that var_list represents a column of variables connected with ",", exp_list represents a column of expressions connected with ",", and ei is a symbol that appears in exp_list, the conversion rules of the declaration statement are as follows:

如果声明语句为int x,转化为int x;If the declaration statement is int x, convert it to int x;

如果声明语句为int var_list,转化为int var_list;If the declaration statement is int var_list, convert it to int var_list;

如果声明语句为int x=exp,转化为int x;x=exp and skip;If the declaration statement is int x=exp, convert it to int x;x=exp and skip;

如果声明语句为int exp_list,对其中的每一个表达式使用声明语句的规则进行转化,分别转换成对应的独立的MSVL声明语。If the declaration statement is int exp_list, use the rules of the declaration statement to convert each expression in it into the corresponding independent MSVL declaration language.

在上述技术方案的基础上,所述基本语句的转化规则对于语句块的转化,且分别逐条对每条基本语句进行转化,直到语句块中所有语句转化完毕。On the basis of the above technical solution, the conversion rule of the basic sentence is for the conversion of the sentence block, and each basic sentence is transformed one by one until all the sentences in the sentence block are transformed.

相对于现有技术,本发明通过将C语言转换成MSVL语言通过对基本语句的转化定义,可以实现对C程序的转化,并且得到等价的MSVL语言同样可以执行得到C程序的仿真结果。可以将需要验证的性质用MSVL的命题逻辑表示,C程序转换为MSVL程序,因此模型构造与性质描述使用的是同一种语言,使得建模与验证在同一逻辑框架下进行,便可以方便地实现对C语言程序的模型检测。MSVL的建模和模型检测方法的逻辑基础是属于形式化方法的时序逻辑,改发明将非形式化的C语言程序,用形式化的方法对其模型检测,保证了C程序所建的模型进行验证和检测的有效性和可靠性。可以用熟悉的C语言编写程序后,用形式化的语言对其进行模型检测,保证程序安全可靠。Compared with the prior art, the present invention can realize the conversion of C program by converting C language into MSVL language and defining the conversion of basic sentences, and the obtained equivalent MSVL language can also be executed to obtain the simulation result of C program. The properties that need to be verified can be expressed by propositional logic of MSVL, and the C program is converted into an MSVL program. Therefore, the model construction and property description use the same language, so that modeling and verification can be carried out under the same logical framework, which can be easily realized Model checking for C language programs. The logic basis of MSVL's modeling and model checking method is the sequential logic belonging to the formal method, and the non-formal C language program is reformed to use the formal method to check its model, which ensures that the model built by the C program is accurate. Validity and reliability of verification and testing. After the program is written in the familiar C language, it can be model-checked with a formal language to ensure the safety and reliability of the program.

附图说明Description of drawings

图1是本发明对C语言程序模型检测的流程框架图。Fig. 1 is a flow frame diagram of the present invention for C language program model detection.

具体实施方式Detailed ways

本发明提供一种计算机语言转换系统,其能将C语言转换成MSVL语言,以对C语言的程序进行检测。其具体包括,一种计算机语言转换系统,其用于将C语言程序转换成MSVL语言程序,其包括,词法分析模块,词法分析模块将字符序列转换为单词序列,字符序列包括C语言中的关键字、标识符、常数、运算符、头文件以及注释行的定义;还包括语法分析模块,语法分析模块基于yacc中所规定的C语言的相关词法规则,进而识别出C语言中特定的语句;还包括转换处理模块,转换处理模块根据C语言与MSVL语言之间的语言转换规律将C语言转换成MSVL语言。The invention provides a computer language conversion system, which can convert C language into MSVL language to detect programs in C language. It specifically includes, a computer language conversion system, which is used to convert a C language program into an MSVL language program, including a lexical analysis module, which converts a character sequence into a word sequence, and the character sequence includes a key word in the C language. Definition of words, identifiers, constants, operators, header files and comment lines; also includes a syntax analysis module, which identifies specific statements in the C language based on the relevant lexical rules of the C language specified in yacc; It also includes a conversion processing module, which converts the C language into the MSVL language according to the language conversion rules between the C language and the MSVL language.

请参考图1,下面介绍使用本发明计算机语言转换系统将C语言转换成MSVL语言的方法。Please refer to Fig. 1, introduce the method that uses computer language conversion system of the present invention to convert C language into MSVL language below.

第一步:将C语言程序导入词法分析模块,该步骤包括将字符序列转换为单词序列,所述字符序列包括C语言中的关键字、标识符、常数、运算符、头文件以及注释行的定义。The first step: the C language program is imported into the lexical analysis module, and this step includes converting the character sequence into a word sequence, and the character sequence includes keywords, identifiers, constants, operators, header files and comment lines in the C language definition.

经过词法分析后,程序变成了关键字、常数、标识符和运算符的序列,其中C语言程序中的头文件部分和注释部分识别后将被忽略,不会送入下一模块。在上述求最大公约数和最小公倍数的C语言源程序中,用到的词法分析规则有:After lexical analysis, the program becomes a sequence of keywords, constants, identifiers, and operators. Among them, the header file part and comment part in the C language program will be ignored after identification and will not be sent to the next module. In the above C language source program for finding the greatest common divisor and least common multiple, the lexical analysis rules used are:

1.遇到头文件#include<stdio.h>语句,不做任何操作;1. When encountering the #include<stdio.h> statement in the header file, do nothing;

2.遇到关键字返回标记名称,如int返回INT、main返回MAIN;2. When a keyword is encountered, the tag name is returned, such as int returns INT, main returns MAIN;

3.遇到标识符返回给Yacc语法分析器该标记,如num1、num2、a等;3. When encountering an identifier, return the token to the Yacc parser, such as num1, num2, a, etc.;

4.遇到运算符返回运算符的标记名,如!=、=、%、*等;4. When an operator is encountered, return the tag name of the operator, such as !=, =, %, *, etc.;

5.遇到空格被忽略,不做任何操作。5. If a space is encountered, it is ignored and no action is taken.

至此,通过词法规则定义,实现了利用lex词法分析对源语言C语言的程序进行词法分析的功能。So far, through the definition of lexical rules, the function of using lex lexical analysis to perform lexical analysis on programs in the source language C language has been realized.

第二步:将步骤一中得到的单词流导入语法分析模块,该步骤包括基于yacc中所规定的C语言的相关词法规则,进而识别出C语言中特定的语句。Step 2: import the word flow obtained in step 1 into the grammar analysis module, this step includes identifying specific sentences in C language based on the relevant lexical rules of C language specified in yacc.

如图2所示,对输入的C程序用lex词法分析器实现词法分析,生成的单词流和记号流作为yacc语法分析器的输入,语法分析程序根据yacc文件中所规定的C语言的相关词法规则,进而识别出特定的语句,识别出的有:基本表达式语句(如a<b)、while语句和if语句,以及if语句和while语句中的语句块。As shown in Figure 2, the lex lexical analyzer is used to perform lexical analysis on the input C program, and the generated word flow and token flow are used as the input of the yacc grammatical analyzer. Rules, and then identify specific statements, which are: basic expression statements (such as a<b), while statements and if statements, and statement blocks in if statements and while statements.

第三步:将第二步语法分析识别出的C语言语句序列在转换处理模块中根据相应的转换规则转换成对应的MSVL语句;The third step: convert the C language statement sequence identified by the second step grammatical analysis into a corresponding MSVL statement in the conversion processing module according to the corresponding conversion rules;

第四步:用时序操作符“;”连接得到的MSVL语句序列,得到MSVL程序。Step 4: Connect the obtained MSVL statement sequence with the sequence operator ";" to obtain the MSVL program.

语法分析模块中所述的C语言中的结构化语句包括基本表达式语句、while语句、if语句、if-else语句、for语句、switch语句、printf语句以及scanf语句。The structured statements in the C language described in the syntax analysis module include basic expression statements, while statements, if statements, if-else statements, for statements, switch statements, printf statements and scanf statements.

语法分析模块中所述的C语言中结构化语句的while语句、for语句的循环体部分和if语句、if-else语句的条件语句部分被看成是一个语句块。The while statement, the loop body part of the for statement, the if statement, and the conditional statement part of the if-else statement in the structured statement in the C language described in the syntax analysis module are regarded as a statement block.

定义转化规则包括定义对表达式转换规则、语句转换规则和语句块转换规则。Defining conversion rules includes defining pair expression conversion rules, sentence conversion rules and statement block conversion rules.

在上述技术方案的基础上,所述表达式的转化规则如下:On the basis of the above-mentioned technical scheme, the transformation rule of described expression is as follows:

对表达式进行转化,假设x和y是标准符号,e代表一个常量或变量,参照规则如下:Convert the expression, assuming that x and y are standard symbols, and e represents a constant or variable, the reference rules are as follows:

如果表达式为e,则转化为MSVL表达式返回e;If the expression is e, convert it to MSVL expression and return e;

如果表达式为[x++|x--],则转化为MSVL语句x:=x+1and skip或者x:=x-1and skip;If the expression is [x++|x--], it will be transformed into MSVL statement x:=x+1and skip or x:=x-1and skip;

如果表达式为x=y,则转化为MSVL语句x:=y and skip;If the expression is x=y, it will be transformed into MSVL statement x:=y and skip;

如果表达式为x==y,则转化为MSVL语句x==y;If the expression is x==y, it will be transformed into MSVL statement x==y;

如果表达式为x[+,-,*,/,%,!=]y,则转化为MSVL表达式x[+,-,*,/,%,!=]y;If the expression is x[+,-,*,/,%,!=]y, it will be converted to MSVL expression x[+,-,*,/,%,!=]y;

如果表达式为x*=y(*=[<|>]),则转化为MSVL表达式x=y或者x*y;If the expression is x*=y(*=[<|>]), it will be converted to MSVL expression x=y or x*y;

如果表达式为x[+|-|*|/|%]=y,则转化为x:=x[+|-|*|/|%]y and skip;If the expression is x[+|-|*|/|%]=y, it is transformed into x:=x[+|-|*|/|%]y and skip;

如果表达式为x&&y,则转化为MSVL语句x and skip;If the expression is x&&y, it will be transformed into MSVL statement x and skip;

如果表达式为x||y,则转化为MSVL语句x or y;If the expression is x||y, it is transformed into the MSVL statement x or y;

如果表达式为x,y,则转化为MSVL语句x,y;If the expression is x, y, it will be converted into MSVL statement x, y;

如果表达式为(x),则转化为MSVL语句为(x);If the expression is (x), it is converted into an MSVL statement as (x);

下面说明语句转换规则及语句块转换规则,对基本语句进行转化,基本语句包括语句和语句块,假设exp是一个常量表达式,block是一个语句块,s代表一个完整的声明,x是一个变量,parameter代表一个字符串,规则参照如下:The following describes the statement conversion rules and statement block conversion rules to convert basic statements. Basic statements include statements and statement blocks. Assume that exp is a constant expression, block is a statement block, s represents a complete statement, and x is a variable. , parameter represents a string, and the rules are as follows:

如果语句为空语句,转化为空语句;If the statement is an empty statement, convert it to an empty statement;

如果语句为exp,转化为exp;If the statement is exp, convert it to exp;

如果语句为x=exp,转化为x:=exp and skip;If the statement is x=exp, it is transformed into x:=exp and skip;

如果语句为if语句,使用IF语句的转化规则对语句进行转换;If the statement is an if statement, use the conversion rules of the IF statement to convert the statement;

如果语句为while(exp){block},转化为MSVL语句while(exp){block};If the statement is while(exp){block}, it is converted into MSVL statement while(exp){block};

如果语句为int声明语句,使用声明语句的转换规则对语句进行转换;If the statement is an int declaration statement, use the conversion rules of the declaration statement to convert the statement;

如果语句为for(s exp1;exp2){block},转化为s while(exp){block;exp2};If the statement is for(s exp1;exp2){block}, it is transformed into s while(exp){block;exp2};

如果语句为printf(“parameter”,exp),转化为output(exp);If the statement is printf("parameter", exp), it will be converted to output(exp);

如果语句为scanf(“parameter”,exp),转化为input(exp);If the statement is scanf("parameter", exp), it is converted to input(exp);

其中,对IF语句的转换规则如下:Among them, the conversion rules for the IF statement are as follows:

若语句形如if(exp)s,转化为if(exp)then{s}If the statement is in the form of if(exp)s, it is transformed into if(exp)then{s}

若语句形如if(exp){block},转化为if(exp)then{s}If the statement is in the form of if(exp){block}, it will be converted into if(exp)then{s}

若语句形如if(exp){block1}else{block2},转化为if(exp)then{block1}else{block2}If the statement is in the form of if(exp){block1}else{block2}, it is transformed into if(exp)then{block1}else{block2}

若语句形如if(exp1){block1}else if(exp2){block2},转化为if(exp1)then{block1}else if(exp2){block2}If the statement is in the form of if(exp1){block1}else if(exp2){block2}, it is converted into if(exp1)then{block1}else if(exp2){block2}

假设var_list代表一列以“,”连接的变量,exp_list代表一列以“,”连接的表达式,ei是在exp_list中出现的一个符号,则声明语句的转换规则如下:Assuming that var_list represents a column of variables connected with ",", exp_list represents a column of expressions connected with ",", and ei is a symbol that appears in exp_list, the conversion rules of the declaration statement are as follows:

如果声明语句为int x,转化为int x;If the declaration statement is int x, convert it to int x;

如果声明语句为int var_list,转化为int var_list;If the declaration statement is int var_list, convert it to int var_list;

如果声明语句为int x=exp,转化为int x;x=exp and skip;If the declaration statement is int x=exp, convert it to int x;x=exp and skip;

如果声明语句为int exp_list,对其中的每一个表达式使用声明语句的规则进行转化,分别转换成对应的独立的MSVL声明语句。If the declaration statement is int exp_list, use the rules of the declaration statement to convert each expression in it, and convert them into corresponding independent MSVL declaration statements.

基本语句的转化规则对于语句块的转化,且分别逐条对每条基本语句进行转化,直到语句块中所有语句转化完毕。The conversion rules of the basic sentence are for the conversion of the statement block, and each basic statement is converted one by one until all the statements in the statement block are converted.

Claims (8)

1.一种计算机语言转换系统,其用于将C语言程序转换成MSVL语言程序,其特征在于:其包括,1. A computer language conversion system, which is used to convert a C language program into an MSVL language program, is characterized in that: it includes, 词法分析模块,其将字符序列转换为单词序列,所述字符序列包括C语言中的关键字、标识符、常数、运算符、头文件以及注释行的定义;A lexical analysis module, which converts the character sequence into a word sequence, and the character sequence includes definitions of keywords, identifiers, constants, operators, header files and comment lines in the C language; 语法分析模块,其基于yacc中所规定的C语言的相关词法规则,进而识别出C语言中特定的语句;The grammatical analysis module, which is based on the relevant lexical rules of the C language specified in yacc, and then identifies specific sentences in the C language; 转换处理模块,其根据C语言与MSVL语言之间的语言转换规律将C语言转换成MSVL语言。The conversion processing module converts the C language into the MSVL language according to the language conversion rule between the C language and the MSVL language. 2.一种C语言到MSVL语言的转换方法,其提供词法分析模块、语法分析模块及转换处理模块,其特征在于:所述方法包括以下步骤;2. a conversion method from C language to MSVL language, it provides lexical analysis module, syntax analysis module and conversion processing module, it is characterized in that: described method comprises the following steps; 第一步:将C语言程序导入词法分析模块,该步骤包括将字符序列转换为单词序列,所述字符序列包括C语言中的关键字、标识符、常数、运算符、头文件以及注释行的定义;The first step: the C language program is imported into the lexical analysis module, and this step includes converting the character sequence into a word sequence, and the character sequence includes keywords, identifiers, constants, operators, header files and comment lines in the C language definition; 第二步:将步骤一中得到的单词流导入语法分析模块,该步骤包括基于yacc中所规定的C语言的相关词法规则,进而识别出C语言中特定的语句;Step 2: import the word stream obtained in step 1 into the syntax analysis module, which step includes identifying specific sentences in the C language based on the relevant lexical rules of the C language specified in the yacc; 第三步:将第二步语法分析识别出的C语言语句序列在转换处理模块中根据相应的转换规则转换成对应的MSVL语句;The third step: convert the C language statement sequence identified by the second step grammatical analysis into a corresponding MSVL statement in the conversion processing module according to the corresponding conversion rules; 第四步:用时序操作符“;”连接得到的MSVL语句序列,得到MSVL程序。Step 4: Connect the obtained MSVL statement sequence with the sequence operator ";" to obtain the MSVL program. 3.根据权利要求2所述的一种C语言到MSVL语言的转换方法,其特征在于:语法分析模块中所述的C语言中的结构化语句包括基本表达式语句、while语句、if语句、if-else语句、for语句、switch语句、printf语句以及scanf语句。3. a kind of C language according to claim 2 is to the conversion method of MSVL language, it is characterized in that: the structured statement in the C language described in the syntax analysis module comprises basic expression statement, while statement, if statement, if-else statement, for statement, switch statement, printf statement, and scanf statement. 4.根据权利要求2所述的一种C语言到MSVL语言的转换方法,其特征在于:所述语法分析模块中所述的C语言中结构化语句的while语句、for语句的循环体部分和if语句、if-else语句的条件语句是一个语句块。4. a kind of C language according to claim 2 is to the conversion method of MSVL language, it is characterized in that: the while statement of structured statement in the C language described in the described syntax analysis module, the cycle body part of for statement and The conditional statement of the if statement and if-else statement is a statement block. 5.根据权利要求1所述的一种C语言到MSVL语言的转换方法,其特征在于:所述C语言与MSVL语言之间的语言转换规律包括表达式转换规则、语句转换规则和语句块转换规则。5. a kind of C language according to claim 1 is to the conversion method of MSVL language, it is characterized in that: the language conversion rule between described C language and MSVL language comprises expression conversion rule, sentence conversion rule and sentence block conversion rule. 6.根据权利要求5所述的一种C语言到MSVL语言的转换方法,其特征在于:所述表达式的转化规则如下:6. a kind of C language according to claim 5 is to the conversion method of MSVL language, it is characterized in that: the conversion rule of described expression is as follows: 对表达式进行转化,假设x和y是标准符号,e代表一个常量或变量,参照规则如下:Convert the expression, assuming that x and y are standard symbols, and e represents a constant or variable, the reference rules are as follows: 如果表达式为e,转化为MSVL表达式返回e;If the expression is e, convert it to MSVL expression and return e; 如果表达式为[x++|x--],转化为MSVL语句x:=x+1and skip或者x:=x-1and skip;If the expression is [x++|x--], it is transformed into the MSVL statement x:=x+1and skip or x:=x-1and skip; 如果表达式为x=y,转化为MSVL语句x:=y and skip;If the expression is x=y, it is transformed into the MSVL statement x:=y and skip; 如果表达式为x==y,转化为MSVL语句x==y;If the expression is x==y, it will be transformed into MSVL statement x==y; 如果表达式为x[+,-,*,/,%,!=]y,转化为MSVL表达式x[+,-,*,/,%,!=]y;If the expression is x[+,-,*,/,%,!=]y, it will be converted to MSVL expression x[+,-,*,/,%,!=]y; 如果表达式为x*=y(*=[<|>]),转化为MSVL表达式x=y或者x*y;If the expression is x*=y(*=[<|>]), convert to MSVL expression x=y or x*y; 如果表达式为x[+|-|*|/|%]=y,转化为x:=x[+|-|*|/|%]y and skip;If the expression is x[+|-|*|/|%]=y, convert to x:=x[+|-|*|/|%]y and skip; 如果表达式为x&&y,转化为MSVL语句x and skip;If the expression is x&&y, it will be converted into MSVL statement x and skip; 如果表达式为x||y,转化为MSVL语句x or y;If the expression is x||y, it is converted into the MSVL statement x or y; 如果表达式为x,y,转化为MSVL语句x,y;If the expression is x, y, it will be converted into MSVL statement x, y; 如果表达式为(x),转化为MSVL语句为(x)。If the expression is (x), it will be converted to MSVL statement as (x). 7.如权利要求5所述的一种C语言到MSVL语言的转换方法,其特征在于:所述语句转换规则和语句块转换规则如下,7. a kind of C language as claimed in claim 5 is to the conversion method of MSVL language, it is characterized in that: described sentence conversion rule and sentence block conversion rule are as follows, 对基本语句进行转化,假设exp是一个常量表达式,block是一个语句块,s代表一个完整的声明,x是一个变量,parameter代表一个字符串,规则参照如下:To convert the basic statement, assuming that exp is a constant expression, block is a statement block, s represents a complete statement, x is a variable, and parameter represents a string, the rules are as follows: 如果语句为,转化为;If the statement is, transformed into; 如果语句为exp,转化为exp;If the statement is exp, convert it to exp; 如果语句为x=exp,转化为x:=exp and skip;If the statement is x=exp, it is transformed into x:=exp and skip; 如果语句为if语句,使用IF语句的转化规则对语句进行转换;If the statement is an if statement, use the conversion rules of the IF statement to convert the statement; 如果语句为while(exp){block},转化为MSVL语句while(exp){block};If the statement is while(exp){block}, it is converted into MSVL statement while(exp){block}; 如果语句为int声明语句,使用声明语句的转换规则对语句进行转换;If the statement is an int declaration statement, use the conversion rules of the declaration statement to convert the statement; 如果语句为for(s exp1;exp2){block},转化为s while(exp){block};If the statement is for(s exp1;exp2){block}, it is transformed into s while(exp){block}; 如果语句为printf(“parameter”,exp),转化为output(exp);If the statement is printf("parameter", exp), it will be converted to output(exp); 如果语句为scanf(“parameter”,exp),转化为input(exp);If the statement is scanf("parameter", exp), it is converted to input(exp); 其中,对IF语句的转换规则如下:Among them, the conversion rules for the IF statement are as follows: 若语句形如if(exp)s,转化为if(exp)then{s}If the statement is in the form of if(exp)s, it is transformed into if(exp)then{s} 若语句形如if(exp){block},转化为if(exp)then{s}If the statement is in the form of if(exp){block}, it will be converted into if(exp)then{s} 若语句形如if(exp){block1}else{block2},转化为if(exp)then{block1}else{block2}If the statement is in the form of if(exp){block1}else{block2}, it is transformed into if(exp)then{block1}else{block2} 若语句为if(exp1){block1}else if(exp2){block2},转化为if(exp1)then{block1}else if(exp2){block2}If the statement is if(exp1){block1}else if(exp2){block2}, it will be converted into if(exp1)then{block1}else if(exp2){block2} 假设var_list代表一列以“,”连接的变量,exp_list代表一列以“,”连接的表达式,ei是在exp_list中出现的一个符号,则声明语句的转换规则如下:Assuming that var_list represents a column of variables connected with ",", exp_list represents a column of expressions connected with ",", and ei is a symbol that appears in exp_list, the conversion rules of the declaration statement are as follows: 如果声明语句为int x,转化为int x;If the declaration statement is int x, convert it to int x; 如果声明语句为int var_list,转化为int var_list;If the declaration statement is int var_list, convert it to int var_list; 如果声明语句为int x=exp,转化为int x;x=exp and skip;If the declaration statement is int x=exp, convert it to int x;x=exp and skip; 如果声明语句为int exp_list,对其中的每一个表达式使用声明语句的规则进行转化,分别转换成对应的独立的MSVL声明语。If the declaration statement is int exp_list, use the rules of the declaration statement to convert each expression in it into the corresponding independent MSVL declaration language. 8.根据权利要求5所述的一种C语言到MSVL语言的转换方法,其特征在于:所述基本语句的转化规则对于语句块的转化,且分别逐条对每条基本语句进行转化,直到语句块中所有语句转化完毕。8. a kind of C language according to claim 5 is to the conversion method of MSVL language, it is characterized in that: the conversion rule of described basic sentence is for the transformation of sentence block, and each basic sentence is converted one by one respectively, until sentence All statements in the block are converted.
CN201310120182.1A 2013-04-08 2013-04-08 A kind of C language is to the conversion method of MSVL language Active CN103150200B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201310120182.1A CN103150200B (en) 2013-04-08 2013-04-08 A kind of C language is to the conversion method of MSVL language

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201310120182.1A CN103150200B (en) 2013-04-08 2013-04-08 A kind of C language is to the conversion method of MSVL language

Publications (2)

Publication Number Publication Date
CN103150200A true CN103150200A (en) 2013-06-12
CN103150200B CN103150200B (en) 2016-08-03

Family

ID=48548300

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201310120182.1A Active CN103150200B (en) 2013-04-08 2013-04-08 A kind of C language is to the conversion method of MSVL language

Country Status (1)

Country Link
CN (1) CN103150200B (en)

Cited By (12)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN103455362A (en) * 2013-09-27 2013-12-18 西安电子科技大学 Automatic hardware language transformation system
CN104503816A (en) * 2014-12-30 2015-04-08 西安电子科技大学 System for automatically converting hardware language VHDL (Vhsic Hardware Description Language) into MSVL (Modeling, Simulation and Verification Language)
CN104572072A (en) * 2014-12-01 2015-04-29 北京百度网讯科技有限公司 MVC (model view controller) mode-based language transformation method and equipment for program
CN104657542A (en) * 2015-01-27 2015-05-27 西安电子科技大学 MSVL (Modeling, Simulation and Verification Language)-based Petri network model detection method
CN104657190A (en) * 2015-02-14 2015-05-27 南威软件股份有限公司 Method for enhancing function of switch statement based on C language family
CN106991166A (en) * 2017-03-31 2017-07-28 北京奇艺世纪科技有限公司 A kind of big data processing method and processing device
CN108037913A (en) * 2017-12-21 2018-05-15 西安邮电大学 A kind of conversion method of xUML4MC models to MSVL LISP program LISPs, computer program
CN108090053A (en) * 2018-01-09 2018-05-29 亢世勇 A kind of language conversion output device and method
CN109739512A (en) * 2018-12-28 2019-05-10 江苏极光网络技术有限公司 A kind of analytical type language text formula analysis conversion method
CN109885307A (en) * 2019-01-07 2019-06-14 西安邮电大学 Conversion method and computer program from multi-threaded C program of pthread library to MSVL program
CN112306470A (en) * 2020-10-19 2021-02-02 南京航空航天大学 A Simplified Transformation and Automatic Verification Method of Complex Synchronous Language Programs
CN114661303A (en) * 2022-03-30 2022-06-24 武汉理工大学 Computer language conversion system and conversion method thereof

Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
JP2000029678A (en) * 1998-05-18 2000-01-28 Ntt Communication Ware Kk Program language conversion method, device therefor and recording medium
CN1503459A (en) * 2002-11-27 2004-06-09 华为技术有限公司 Protocol conversion device and method based on text character stream report
CN101499015A (en) * 2009-03-18 2009-08-05 北京和利时系统工程有限公司 Method and converter for converting high level language to other high level languages
CN102012991A (en) * 2010-11-09 2011-04-13 北京神舟航天软件技术有限公司 Static analysis-based checking method of safety rules of C language
CN102222004A (en) * 2011-07-01 2011-10-19 福建富士通信息软件有限公司 Method for transforming switch special language into C language

Patent Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
JP2000029678A (en) * 1998-05-18 2000-01-28 Ntt Communication Ware Kk Program language conversion method, device therefor and recording medium
CN1503459A (en) * 2002-11-27 2004-06-09 华为技术有限公司 Protocol conversion device and method based on text character stream report
CN101499015A (en) * 2009-03-18 2009-08-05 北京和利时系统工程有限公司 Method and converter for converting high level language to other high level languages
CN102012991A (en) * 2010-11-09 2011-04-13 北京神舟航天软件技术有限公司 Static analysis-based checking method of safety rules of C language
CN102222004A (en) * 2011-07-01 2011-10-19 福建富士通信息软件有限公司 Method for transforming switch special language into C language

Non-Patent Citations (1)

* Cited by examiner, † Cited by third party
Title
YAN YU,ZHENHUA DUAN,CONG TIAN,AND MENGFEI YANG: "Model Checking C Programs with MSVL", 《STRUCTURED OBJECT-ORIENTED FORMAL LANGUAGE AND METHOD》 *

Cited By (19)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN103455362A (en) * 2013-09-27 2013-12-18 西安电子科技大学 Automatic hardware language transformation system
CN104572072B (en) * 2014-12-01 2017-09-29 北京百度网讯科技有限公司 A kind of language transfer method and equipment to the program based on MVC pattern
CN104572072A (en) * 2014-12-01 2015-04-29 北京百度网讯科技有限公司 MVC (model view controller) mode-based language transformation method and equipment for program
CN104503816A (en) * 2014-12-30 2015-04-08 西安电子科技大学 System for automatically converting hardware language VHDL (Vhsic Hardware Description Language) into MSVL (Modeling, Simulation and Verification Language)
CN104503816B (en) * 2014-12-30 2017-09-19 西安电子科技大学 An Automatic Conversion System from Hardware Language VHDL to MSVL
CN104657542A (en) * 2015-01-27 2015-05-27 西安电子科技大学 MSVL (Modeling, Simulation and Verification Language)-based Petri network model detection method
CN104657542B (en) * 2015-01-27 2017-12-19 西安电子科技大学 A kind of Petri net model detection method based on MSVL
CN104657190A (en) * 2015-02-14 2015-05-27 南威软件股份有限公司 Method for enhancing function of switch statement based on C language family
CN104657190B (en) * 2015-02-14 2018-05-11 南威软件股份有限公司 A kind of method of the enhancing switch statement function based on C language family
CN106991166A (en) * 2017-03-31 2017-07-28 北京奇艺世纪科技有限公司 A kind of big data processing method and processing device
CN108037913A (en) * 2017-12-21 2018-05-15 西安邮电大学 A kind of conversion method of xUML4MC models to MSVL LISP program LISPs, computer program
CN108037913B (en) * 2017-12-21 2021-08-17 西安邮电大学 Conversion method from xUML4MC model to MSVL language program, computer readable storage medium
CN108090053A (en) * 2018-01-09 2018-05-29 亢世勇 A kind of language conversion output device and method
CN109739512A (en) * 2018-12-28 2019-05-10 江苏极光网络技术有限公司 A kind of analytical type language text formula analysis conversion method
CN109739512B (en) * 2018-12-28 2022-04-12 江苏极光网络技术有限公司 Analytic language text type analysis and conversion method
CN109885307A (en) * 2019-01-07 2019-06-14 西安邮电大学 Conversion method and computer program from multi-threaded C program of pthread library to MSVL program
CN109885307B (en) * 2019-01-07 2022-03-01 西安邮电大学 Method for converting pthread library multithread C program into MSVL program and computer program
CN112306470A (en) * 2020-10-19 2021-02-02 南京航空航天大学 A Simplified Transformation and Automatic Verification Method of Complex Synchronous Language Programs
CN114661303A (en) * 2022-03-30 2022-06-24 武汉理工大学 Computer language conversion system and conversion method thereof

Also Published As

Publication number Publication date
CN103150200B (en) 2016-08-03

Similar Documents

Publication Publication Date Title
CN103150200B (en) A kind of C language is to the conversion method of MSVL language
CN109753288B (en) Intelligent contract compiling method suitable for formalized verification
CN104503816B (en) An Automatic Conversion System from Hardware Language VHDL to MSVL
CN106371887B (en) Compiling system and method for MSVL language
US20130067437A1 (en) Providing SystemVerilog Testing Harness for a Standardized Testing Language
CN106294148B (en) C programmer software verification method and device based on escape character transition system
CN102195773A (en) Method and system for analyzing block cipher algorithm
CN103455362A (en) Automatic hardware language transformation system
CN109359055B (en) Data testing method and device
CN111222141A (en) Automobile electronic control unit code vulnerability analysis method and system
Leung et al. C-to-verilog translation validation
CN115237418A (en) A network modal configuration system and method for multi-modal network element equipment
Kausch et al. An Approach for Logic-based Knowledge Representation and Automated Reasoning over Underspecification and Refinement in Safety-Critical Cyber-Physical Systems.
CN110427179B (en) MSVL (modeling, simulation and verification language) program automatic generation method and system for intelligent contract language
CN110309656B (en) Implicit type conversion security detection method
Küster et al. Towards explicit behavioral consistency concepts in the UML
Vizovitin et al. Verifying UCM specifications of distributed systems using colored Petri nets
CN100578513C (en) Tri-state device pull-up impedance/pull-down impedance/bus hold conversion method
Pona et al. Formally-Verified ASN. 1 Protocol C-language Stack
Belghiat et al. A Pi-calculus-based approach for the verification of UML2 sequence diagrams
Zafar Model analysis of equivalence classes in UML events relations
Li et al. Accessible Formal Methods for Verified Parser Development
Mussa et al. Model-based test cases reuse and optimization
Zafar Automatic Construction of Formal Syntax Tree Based on Regular Expressions
CN106681786A (en) Method for automatically synthesizing commonly-used cyclic abstracts and generating program specifications

Legal Events

Date Code Title Description
C06 Publication
PB01 Publication
C10 Entry into substantive examination
SE01 Entry into force of request for substantive examination
C14 Grant of patent or utility model
GR01 Patent grant