Finding redeclared variables
When a variable has been declared, most languages report an error if the same variable is declared again in the same scope. The reason for this is that within a given scope, the name must have a single, well-defined meaning. Trying to declare a new variable would entail allocating some new memory and from then on, mentioning that name would be ambiguous. If the x
variable is defined twice, it is unclear to which x
any given use refers. You can identify such redeclared variable errors when you insert symbols into the symbol table.
Inserting symbols into the symbol table
The insert()
method in the symbol table class calls the language’s underlying hash table API. The method takes a symbol, a Boolean isConst
flag, and an optional nested symbol table, for symbols that introduce a new (sub)scope. The Unicon implementation of the symbol table’s insert()
method is shown here. If you go to https://github.com/PacktPublishing/Build-Your-Own...