Testing and debugging symbol tables
You can test your symbol tables by writing many test cases and verifying whether they obtain the expected undeclared or redeclared variable error messages. But nothing says confidence like an actual visual depiction of your symbol tables.
If you have built your symbol tables correctly by following the guidance in this chapter, then there should be a tree of symbol tables. You can print out your symbol tables using the same tree printing techniques that were used to verify your syntax trees in the previous chapter, using either a textual representation or a graphical one.
Symbol tables are slightly more work to traverse than syntax trees. To output the symbol table, you need to output information for the table and then visit all the children, not just look one up by name. Also, there are two classes involved: symtab
and symtab_entry
. Suppose you start at the root symbol table. In Unicon, to iterate through all the symbol tables, use the...