SYMBOL TABLE Chuen-Liang Chen Department of Computer Science

Slides:



Advertisements
Similar presentations
Chap 8 Symbol Table name attributes : :
Advertisements

1 Symbol Tables. 2 Contents Introduction Introduction A Simple Compiler A Simple Compiler Scanning – Theory and Practice Scanning – Theory and Practice.
CS 11 C track: lecture 7 Last week: structs, typedef, linked lists This week: hash tables more on the C preprocessor extern const.
Symbol Table.
Programming Paradigms Introduction. 6/15/2005 Copyright 2005, by the authors of these slides, and Ateneo de Manila University. All rights reserved. L1:
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.
Honors Compilers Semantic Analysis and Attribute Grammars Mar 5th 2002.
Lecture 11 March 5 Goals: hashing dictionary operations general idea of hashing hash functions chaining closed hashing.
Tutorial 6 & 7 Symbol Table
Semantic analysis Enforce context-dependent language rules that are not reflected in the BNF, e.g.a function must have a return statement. Decorate AST.
Stacks.
Semantic analysis Enforce context-dependent language rules that are not reflected in the BNF, e.g.a function must have a return statement. Decorate AST.
Types Type = Why? a set of values
Cs164 Prof. Bodik, Fall Symbol Tables and Static Checks Lecture 14.
國立台灣大學 資訊工程學系 薛智文 98 Spring Symbol Table (textbook ch#2.7 and 6.5 )
Chap. 8, Declaration Processing and Symbol Tables J. H. Wang Dec. 13, 2011.
CS 202, Spring 2003 Fundamental Structures of Computer Science II Bilkent University1 Hashing CS 202 – Fundamental Structures of Computer Science II Bilkent.
COMPILERS Semantic Analysis hussein suleman uct csc3005h 2006.
1 Semantic Analysis Aaron Bloomfield CS 415 Fall 2005.
Attribute Grammar Examples and Symbol Tables Compiler Design Lecture (02/23/98) Computer Science Rensselaer Polytechnic.
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.
1 Symbol Tables The symbol table contains information about –variables –functions –class names –type names –temporary variables –etc.
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.
Slide 1 Linked Data Structures. Slide 2 Learning Objectives  Nodes and Linked Lists  Creating, searching  Linked List Applications  Stacks, queues.
CS536 Semantic Analysis Introduction with Emphasis on Name Analysis 1.
Copyright © 2002 Pearson Education, Inc. Slide 1.
ENEE150 – 0102 ANDREW GOFFIN Project 4 & Function Pointers.
Bernd Fischer RW713: Compiler and Software Language Engineering.
1 Compiler Construction (CS-636) Muhammad Bilal Bashir UIIT, Rawalpindi.
CS412/413 Introduction to Compilers Radu Rugina Lecture 11: Symbol Tables 13 Feb 02.
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.
COMPILERS Semantic Analysis hussein suleman uct csc3003s 2009.
Lecture 9 Symbol Table and Attributed Grammars
Storage and File Organization
Chapter 10 : Implementing Subprograms
Java Array Object Chuen-Liang Chen Department of Computer Science
Context-Sensitive Analysis
Constructing Precedence Table
CS522 Advanced database Systems
MIS 215 Module 1 – Unordered Lists
Semantic Analysis with Emphasis on Name Analysis
CS 153: Concepts of Compiler Design October 5 Class Meeting
Cinda Heeren / Geoffrey Tien
Introduction to Hashing - Hash Functions
DECLARATION Chuen-Liang Chen Department of Computer Science
CMPE 152: Compiler Design February 6 Class Meeting
CMPE 152: Compiler Design September 25 Class Meeting
CMPE 152: Compiler Design September 18 Class Meeting
CMPE 152: Compiler Design October 4 Class Meeting
CMPE 152: Compiler Design September 20 Class Meeting
Advance Database System
Queues Jyh-Shing Roger Jang (張智星)
CS 432: Compiler Construction Lecture 11
CMPE 152: Compiler Design February 28 Class Meeting
CMPE 152: Compiler Design February 7 Class Meeting
File Organization.
Programming Languages and Paradigms
Symbol Table 薛智文 (textbook ch#2.7 and 6.5) 薛智文 96 Spring.
CSE 3302 Programming Languages
COMPILERS Semantic Analysis
CMPE 152: Compiler Design February 21 Class Meeting
(1 - 2) Introduction to C Data Structures & Abstract Data Types
CMPE 152: Compiler Design February 26 Class Meeting
RUN-TIME STORAGE Chuen-Liang Chen Department of Computer Science
CMPE 152: Compiler Design February 7 Class Meeting
Presentation transcript:

SYMBOL TABLE Chuen-Liang Chen Department of Computer Science and Information Engineering National Taiwan University Taipei, TAIWAN

Introduction (1/2) Introduction (1/2) function dictionary interface (operations) typedef char string[MAXSTRING]; typedef struct symtab { ... } *symbol_table; /* a pointer */ typedef struct id_entry { ... } id_entry; /* Create a new (empty) symbol table . */ extern symbol_table create(void); /* Remove all entries in table and destroy it. */ extern void destory(symbol_table table); name semantic meaning attribute

Introduction (2/2) /* Enter name in table; return a reference to the entry corresponding to name * and a flag to indicate whether the name was already present. */ extern void enter( symbol_table table, const string name, id_entry *entry, boolean *present ); /* Search for name is table; return a reference to the entry corresponding to name * (if there is one) and a flag to indicate whether the name was present. */ extern void find( const symbol_table table, const string name, /* Associate the attrs record with entry. */ extern void set_attributes( id_entry *entry, const attributes *attrs ); /* Get the attributes record associated with entry. */ extern void get_attributes( const id_entry entry, attributes *attrs );

Basic implementation techniques considerations insert time u search time storage utilization (especially, “name” field) QUIZ: how to handle “name” field efficiently? and so on unordered list array u linked list ordered list array binary search tree with balancing technique hash table with chaining (linked list, binary tree) QUIZ: comparison

Block-structured symbol tables nested name scopes declare H, A, L : Integer; begin X, Y : Real; ... H, A(integer), L, X, Y are visible end; A, C, M : Character; ... H, L, A(character), C, M are visible problem -- a variable may be visible in one place and invisible in another place approaches 1. an integrated table 2. individual table per scope

Integrated table for all scopes name + scope number global hash table implementation of nested scopes hash key : name only QUIZ: how about binary tree implementation? QUIZ: what to do, when a scope is closed? drawbacks? A(3) hash table chained entries for names (with scope numbers) L(1) A(1) C(3) H(1) M(3) .

Individual table per scope scope stack scopes are opened and closed in LIFO manner interface extern void sts_push(const symbol_table table); extern symbol_table sts_pop(void); extern symbol_table sts_current_scope(void); /* for insertion */ /* Search stack of tables for name; return a reference to the entry corresponding to * name (if there is one) and a flag to indicate whether the name was present. */ extern void sts_find( const string name, id_entry *entry, boolean *present ); QUIZ: drawbacks? QUIZ: comparison of two approaches H,A,L A,C,M individual symbol tables

Symbol table for fields/records example record declaration l approach 2 A, R : record A : Integer; X : record A : real; C : boolean; end; example field references -- A.X.A R.X.C approach 1 (A,0) 1 (R,0) 2 (A,1) - (X,1) 3 (A,3) - (C,3) - (A,2) - (X,2) 4 . . . A R C real bool X int (A,4) - (C,4) -

Advanced features export rules import rules altered search rules Pascal’s with Ada’s use implicit declaration overloading forwarding reference QUIZ: how?