Compiler Designs and Constructions - PowerPoint PPT Presentation

1 / 23
About This Presentation
Title:

Compiler Designs and Constructions

Description:

Syntax-directed definition with only synthesized attributes is called S-attributed ... Use Run-Time Stack. Easy to reconstruct Parse Tree. Chapter 9: ... – PowerPoint PPT presentation

Number of Views:65
Avg rating:3.0/5.0
Slides: 24
Provided by: scie6
Category:

less

Transcript and Presenter's Notes

Title: Compiler Designs and Constructions


1
Compiler Designs and Constructions
  • Chapter 9 Translation
  • Objectives
  • Translation Method
  • Three Address Code
  • Dr. Mohsen Chitsaz

2
Bottom-up evaluation of S-attributed
  • Definitions
  • Syntax-directed definition with only synthesized
    attributes is called S-attributed
  • Use LR Parser
  • Implementation
  • Stack to hold info about subtrees that have been
    parsed

3
  • Example
  • A.a F(X.x, Y.y, Z.z) for production
  • A ---gt XYZ

lt--- Top
After Parse gt
Value of Symbol Table
Pointer to a State in LR(1) Parse Table
4
  • Example

5
Cont.
  • Using LR Parser Parse 3 5 4

lt--- Top Top 1 Top - 2
lt--- nTop

6
(No Transcript)
7
  • Parse 3 5 4

L
E

Show Stack

T
E
F
T
F
T

4
F
5
3
8
Intermediate Code Generation
  • Type of intermediate code generation
  • Graphical Representation
  • a b c b c
  • Syntax Tree



a


c
b
b
c
9
  • Dag



a

c
b
10
  • Advantages?
  • Disadvantages?

11
Representation of Syntax Tree
a-
lt--- b c
12
  • Using array

b c
b c
13
  • Postfix notation
  • ( a ((b c) (b c)))
  • a b c b c
  • Advantages/Disadvantages?
  • No need for ()
  • No need for Temp
  • Use Run-Time Stack
  • Easy to reconstruct Parse Tree

14
Three Address Code
  • Three address Code
  • General Form
  • X A op B
  • X, A, B are Const, Name, or Temp
  • Example
  • a b c d
  • T0 b c
  • T1 T0 d
  • a T1

15
Three Address Code
  • Advantages?
  • Disadvantages?

16
Three Address Code
  • Assignment
  • Operand Operand1 op Operand2
  • Unary Operation
  • Operand Op Operand1
  • Copy Statement
  • Operand Operand1
  • Procedure/Function Call
  • Parm A,B
  • Call P,n

17
Three Address Code
  • Indexed Assignment
  • OperandI B
  • Pointer
  • A Address B
  • Unconditional Jump
  • GOTO L
  • Conditional Jump
  • If A RelOp B GOTO L

18
Types of Three Address Codes
  • Quadruples (Quad/Three Address Code)
  • Record structure with 4 fields
  • Arg1, Arg3, op, Result
  • Example a -bcd

19
Quadruples
Code U_Minus b T1 Mul c d T2 Add T1 T2 T3
Assign T3 a
20
Types of Three Address Codes
  • Triples (3 Tuples/Triplest)
  • Record with 3 fields
  • Arg1, Arg2, op
  • Example a -b c d

21
Triples
  • Arg1, Arg2 are either a pointer to Symbol Table
    (Name, Constant) or a pointer to Triple Structure
  • This is a Two Address Instruction
  • Most Assembly Languages are made up of Triples

22
  • Indirect Tuples
  • We use pointers to Triples
  • Example a -b c d

23
Indirect Tuples
  • Save Space Why?
  • Not good for optimizing code Why?
  • Not good for memory assignment prior to code
    generation
Write a Comment
User Comments (0)
About PowerShow.com