Docsity

Three Address Code (Compiler), Schemes and Mind Maps of Compiler Construction

Partial preview of the text

Download Three Address Code (Compiler) and more Schemes and Mind Maps Compiler Construction in PDF only on Docsity!

COMPILER CONSTRUCTION

LECTURE8 3AC

Muhammad Fawad Nasim [email protected]

Phases of Compiler

๏‚ž (^) Lexical Analysis: Creates new table entries in the table, example like entries about token. ๏‚ž (^) Syntax Analysis: Adds information regarding attribute type, scope, dimension, line of reference, use, etc in the table. ๏‚ž (^) Semantic Analysis: Uses available information in the table to check for semantics i.e. to verify that expressions and assignments are semantically correct(type checking) and update it accordingly. ๏‚ž (^) Intermediate Code generation: Refers symbol table for knowing how much and what type of run-time is allocated and table helps in adding temporary variable information. ๏‚ž (^) Code Optimization: Uses information present in symbol table for machine dependent optimization. ๏‚ž (^) Target Code generation: Generates code by using address information of identifier present in the table.

๏‚ž Intermediate Code Generation Ties the front and back ends together

Three Address Code?

๏‚ž A statement of the form x = y op z is a three address statement. ๏‚ž x, y and z are the three operands and op is any logical or arithmetic operator. ๏‚ž Maximum one OP on right side and two operands ๏‚ž Here three address refers to the three addresses in the statement viz addresses of x , y and z.

๏‚ž Say for example we have a statement a = b + c + d Then three address code for this statement is :- t1 = c + d a = b + t t2=a

Example

๏‚ž Only Single operator @ LHS ๏‚ž Say for example we have a statement a = -b + c ๏‚ž Is it in 3 AC?? ๏‚ž No: 2 operators Then three address code for this statement is :- a = -b + c => a = 0 โ€“ b + c t1 = 0 โ€“ b t2= t1+c

Example

Challenge!

3AC

๏‚ž Generic Code {to convert it to any language} ๏‚ž Baby feed {Small pieces} ๏‚ž Byte Code(Java)???

3AC for complex statements

If (a < b) t= else t= ๏‚ž (^) For 3AC we need to manually move the control to specific line number 1 2 3 4 How to move the control in assembly??

  • (^) goto statement
    1. If (a < b) goto (4)
    2. t=
    3. goto (5)
    4. t=

Challenge!

Loops

๏‚ž No loops in 3AC just goto statement!!!!

Challenge!