The symbol table displays identifiers (usually with a domain name prefix) for information about this identifier, for example, its symbol type (local variable / parameter / function / class, etc.), data type, its order relative to other identifiers in the same volume , in its original code line, etc. A symbol table can be generated by traversing the abstract syntax tree, always keeping track of which area you are in, and adding information to the symbol table whenever you click on a variable declaration. In your example, a part of the symbol table may look like this (matching the symbol type, data type, position, and line of the source code):
MULTIPLY.A -> {"LOCAL", "INT", 0, 4} MULTIPLY.B -> {"LOCAL", "INT", 1, 4} MULTIPLY.C -> {"LOCAL", "INT", 2, 4} MULTIPLY.Aop -> {"FUNCTION", "INT", 3, 4} MULTIPLY.Aop.A -> {"INOUTPARAM", "INT", 0, 6}
Now you can resolve all references to variables. For example, in the expression A := A + 1 , if you know that your current scope is MULTIPLY.Aop , the MULTIPLY.Aop table will let you know that this A is an INT input / output parameter and that it is the first parameter (this information will allow you generate a stack address offset so you can load / save the variable).
source share