Again freestudy9 is presenting new post related to Intermediate Forms. Additionally, Here Intermediate Forms are the important object of the Compiler Design.
- There are three types of intermediate representation,
1. Abstract syntax tree
2. Postfix notation
3. Three address code
Abstract syntax tree
- A syntax tree depicts the natural hierarchical structure of a source program.
- A DAG (Directed Acyclic Graph) gives the same information but in a more compact way because common sub-expressions identified.
- A syntax tree and DAG for the assignment statement a = b*-c + b*-c is given in Fig.
- Postfix notation is a linearization of a syntax tree.
- In postfix notation, the operands occur first and then operators arranged.
- the postfix notation for the syntax tree in Fig. is, a b c uminus * b c uminus * + assign.
Three address code: Intermediate Forms
- Three address code is a sequence of statement of the general form, statements a:= b op c
- Where a, b or c are the operands that can be names or constants. And op stands for any operator.
- For the expression like a = b + c + d might be translated into a sequence expression,
- Here t1 and t2 the temporary names generated by the compiler.
- There at most three addresses allowed (two for operands and one for the result). Hence, this representation called three three-address code.
Overview of the translation process: Intermediate Forms
- A translator is a kind of program that takes one form of the program as input and converts it into another form.
- The input is called source program and output is called target program.
- The source language can be assembly language or higher level language like C, C++, FORTRAN, etc…
- There are three types of translators,
Compiler: Major functions done by the compiler
- A compiler is a program that reads a program written in one language and translates into an equivalent program in another language.
Major functions done by the compiler: Intermediate Forms
- The compiler used to convert one form of program to another.
- A compiler should convert the source program to a target machine code in such a way that the generated target code should be easy to understand.
- Compiler should preserve the meaning of source code.preserve
- The compiler should report errors that occur during the compilation process.
- The compilation must be done efficiently.