SUBJECTIVE ASSIGNMENT – 2AW
NAME: Dr.S.Dhanalakshmi
APPLICATION NUMBER: a4131826e72b11e9994823b41d67a0f0
COURSE NAME: ACADEMIC WRITING
AFFILIATION:
Professor,
Dept of Computer Science and Engineering,
Malla Reddy Engineering College (Autonomous),
Hyderabad - 500100, Telangana, India.
Subject Name: Compiler Design
Branch & Sem : III B.Tech (CSE) & I Sem
Topic : Intermediate Code Generation
(Compiler Design subject contains 5 modules, this
topic belongs to 3rd module)
Intermediate Code Generation
• Intermediate code is the interface between front end and back
end in a compiler source language are confined to the front end
and the details of target machines to the back end
• An intermediate code form of source program is an internal
form of a program created by the compiler while translating the
program created by the compiler from a high –level language to
assembly code(or)object code(machine code).
Parser
Static
Checker
Intermediate
Code Generator
Code
Generator
Front end Back end
Types of Intermediate
representations
3 Types of Intermediate Representations
1) Syntax tree
2) Postfix notation
3) Three address code (3AC)
1. SYNTAX TREE
• The parse tree itself is a useful intermediate-language representation for a
source program, especially in optimizing compilers where the
intermediate code needs to extensively restructure.
• A parse tree, however, often contains redundant information which can be
eliminated, Thus producing a more economical representation of the
source Program. One such variant of a parse tree is what is called an
(abstract) syntax tree, a tree in which each leaf represents an operand and
each interior node an operator.
Ex: a:= b*-c + b*-c
Graphical Representations - DAG
• A syntax tree depicts the natural hierarchical structure of
source program. A DAG (Directed Acyclic Graph) gives the
same information but in a more compact way because
common sub-expressions are identified.
• DAG is the common sub expression in the given expression is
called directed acyclic graph.
:=
+
-b
c
*
a
2. Postfix Notation
• Postfix notation is a linearized representation of a
syntax tree; it is a list of the nodes of the in which a
node appears immediately after its children.
The postfix notation for the syntax tree in the fig is
• a:= b c uminus + b c uminus * + assign
+
+ *
*
-
b c
a
d
• 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)
3.Three address code (3AC)
• In a three address code there is at most one
operator at the right side of an instruction
Example a:= b *- c + b* - c
t1 = – c
t2 = b * t1
t3 = – c
t4 = b * t3
t5 = t2 + t4
a:= t5
Three address codes
Implementations
• Quadruples
– Has four fields: op, arg1, arg2 and result
• Triples
– Temporaries are not used and instead references
to instructions are made
• Indirect triples
– In addition to triples we use a list of pointers to
triples
FEEDBACK
SIR/MADAM, its really very nice and interesting topics for those you are doing
research work, completed research work peoples. I think that you did a great
job sir, excellent work sir. I really think you have a super power in academic
writing. Your approach also very marvelous. Many times, I send mail to your
mailid, for the clarification related to assessment or topics, you replied that in
positive behaviour, its really appreciatable.

Intermediate code generation

  • 1.
    SUBJECTIVE ASSIGNMENT –2AW NAME: Dr.S.Dhanalakshmi APPLICATION NUMBER: a4131826e72b11e9994823b41d67a0f0 COURSE NAME: ACADEMIC WRITING AFFILIATION: Professor, Dept of Computer Science and Engineering, Malla Reddy Engineering College (Autonomous), Hyderabad - 500100, Telangana, India.
  • 2.
    Subject Name: CompilerDesign Branch & Sem : III B.Tech (CSE) & I Sem Topic : Intermediate Code Generation (Compiler Design subject contains 5 modules, this topic belongs to 3rd module)
  • 3.
    Intermediate Code Generation •Intermediate code is the interface between front end and back end in a compiler source language are confined to the front end and the details of target machines to the back end • An intermediate code form of source program is an internal form of a program created by the compiler while translating the program created by the compiler from a high –level language to assembly code(or)object code(machine code). Parser Static Checker Intermediate Code Generator Code Generator Front end Back end
  • 4.
    Types of Intermediate representations 3Types of Intermediate Representations 1) Syntax tree 2) Postfix notation 3) Three address code (3AC)
  • 5.
    1. SYNTAX TREE •The parse tree itself is a useful intermediate-language representation for a source program, especially in optimizing compilers where the intermediate code needs to extensively restructure. • A parse tree, however, often contains redundant information which can be eliminated, Thus producing a more economical representation of the source Program. One such variant of a parse tree is what is called an (abstract) syntax tree, a tree in which each leaf represents an operand and each interior node an operator. Ex: a:= b*-c + b*-c
  • 6.
    Graphical Representations -DAG • A syntax tree depicts the natural hierarchical structure of source program. A DAG (Directed Acyclic Graph) gives the same information but in a more compact way because common sub-expressions are identified. • DAG is the common sub expression in the given expression is called directed acyclic graph. := + -b c * a
  • 7.
    2. Postfix Notation •Postfix notation is a linearized representation of a syntax tree; it is a list of the nodes of the in which a node appears immediately after its children. The postfix notation for the syntax tree in the fig is • a:= b c uminus + b c uminus * + assign
  • 8.
    + + * * - b c a d •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)
  • 9.
    3.Three address code(3AC) • In a three address code there is at most one operator at the right side of an instruction Example a:= b *- c + b* - c t1 = – c t2 = b * t1 t3 = – c t4 = b * t3 t5 = t2 + t4 a:= t5
  • 10.
    Three address codes Implementations •Quadruples – Has four fields: op, arg1, arg2 and result • Triples – Temporaries are not used and instead references to instructions are made • Indirect triples – In addition to triples we use a list of pointers to triples
  • 13.
    FEEDBACK SIR/MADAM, its reallyvery nice and interesting topics for those you are doing research work, completed research work peoples. I think that you did a great job sir, excellent work sir. I really think you have a super power in academic writing. Your approach also very marvelous. Many times, I send mail to your mailid, for the clarification related to assessment or topics, you replied that in positive behaviour, its really appreciatable.