|Symbol table management email@example.com (hantheman) (2002-07-02)|
|Re: Symbol table management firstname.lastname@example.org (Ralph Corderoy) (2002-07-04)|
|Re: Symbol table management email@example.com (George Russell) (2002-07-04)|
|Symbol table management firstname.lastname@example.org (1995-10-18)|
|From:||"George Russell" <email@example.com>|
|Date:||4 Jul 2002 23:20:47 -0400|
|Posted-Date:||04 Jul 2002 23:20:47 EDT|
> 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
All this varies of course with your scoping rules - I have no overloading,
no shadowing declarations.
Return to the
Search the comp.compilers archives again.