Attribute Grammar Examples and Symbol Tables 66.648 Compiler Design Lecture (02/23/98) Computer Science Rensselaer Polytechnic.

Slides:



Advertisements
Similar presentations
SYMBOL TABLES &CODE GENERATION FOR EXECUTABLES. SYMBOL TABLES Compilers that produce an executable (or the representation of an executable in object module.
Advertisements

Semantic Analysis and Symbol Tables
Symbol Table.
Intermediate Code Generation
Chapter 6 Type Checking. The compiler should report an error if an operator is applied to an incompatible operand. Type checking can be performed without.
Semantic Analysis Chapter 6. Two Flavors  Static (done during compile time) –C –Ada  Dynamic (done during run time) –LISP –Smalltalk  Optimization.
CSI 3120, Implementing subprograms, page 1 Implementing subprograms The environment in block-structured languages The structure of the activation stack.
1 Compiler Construction Intermediate Code Generation.
Generation of Intermediate Code Compiler Design Lecture (03/30//98) Computer Science Rensselaer Polytechnic.
Structures. An array allows us to store a collection of variables However, the variables must be of the same type to be stored in an array E.g. if we.
Type Checking Compiler Design Lecture (02/25/98) Computer Science Rensselaer Polytechnic.
The Symbol Table Lecture 13 Wed, Feb 23, The Symbol Table When identifiers are found, they will be entered into a symbol table, which will hold.
Dale/Weems/Headington
Type Checking- Contd Compiler Design Lecture (03/02/98) Computer Science Rensselaer Polytechnic.
Elaboration or: Semantic Analysis Compiler Baojian Hua
Context-sensitive Analysis, II Ad-hoc syntax-directed translation, Symbol Tables, andTypes.
Types Type = Why? a set of values
Cs164 Prof. Bodik, Fall Symbol Tables and Static Checks Lecture 14.
CSc 453 Semantic Analysis Saumya Debray The University of Arizona Tucson.
Semantic Analysis Legality checks –Check that program obey all rules of the language that are not described by a context-free grammar Disambiguation –Name.
COMPILERS Semantic Analysis hussein suleman uct csc3005h 2006.
CS212: DATA STRUCTURES Lecture 10:Hashing 1. Outline 2  Map Abstract Data type  Map Abstract Data type methods  What is hash  Hash tables  Bucket.
Runtime Environments Compiler Construction Chapter 7.
1 Semantic Analysis Aaron Bloomfield CS 415 Fall 2005.
INTRODUCTION TO JAVASCRIPT AND DOM Internet Engineering Spring 2012.
Names and Scope. Scope Suppose that a name is used many times for different entities in text of the program, or in the course of execution. When the name.
Chapter 5: Programming Languages and Constructs by Ravi Sethi Activation Records Dolores Zage.
CS212: Object Oriented Analysis and Design Lecture 10: Copy constructor.
Elements of Computing Systems, Nisan & Schocken, MIT Press, 2005, Chapter 11: Compiler II: Code Generation slide 1www.idc.ac.il/tecs.
Hashing Table Professor Sin-Min Lee Department of Computer Science.
Prepared By Ms.R.K.Dharme Head Computer Department.
1 Symbol Tables The symbol table contains information about –variables –functions –class names –type names –temporary variables –etc.
COMPILERS Symbol Tables hussein suleman uct csc3003s 2007.
SB Symbol table handling in ScriptBasic The Module sym.
1 Compiler Construction (CS-636) Muhammad Bilal Bashir UIIT, Rawalpindi.
Basic Semantics Associating meaning with language entities.
1 October 25, October 25, 2015October 25, 2015October 25, 2015 Azusa, CA Sheldon X. Liang Ph. D. Computer Science at Azusa Pacific University Azusa.
Programming Languages by Ravi Sethi Chapter 6: Groupings of Data and Operations.
CS 153: Concepts of Compiler Design October 5 Class Meeting Department of Computer Science San Jose State University Fall 2015 Instructor: Ron Mak
Run-Time Storage Organization Compiler Design Lecture (03/23/98) Computer Science Rensselaer Polytechnic.
RUN-Time Organization Compiler phase— Before writing a code generator, we must decide how to marshal the resources of the target machine (instructions,
1 Compiler Construction (CS-636) Muhammad Bilal Bashir UIIT, Rawalpindi.
Review: Syntax directed translation. –Translation is done according to the parse tree. Each production (when used in the parsing) is a sub- structure of.
ENEE150 – 0102 ANDREW GOFFIN Project 4 & Function Pointers.
Lexical Analysis - Scanner- Contd Computer Science Rensselaer Polytechnic Compiler Design Lecture 3(01/21/98)
Syntax Analysis - Parsing Compiler Design Lecture (01/28/98) Computer Science Rensselaer Polytechnic.
Syntax-Directed Definitions and Attribute Evaluation Compiler Design Lecture (02/18/98) Computer Science Rensselaer Polytechnic.
1 Compiler Construction (CS-636) Muhammad Bilal Bashir UIIT, Rawalpindi.
ICOM 4035 – Data Structures Dr. Manuel Rodríguez Martínez Electrical and Computer Engineering Department Lecture 2 – August 23, 2001.
CS 153: Concepts of Compiler Design September 23 Class Meeting Department of Computer Science San Jose State University Fall 2015 Instructor: Ron Mak
1 Compiler Construction Run-time Environments,. 2 Run-Time Environments (Chapter 7) Continued: Access to No-local Names.
©2004 Joel Jones 1 CS 403: Programming Languages Lecture 3 Fall 2004 Department of Computer Science University of Alabama Joel Jones.
Semantic Analysis Chapter 6. Two Flavors  Static (done during compile time) –C –Ada  Dynamic (done during run time) –LISP –Smalltalk  Optimization.
COMPILERS Semantic Analysis hussein suleman uct csc3003s 2009.
Lecture 9 Symbol Table and Attributed Grammars
Names and Attributes Names are a key programming language feature
Context-Sensitive Analysis
Constructing Precedence Table
Compiler Construction (CS-636)
Semantic Analysis Chapter 6.
CMPE 152: Compiler Design October 4 Class Meeting
Chapter 6 Intermediate-Code Generation
Local Variables, Global Variables and Variable Scope
Three-address code A more common representation is THREE-ADDRESS CODE . Three address code is close to assembly language, making machine code generation.
Semantic Analysis Chapter 6.
Symbol Table 薛智文 (textbook ch#2.7 and 6.5) 薛智文 96 Spring.
COMPILERS Semantic Analysis
Language Definitions Chap. 3 of Orange Book.
SYMBOL TABLE Chuen-Liang Chen Department of Computer Science
Lexical Analysis - Scanner-Contd
Presentation transcript:

Attribute Grammar Examples and Symbol Tables Compiler Design Lecture (02/23/98) Computer Science Rensselaer Polytechnic

Lecture Outline Examples Examples Symbol Tables Symbol Tables Administration Administration

Example Question 5.5, 5.4 and 5.8 in the text book. Qn: 5.5 Give a syntax directed translation scheme to differentiate expressions. D/dx (x*x + x) = 1*x + x* How do we do it?

Yet Another Example qn 5.8 To get the value of a binary number: qn 5.8 To get the value of a binary number: s --> L.L | L L --> L B | B B --> 0 | 1 We can do the problem in two steps: S--> L and S -->.L. Then how do we combine

Qn. 5.4 Give a syntax directed translation scheme to remove extra parentheses. (( x * x)) = x * x (x*x) +x x * x +x (x+x) *x = (x+x) * x How do we do this in terms of attributes? Yet Another Example

In this example, we will explore how we take care of identifiers and types. Simple Declarative language

Symbol Table The symbol tables - repository of all information within a compiler. All parts of a compiler communicate thru these table and access the data-symbols. Symbol tables are also used to hold labels, constants, and types. Symbol tables map names ( constants, identifiers, label numbers) into sets of symbols. Different names have different attributes. - for identifiers, it could be its type, its location in a stack frame, its storage class etc.

Symbol Tables- Contd Symbols are collected into symbol tables. The symbol-table module manages symbols and tables. Symbol Management should also deal with scope and visibility that is imposed by the language. Symbol Tables are usually lists of hash tables, one for each scope.

Symbol Table- Contd A typical table (see Fraser and Hanson book page 40) typedef struct table *Table; struct table { int level ; /* scope value */ Table previous; struct entry { struvt symbol sym; struct entry *link; } *buckets[256]; Symbol all; } ;

Symbol Table- Contd The buckets field is an array of pointers to the hash chains. Previous field points to the table of the enclosing scope. In each table structure all heads a list of symbols in this and enclosing scopes. Symbol Table entries are (can be ) non-uniform (variable sized). Depending upon what the identifier represents. (We will see how a symbol is defined soon). Symbol Table look-up is performed in the context of a current scope, global, local, structured type.

Symbol Table Interface Create_scope(parent_scope) - return index for a new scope contained in a parent scope. Insert_scope(scope,name) - insert identifier into the specified scope of a symbol table. Lookup(scope,name) - look up identifier in specified scope. Delete_scope(scope) - delete specified scope and all symbol table entries that it contains

Symbols Typedef struct symbol *Symbol; struct symbol { char *name; int scope; int scope; Coordinates src; Symbol up; Coordinates src; Symbol up; List uses; int sclass; /*storgeclass*/ List uses; int sclass; /*storgeclass*/ float ref; float ref; union { constants,,function symbols, globals, temporaries} u; union { constants,,function symbols, globals, temporaries} u; Xsymbol x; /* debugger infmtion */ } ; Xsymbol x; /* debugger infmtion */ } ;

U field The u field supplies additional data for labels, structure and union types, static variables and temporary variables. We will discuss this in later classes.

Comments and Feedback Please read chapter 6 and look at the sample compilers in the course home page to get an over all picture. All the programs discussed to- day are also in the home page.