I am developing a small object-based programming language.
I lost a little simple thing. I implemented a couple of visitors who collect the names, types and parameters of classes, method headers and fields from the AST.
My problem is what to do with the body of my methods now. Should I add local variables to the character table?
At first, this may seem like a good idea until you think about a case such as:
void myMethod() { int i; while (something) { int y; } while (something) { int y; } }
If I just added the variables i
and y
to the character table, and I would understand that y
is a duplicate variable.
Keep in mind that I know about symbol table clouds. What I donβt understand is whether to add and remove information on the fly in the Symbols table while inside the method, or if I have to constantly add data to the symbol table when visiting the method (for example, I did this with fields of class + methodsheader).
Repeat question: when visiting the body of the method, should I leave the Symbol Table at the end of the visit in the same way as it was before the visit?
Thanks!
source share