Symbol Table Entries

Symbol_table_entry class is a base class. Several different subclasses of symbol table entries will be derived from this class, each designed to store and provide attribute information for the various identifiers that are encountered in the source program.

Symbol table entry base class

Public members:

virtual string get_name() {return name;}
virtual TypeInfo get_type() {return 0;}
virtual int is_variable() {return 0;}
virtual int is_keyword() {return 0;}
virtual int is_proc() {return 0;}
virtual int is_function() {return 0;}
virtual int is_function_result() {return 0;}
virtual int is_parameter() {return 0;}
virtual int is_array() {return 0;}
virtual void print ();
Protected members: Notes Derived classes

You need classes for the following entry types. The required fields are indicated for each.

Note that function result variables are just simple variables (i.e., they have the same fields), except that the method is_function_result is defined differently.

Here is one example of an implementation for the derived classes for Variable_entry class. Note that the virtual functions is_variable and print are redefined. Note also that a value is passed to the constructor to set the return value of is_parameter appropriately; since it defaults to 0, this value can be omitted when instantiating a variable entry that is not a parameter. You will have to do the same thing for array entries, which can also be parameters.

Public members:

Variable_entry() {;}
Variable_entry(string Name, TypeInfo Type, int p=0);
/* inside this constructor set parm = p */
int is_variable() {return 1;};
int is_parameter() {return parm;};
void print();
Private members:
TypeInfo type;
int address;
int parm;