The Dump Statement

This page last updated: Sunday September 27, 1998 01:07

The dump statement is a symbol table debugging tool that takes optional arguments. If no arguments are given, it prints the contents of the entire symbol table using sym_dump(). With string arguments, it looks up each argument using sym_lookup() and prints a dump of only those symbol table entries.

dump;         <-- no arguments; dumps the whole symbol table
dump "abc";
dump "abc","mysymbol","id3";
dump 1,2;     <-- invalid; only strings can be looked up as identifiers

The argument is an expression, so the usual expression parser will handle collecting the arguments and pushing them onto the value stack.  All the dump statement need do is pop each expression off the stack, check its type (only strings can be looked up in the symbol table), perform the appropriate look-up action in the symbol table using sym_lookup(), and dump the corresponding symbol table entry using sym_dump().

If there are no arguments between dump and the following semicolon, dump all the symbols in the symbol table.

The Dump output might look something like this, only nicer:

Symbol       Line  Type     Value
------------ ----  ------   ---------------------------------------------
abc             1     INT   32769
mysymbol        2  STRING   Hello World!
id3             3     INT   -65339

The list of output fields might also include other fields in your symbol table. Print whatever information you need to assure yourself that your symbol table is working correctly.

To preserve the integrity of the symbol table and protect its internal details from external view, make sure your parser does not directly access the symbol table data structures. It must call symbol table functions to do the dump work. Only the symbol table functions should know the inner workings of the symbol table data structures.