Compiler Construction

Slides:



Advertisements
Similar presentations
CPSC 388 – Compiler Design and Construction
Advertisements

SYMBOL TABLES &CODE GENERATION FOR EXECUTABLES. SYMBOL TABLES Compilers that produce an executable (or the representation of an executable in object module.
Intermediate Code Generation
Intermediate Code Generation. 2 Intermediate languages Declarations Expressions Statements.
8 Intermediate code generation
Chapter 8 Intermediate Code Generation. Intermediate languages: Syntax trees, three-address code, quadruples. Types of Three – Address Statements: x :=
1 Compiler Construction Intermediate Code Generation.
Generation of Intermediate Code Compiler Design Lecture (03/30//98) Computer Science Rensselaer Polytechnic.
CPSC Compiler Tutorial 9 Review of Compiler.
Environments and Evaluation
Syntax Directed Translation. Syntax directed translation Yacc can do a simple kind of syntax directed translation from an input sentence to C code We.
The TINY sample language and it’s compiler
Review: –What is an activation record? –What are the typical fields in an activation record? –What are the storage allocation strategies? Which program.
1 Compiler Construction (CS-636) Muhammad Bilal Bashir UIIT, Rawalpindi.
Unit-1 Introduction Prepared by: Prof. Harish I Rathod
CS536 Semantic Analysis Introduction with Emphasis on Name Analysis 1.
1 Compiler & its Phases Krishan Kumar Asstt. Prof. (CSE) BPRCE, Gohana.
1 Nonrecursive Predictive Parsing  It is possible to build a nonrecursive predictive parser  This is done by maintaining an explicit stack.
What am I? while b != 0 if a > b a := a − b else b := b − a return a AST == Abstract Syntax Tree.
Programming Language Concepts (CIS 635) Elsa L Gunter 4303 GITC NJIT,
1 Structure of a Compiler Source Language Target Language Semantic Analyzer Syntax Analyzer Lexical Analyzer Front End Code Optimizer Target Code Generator.
Three Address Code Generation of Control Statements continued..
CS 404Ahmed Ezzat 1 CS 404 Introduction to Compiler Design Lecture 10 Ahmed Ezzat.
7. Symbol Table Chih-Hung Wang Compilers References 1. C. N. Fischer and R. J. LeBlanc. Crafting a Compiler with C. Pearson Education Inc., D.
Translation Scheme for Addressing Array Elements
System Software Theory (5KS03).
Introduction Chapter : Introduction.
PRINCIPLES OF COMPILER DESIGN
Chapter 1 Introduction.
Chapter 5- Assembling , Linking, and Executing Programs
Lexical and Syntax Analysis
A Simple Syntax-Directed Translator
Compiler Construction (CS-636)
8. Symbol Table Chih-Hung Wang
Compilers Principles, Techniques, & Tools Taught by Jing Zhang
Semantic Analysis with Emphasis on Name Analysis
Chapter 1 Introduction.
-by Nisarg Vasavada (Compiled*)
History of compiler development
Compiler Construction
Chapter 1: Introduction to Compiling (Cont.)
Compiler Construction
Intermediate Code Generation
Compiler Optimization and Code Generation
and Executing Programs
CS 3304 Comparative Languages
Compiler Construction
Computer Programming Machine and Assembly.
Compiler Construction
Compiler Construction
Query Optimization CS 157B Ch. 14 Mien Siao.
Intermediate code generation
Three-address code A more common representation is THREE-ADDRESS CODE . Three address code is close to assembly language, making machine code generation.
Compiler design.
Subject: Language Processor
Compiler Construction
Compiler Construction
THREE ADDRESS CODE GENERATION
Deletion in AVL Tree There are 5 cases to consider.
Compiler Construction
Compiler Construction
Compiler Construction
Nonrecursive Predictive Parsing
Compiler Construction
Compiler Construction
Compiler Construction
Review: For array a[2,5], how would the memory for this array looks like using row major layout? What about column major layout? How to compute the address.
Compiler Construction
Compiler Construction
Introduction Chapter : Introduction.
Presentation transcript:

Compiler Construction Sohail Aslam Lecture 36 compiler: Bottom-up Parsing

Three-Address Code Three-address code is attractive for several reasons: This is a note compiler: Bottom-up Parsing

Three-Address Code absence of destructive operators gives the compiler freedom to reuse names and values three-address code is reasonably compact: operations are 1 to 2 bytes; addresses are 4 bytes This is a note compiler: Bottom-up Parsing

Three-Address Code absence of destructive operators gives the compiler freedom to reuse names and values three-address code is reasonably compact: operations are 1 to 2 bytes; addresses are 4 bytes This is a note compiler: Bottom-up Parsing

Three-Address Code many modern processors implement three-address operations, a three-address code models their properties well This is a note compiler: Bottom-up Parsing

Syntax-directed Translation We now consider syntax-directed translation schemes using three-address code for various programming constructs We start with the assignment statement This is a note compiler: Bottom-up Parsing

Syntax-directed Translation We now consider syntax-directed translation schemes using three-address code for various programming constructs We start with the assignment statement This is a note compiler: Bottom-up Parsing

Production translation scheme S → id = E { p = lookup(id.name); emit( p, ‘=’, E.place); } E → E1 + E2 { E.place = newtemp(); emit( E.place, ‘=’, E1.place, ‘+’, E2.place); } E → E1  E2 ‘’, E2.place); } This is a note compiler: Bottom-up Parsing

Production translation scheme E → – E1 { E.place = newtemp(); emit( E.place, ‘=’, ‘–’ , E1.place); } E → ( E1 ) { E.place = E1.place; } E → id { p = lookup(id.name); emit( E.place, ‘=’, p ); } This is a note compiler: Bottom-up Parsing

Assignment Statement The tranlation scheme uses a symbol table for identifiers and temporaries Every time the parser encounters an identifier, it installs it in the symbol table. This is a note compiler: Bottom-up Parsing

Assignment Statement The tranlation scheme uses a symbol table for identifiers and temporaries Every time the parser encounters an identifier, it installs it in the symbol table. This is a note compiler: Bottom-up Parsing

Assignment Statement The symbol table can be implemented as a hash table or using some other efficient data structure for table. This is a note compiler: Bottom-up Parsing

Assignment Statement The routine lookup(name) checks if there an entry for the name in the symbol table If the name is found, the routine returns a pointer to entry. This is a note compiler: Bottom-up Parsing

Assignment Statement The routine lookup(name) checks if there an entry for the name in the symbol table If the name is found, the routine returns a pointer to entry. This is a note compiler: Bottom-up Parsing

Assignment Statement The routine newtemp() returns a new temporary in response to successive calls Temporaries can be placed in the symbol table This is a note compiler: Bottom-up Parsing

Assignment Statement The routine emit() generates a three-address statement which can either be held in memory or written to a file This is a note compiler: Bottom-up Parsing

Example Here is the bottom-up parse of the assignment statement a = b*-c + b*-c and the syntax-directed translation into three-address code This is a note compiler: Bottom-up Parsing