Font Size: a A A

Visual Implementation Of Operational Semantics Of Procedural Programming Languages

Posted on:2009-06-08Degree:MasterType:Thesis
Country:ChinaCandidate:X D SunFull Text:PDF
GTID:2178360242481575Subject:Computer software and theory
Abstract/Summary:PDF Full Text Request
Formal semantics is the field concerned with the rigorous mathematical study of the meaning of programming languages and models of computation. It can formalize the semantics by the use of abstract mathematical tools, strict description of the programming language semantics, so we call it the formal semantics. Because of abstraction, the students have difficulties in understanding deeply during the actual learning, the system developed in this paper is designed to help students better understand of the form of programming language semantics, it can be applied to the teaching of semantics as an teaching assistant tool, and the system makes some useful explorations to the visualization of the programming language.The main task of this paper include: (1) define a prodecural languages by adopting an increasing way, present their abstract syntax and semantic definitions, (2) after scanning and parsiong, create an grammar tree, (3) define the relevant abstract machine according to the language's feature, and realize the functions of each part of the abstract machine, (4) demonstrate the whole process that the abstract machine implement the language.On the base of In-depth studies to the operational semantics, this paper mainly finish five aspects: define procedural languages by increasing way, lexical analysis, parsing, the definition and realization of the abstract machine, the visualization demonstration of the process about abstract machine implement the language.The system can deal with different levels of programming languages, including: L0 language, Lrw language, Ld language, Lb language, Lpf language. Their incremental definition as follows:1,Le expressions (only expressions)2,L0 language = Le + statements 3,Lrw language = L0 + read + write (input and output statement)4,Ld language = Lrw + VarDec (variable declarations)5,Lb language =Ld + block (Block statement)6,Lpf language= Lb + procedure + function (procedure and function)After defining these languages, it is necessary to realize their lexical analysis procedures. The task of lexical analysis is to scan source programs in the form of string sequentially, identify the independent words (Token). The system implements the lexical analysis procedures through constructing DFA, lexical analysis procedure was called by syntax analysis procedure.The main task of parsing is to check the source programme's syntactical structure with the rule of syntax, and identify their corresponding syntax elements, Token is the input of the parsing procedures, and output the syntax tree relative to the source programme's structure. The system implement the parser with the usage of recursive descent method. A recursive descent parser is a top-down parser built from a set of mutually-recursive procedures (or a non-recursive equivalent) where each such procedure usually implements one of the production rules of the grammar. Thus the structure of the resulting program closely mirrors that of the grammar it recognizes.The main ideas of the abstract Machine is to define an abstract machine in accordance with the language L, so that it can implement language L. The definition of the abstract machine includes two parts: the composition of an abstract machine state and the conversion rules of the abstract machine's states. Different abstract machines are defined for different programming languages. The more complex a programming language is, the more difficult it is to implement its abstract machine. The general components of the abstract machine and function as follows:1,the statement controlled area: store declaration statements andstatements sequence.2,expression-controlled area: store some reserved words and expressions. 3,the value stack: store intermediate values and variable name.4,static environment area: static environment of variables and procedure/function static environment sequence.5,dynamic environment area: store variables and the corresponding value.6,the input stack: store values to be improted.7,the output stack: store values to be outputed.8,dump: preserve the interrupted scene when procedure/function calling.The abstract machines implemented by this system consist of components described above fully or partly, depending on the compositions of the abstract machine's state in accordance with the language's characteristics.After the components of an abstract machine determined, the next step is to give the state conversion rules of the abstract machine according to the operation meaning of various language components. The state conversion rules contained the initial state and termination state, at the beginning, the abstract machine is in the initial state, which is the state of the initial procedures required in controlled areas, then in accordance with the contents of the current state select a state transition rules and change to next state, this process will go on until reaching the termination state. When this process finished, the words and expressions controlled areas controlled area are empty.Visual presentation of the abstract machine is demonstrated with the detailed implementation process, whenever a step is implemented (the state is changed), the visual demonstration procedure will be called by the abstract machine, and all the contents stored in every segment of the current abstract machine will be showed out. A simle system has been implemented with MFC to demonstrat the detailed procedures of running programs on the abstract machines.
Keywords/Search Tags:Implementation
PDF Full Text Request
Related items