Modeling Scope table lookup

In the Scope Class, we need to have a table (Map) which can be implemented as HashMap for instance. Regarding the key, tokens cannot be used as a key I guess since each token does have a unique location(for example we might have two token which represent two occurrences for the same identifier at two different locations i.e b-expression: x+x hence for the map they are considered different tokens). An alternative might be using the token text as a key in the map. Does using the token text as key for the map lead to problems afterward?

1 Like

When you use a variable, all you have got is its name (i.e. the “token text” though it really is the name), and you are correct that for looking things up in the scope, the name is all you care about.