0% found this document useful (0 votes)
23 views16 pages

Unit-4-1

The document discusses intermediate code generation in compiler design. It covers topics such as intermediate languages like prefix, postfix notation and triple codes. It also discusses syntax trees, evaluation of expressions, intermediate code generation, declarations, assignment statements, boolean expressions and code generation.

Uploaded by

Jefferson Aaron
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
23 views16 pages

Unit-4-1

The document discusses intermediate code generation in compiler design. It covers topics such as intermediate languages like prefix, postfix notation and triple codes. It also discusses syntax trees, evaluation of expressions, intermediate code generation, declarations, assignment statements, boolean expressions and code generation.

Uploaded by

Jefferson Aaron
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 16

18CSC304J- COMPILER DESIGN

UNIT-4

SRMIST, Vadapalani Campus


UNIT-IV SYLLABUS
1. Intermediate Code Generation 10. Code Generation
2. Intermediate Languages - prefix - postfix 11. Issues in the design of code generator
3. Quadruple - triple - indirect triples 12. The target machine – Runtime Storage
Representation management
4. Syntax tree- Evaluation of 10. A simple Code generator
expression-three-address code 11. Code Generation Algorithm
5. Synthesized attributes – Inherited 12. Register and Address Descriptors
attributes 13. Generating Code of Assignment Statements
6. Intermediate languages – Declarations 14. Cross Compiler – T diagrams
7. Assignment Statements 15. Issues in Cross compilers
8. Boolean Expressions, Case Statements
9. Back patching – Procedure calls

2
SRMIST, Vadapalani Campus
Introduction
Intermediate Code

3
SRMIST, Vadapalani Campus
Overview

● Intermediate representations span the gap


between the source and target languages:

○ closer to target language;

○ (more or less) machine independent;

○ allows many optimizations to be done in a


machine-independent way.
● Implementable via syntax directed translation,
so can be folded into the parsing process.
4
Types of Intermediate Languages
● High Level Representations (e.g., syntax trees):

○ closer to the source language

○ easy to generate from an input program

○ code optimizations may not be straightforward.


● Low Level Representations (e.g., 3-address code):

○ closer to the target machine;

○ easier for optimizations, final code generation;

5
Syntax Trees

A syntax tree shows the structure of a program by abstracting away


irrelevant details from a parse tree.

○ Each node represents a computation to be performed;

○ The children of the node represents what that computation is


performed on.
Syntax trees decouple parsing from subsequent processing.
6
Syntax Trees: Example
Parse tree:
Grammar :

E→E+T | T

T→T*F | F

F → ( E ) | id

Syntax tree:

Input: id + id * id

7
Intermediate Languages Types
● Graphical IRs: Abstract Syntax trees, DAGs, Control Flow Graphs
● Linear IRs:

○ Stack based (postfix)

○ Three address code (quadruples)

CS 540 GMU Spring 2009 8


Graphical IRs
● Abstract Syntax Trees (AST) – retain essential structure of the parse tree,
eliminating unneeded nodes.
● Directed Acyclic Graphs (DAG) – compacted AST to avoid duplication –
smaller footprint as well
● Control flow graphs (CFG) – explicitly model control flow

CS 540 GMU Spring 2009 9


ASTs and DAGs: a := b *-c + b*-c

:= :=

a + a +

* * *

b - (uni) b - (uni) b - (uni)

c c c

10
11
12
13
14
15
16

You might also like