Sign in to follow this  

scope of the variables

This topic is 2307 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites

This topic is 2307 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this