PPT: Intermediate Code Generation Notes | EduRev

Compiler Design

Computer Science Engineering (CSE) : PPT: Intermediate Code Generation Notes | EduRev

 Page 1


Intermediate Code Generation
Page 2


Intermediate Code Generation
Outline
? Variants of Syntax Trees
? Three-address code
? Types and declarations
? Translation of expressions
? Type checking
? Control flow
? Backpatching
Page 3


Intermediate Code Generation
Outline
? Variants of Syntax Trees
? Three-address code
? Types and declarations
? Translation of expressions
? Type checking
? Control flow
? Backpatching
Introduction
? Intermediate code is the interface between front end
and back end in a compiler
? Ideally the details of source language are confined to
the front end and the details of target machines to the
back end (a m*n model)
? In this chapter we study intermediate representations,
static type checking and intermediate code generation
Parser
Static
Checker
Intermediate
Code Generator
Code
Generator
Front end Back end
Page 4


Intermediate Code Generation
Outline
? Variants of Syntax Trees
? Three-address code
? Types and declarations
? Translation of expressions
? Type checking
? Control flow
? Backpatching
Introduction
? Intermediate code is the interface between front end
and back end in a compiler
? Ideally the details of source language are confined to
the front end and the details of target machines to the
back end (a m*n model)
? In this chapter we study intermediate representations,
static type checking and intermediate code generation
Parser
Static
Checker
Intermediate
Code Generator
Code
Generator
Front end Back end
Variants of syntax trees
? It is sometimes beneficial to crate a DAG instead of
tree for Expressions.
? This way we can easily show the common sub-
expressions and then use that knowledge during code
generation
? Example: a+a*(b-c)+(b-c)*d
+
+ *
*
-
b
c
a
d
Page 5


Intermediate Code Generation
Outline
? Variants of Syntax Trees
? Three-address code
? Types and declarations
? Translation of expressions
? Type checking
? Control flow
? Backpatching
Introduction
? Intermediate code is the interface between front end
and back end in a compiler
? Ideally the details of source language are confined to
the front end and the details of target machines to the
back end (a m*n model)
? In this chapter we study intermediate representations,
static type checking and intermediate code generation
Parser
Static
Checker
Intermediate
Code Generator
Code
Generator
Front end Back end
Variants of syntax trees
? It is sometimes beneficial to crate a DAG instead of
tree for Expressions.
? This way we can easily show the common sub-
expressions and then use that knowledge during code
generation
? Example: a+a*(b-c)+(b-c)*d
+
+ *
*
-
b
c
a
d
SDD for creating DAG’s
1) E -> E1+T
2) E -> E1-T
3) E -> T
4) T -> (E)
5) T -> id
6) T -> num
Production Semantic Rules
E.node= new Node(‘+’, E1.node,T.node)
E.node= new Node(‘-’, E1.node,T.node)
E.node = T.node
T.node = E.node
T.node = new Leaf(id, id.entry)
T.node = new Leaf(num, num.val)
Example:
1) p1=Leaf(id, entry-a)
2) P2=Leaf(id, entry-a)=p1
3) p3=Leaf(id, entry-b)
4) p4=Leaf(id, entry-c)
5) p5=Node(‘-’,p3,p4)
6) p6=Node(‘*’,p1,p5)
7) p7=Node(‘+’,p1,p6)
8) p8=Leaf(id,entry-b)=p3
9) p9=Leaf(id,entry-c)=p4
10) p10=Node(‘-’,p3,p4)=p5
11) p11=Leaf(id,entry-d)
12) p12=Node(‘*’,p5,p11)
13) p13=Node(‘+’,p7,p12)
Read More
Offer running on EduRev: Apply code STAYHOME200 to get INR 200 off on our premium plan EduRev Infinity!

Related Searches

mock tests for examination

,

PPT: Intermediate Code Generation Notes | EduRev

,

PPT: Intermediate Code Generation Notes | EduRev

,

shortcuts and tricks

,

practice quizzes

,

Semester Notes

,

Sample Paper

,

Extra Questions

,

MCQs

,

Exam

,

ppt

,

past year papers

,

PPT: Intermediate Code Generation Notes | EduRev

,

Free

,

Summary

,

study material

,

video lectures

,

Objective type Questions

,

Previous Year Questions with Solutions

,

Viva Questions

,

pdf

,

Important questions

;