Re: Symbol table management

"George Russell" <george.russell@clara.net>
4 Jul 2002 23:20:47 -0400

          From comp.compilers

Related articles
Symbol table management hantheman12@hotmail.com (hantheman) (2002-07-02)
Re: Symbol table management ralph@inputplus.co.uk (Ralph Corderoy) (2002-07-04)
Re: Symbol table management george.russell@clara.net (George Russell) (2002-07-04)
Symbol table management krotoff@boy.nmd.msu.ru (1995-10-18)
| List of all articles for this month |
From: "George Russell" <george.russell@clara.net>
Newsgroups: comp.compilers
Date: 4 Jul 2002 23:20:47 -0400
Organization: Compilers Central
References: 02-07-009
Keywords: symbols
Posted-Date: 04 Jul 2002 23:20:47 EDT

hantheman wrote:


> My question is simply: what data structure is typically chosen?
> Hash-tables? Trees? The program lang beeing parsed has syntax and
> semantics pretty close to C++.


I have been writing a small imperative language with first class
functions and nested scope, and for me two symbol table
implementations have been useful.


One is a symbol table of identifier -> information i.e. a hashtable
with identifier string as key. The scope level is stored on every
item. On leaving a scope, all entries with that level are removed, i.e
iterating over all items and erasing the matching level. On entering a
scope, a level counter is incremented.


The second is a vector of hashtables - each scope level is a new
hashtable pushed on the end. On leaving a scope, just pop the top item
of the vector off. Global scope at one end, inner most scope is at the
other. You can check varying levels in the table depending on your
scoping rules.


All this varies of course with your scoping rules - I have no overloading,
no shadowing declarations.


HTH
George Russell


Post a followup to this message

Return to the comp.compilers page.
Search the comp.compilers archives again.