Compiler
1.2 The structure of a compiler
Compiler:analysis and synthesis
Syntactically the grammatical
The semantically semantics of
The analysis section breaks up the source program to constituent pieces and imposes a grammatical structure on them.
The analysis part also collects information on the source program and stores it in a data structure called a symbol tab Le, which is passed along and the intermediate representation to the synthesis part.
The synthesis part constructs the desired target program from the intermediate representstion and the information in the S Ymbol table.
The analysis was often called the front end of the compiler; The synthesis part was the back end.
A typical decomposition of a compiler into phases are shown:
1.2.1 Lexical analysis
Lexemes.
<token-name, attribute-value>
1.2.2 Syntax Analysis
The parser uses the first components of the tokens produced by the lexical analyzer to create a tree-like intermediate rep Resentation that depicts the grammatical structure of the token steam. A typical representation is a syntax teee in which each interior node represents an operation and the children of the nod e represent the arguments of the operation.
1.2.3 Semantic Analysis
The semantic analysis uses the syntax tree and the information of the symbol table to check the source program for Semant IC consistency with the language definition.
Type checking:
Coercions:the Language Specification may permit some type conversions called coercions
1.2.4 Intermediate code generation
This intermediate representation should has a important properties:it should is easy to produce and it should is easy To translate into the target machine.
Three-address code.
1.2.5 Code optimization
The Machine-independent code-optimization phase attempts to improve the intermediate code so better target code WI ll result.
12.6 Code Generation
The code generator takes as input an intermediate representation of the source program and maps it into the target Langua GE.
A crucial aspect of code generation is the judicious assignment of registers to hold variables.
Ldf:load float
mulf:multiplies float
Addf:add float
Stf:store float
1.2.7 symbol-table Management
An essential function of a compiler was to record the variable names used in the source program and collect information ABO UT various attributes of each name.
The symbol table is a data structure containing a record for each variable name, with fields for the attributes of the NA Me.
1.2.8 the grouping of phases into passes
The discussion of phases deals with the logical organization of a compiler. In an implementation, activities from several phase may is grouped together into a pass
With these collections, we can produce compilers for different source languages for one target machine by combining Diffe Rent front ends with the back end for that target machine. Similarly, we can produce compilers for different target machines, by combining a front end with back ends for different Target machines.
1.2.9 compiler-construction Tools
Some commonly used compiler-construction tools includes
1. Parser generators that automatically produce syntax analyzers from a grammatical description of a programming language .
1.2 The structure of a compiler