
- Definition:
A symbol Table is a data structure containing a record for
each identifier, with fields for the attributes of the id. It
allows us to find the record for each identifier quickly and to store
or retrieve data from that record quickly.
- What Attributes?
- position in the input stream (start position, line number, ...);
- type (const, variable, type, procedure...);
- scope (program, procedure, ...);
- ...
- When to insert an entry?
When an id in the source program is detected by the scanner, it is
inserted into the symbol table.
- When to fill in the attributes?
At various times. The attributes cannot normally be determined during
lexical analysis, and are filled in as the information becomes
available.
- Who needs which attributes?
- Semantic analysis and intermediate code generation need to know
the types of identifiers so that they can generate the proper
operations on them;
- Code generator needs to know the storage assigned to
identifiers so that it can generate the proper code to store and
access it;
- ...
- What operations?
- insert(s, t): create a new entry for string s, return index of
the new entry t
- lookup(s): search for string s, return index in the symbol table
|