Download presentation
Presentation is loading. Please wait.
Published byἈνίκητος Πυλαρινός Modified over 5 years ago
1
SYMBOL TABLE Chuen-Liang Chen Department of Computer Science
and Information Engineering National Taiwan University Taipei, TAIWAN
2
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
3
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 );
4
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
5
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
6
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) .
7
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
8
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) -
9
Advanced features export rules import rules altered search rules
Pascal’s with Ada’s use implicit declaration overloading forwarding reference QUIZ: how?
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.