Looking up symbols in a SymbolTable

Developer
Jan 26, 2010 at 1:35 AM

Hi!

I'm wondering how should I look up symbols at runtime :)

Let me explain. My program may have two type of functions: 1) defined in a program and 2) implicitly loaded from the run-time library. Functions defined in a program have names (Symbol objects) created by ParsingContext.Symbols at compile-time. Run-time library functions are registered at runtime and their names are created by EvaluationContext.Symbols. So symbol "div" registered in parser's symbol table is not the same as symbol "div" from the run-time library. Text strings are equal, but Symbol objects are different.

When the interpreter encounters symbol "div", it takes symbol created by ParsingContext.Symbols (it is stored as FunctionName in my AST node) and looks up current EvaluationContext.Symbols. EvaluationContext has also symbol "div", but since it is registered at runtime, it is not the same symbol. So for the interpreter it's an undefined symbol :)

I worked around this by keeping parser's symbol table and using it to generate symbol names for library functions in runtime. It works quite well, but I think doing so is apparently wrong. For example, my interpreter could deserialize AST from some external source (compile -> save to XML -> load from XML), so it won't have access to the parser's symbol table anymore.

Please explain how to deal with two different symbol tables in such a case. Thanks :)

 

Coordinator
Jan 26, 2010 at 6:09 PM

yeah, this part is not completed yet. Just put some hacks there to make all modules use the same symbol table. I'm working on it