what can i do for defining scope of variable? (creating a new symbol table for each function and block or ...)
I'm use lex and yacc and i wrote a very basic interpreter. syntax is like as C
scope of the variables
Keep a stack of scopes. Each time you enter a new scope, push a scope onto the stack. New variables are always added to the top scope.
This enables you to do as in C++ where a variable can be redeclared in a new scope and the highest-scoped version of that variable is what is used (and this typically only leads to bugs, but you can support it if you want).
When you leave a scope, pop the top scope off the stack and all the variables declared in it are gone. Simple.
L. Spiro
This enables you to do as in C++ where a variable can be redeclared in a new scope and the highest-scoped version of that variable is what is used (and this typically only leads to bugs, but you can support it if you want).
When you leave a scope, pop the top scope off the stack and all the variables declared in it are gone. Simple.
L. Spiro
I restore Nintendo 64 video-game OST’s into HD! https://www.youtube.com/channel/UCCtX_wedtZ5BoyQBXEhnVZw/playlists?view=1&sort=lad&flow=grid
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement