Analysis-Synthesis Model of Compilation
Analysis-Synthesis model of compilation is the main topic of this post. Freestudy9 has described it with its point to point information
Again There are mainly two parts of the compilation process. So it is divided into two types.
- Analysis phase: The main objective of the analysis phase is to break the source code into parts and then arranges these pieces into a meaningful structure.
- Synthesis phase: Synthesis phase is concerned with the generation of the target language statement which has the same meaning as the source statement.
Analysis Phase: (Analysis-Synthesis Model)
Analysis part is divided into three subparts,
- Lexical analysis
- Syntax analysis
- Semantic analysis
Similarly, the Lexical analysis is also called linear analysis or scanning.
- Lexical analyzer reads the source program and then it is broken into the stream of units. Such units are called token.
- Then it classifies the units into different lexical classes. E.g. id’s, constants, keyword ..and enters them into different tables.
- For example, in the lexical analysis, the assignment statement a: = a + b * c * 2 would be grouped into the tokens.
Syntax Analysis: Analysis-Synthesis model
- Syntax analysis is also called hierarchical analysis or parsing.
- The syntax analyzer checks each line of the code and spots every tiny mistake that the programmer has committed while typing the code.
- So If the code is error free then syntax analyzer generates the tree.
- The semantic analyzer determines the meaning of a source string.
- For example matching of parenthesis in the expression, or matching of if..else statement or performing an arithmetic operation that is type compatible, or checking the scope of operation.
Int to float
synthesis part divided into three subparts,
- Intermediate code generation
- Code optimization
- Code generation
Intermediate code generation: Analysis-Synthesis model
- The intermediate representation should have two important properties, it should be easy to produce and easy to translate into the target program.
- Moreover, We consider intermediate form called “three address code”.
- Also, Three-address code consists of a sequence of instruction, each of which has at most three operands.
- The source program might appear in three address code as,
t1= int to real(2)
t2= id3 * t1
t3= t2 * id2
t4= t3 + id1
Code optimization: Analysis-Synthesis model
- The code optimization phase attempt to improve the intermediate code.
- Moreover, This is necessary to have a faster-executing code or less consumption of memory.
- Also, Thus by optimizing the code the overall running time of a target program can be
t1= id3 * 2.0
t2= id2 * t1
id1 = id1 + t2
Code generation: Analysis-Synthesis model
- In code generation phase the target code gets generated. Also, The intermediate code instructions translated into the sequence of the machine instruction.
MOV id3, R1
MUL #2.0, R1
MOV id2, R2
MUL R2, R1
ADD R2, R1
MOV R1, id1
- A symbol table a data structure used by a language translator such as a compiler or
- Also, It used to store names encountered in the source program, along with the relevant attributes for those names.
- Moreover, Information about the following entities stored in the symbol table.
Conclusion: Analysis-Synthesis model
Again Freestudy9 have some post related to students. Accordingly given above article we have described it with the point to point description.