|
Hints for implementing symbol tablesUsing CYou may use either the tsearch or the hsearch C library calls. On Unix, look at the on-line documentation (man tsearch or man hsearch). Both manual pages include examples. My suggestion is to implement the symbol table as an array of binary search trees (but opening and closing new scopes following the LIFO ordering), using the tsearch calls. Look at this example. You may also use a sorted array of symbol table entries and then use the bsearch C library call (on Unix, look at the on-line documentation: man bsearch). Using C++You may use the mapping classes provided with the Standard
Template Library (STL), which is available with our installation of
GNU C++. My suggestion is to implement the symbol
table as an array (or alternatively as a
vector) of
map's. The following two small programs illustrate the use of the
two types: vector.cpp and map.cpp.
Both examples should be compiled by g++ (no additional
options are needed).
Using JavaYou should have no problems implementing the symbol table utilizing classes available in the java.util package. My suggestion is to implement the symbol table as an array (or possibly as a Vector) of HashMap's. |