I am creating an AST, and I am currently introducing the concept of "scope". By implementing a scope, wherever an identifier (variable name) is used, I am able to determine its original declaration.
For the scope object, I was going to implement a dictionary as the underlying data structure. The dictionary would be keyed with the identifier object, with the value being the declaration object. The declaration object also contains a reference to the same identifier. So, something like:
class Identifier() {
string name;
}
class Declaration() {
Type type;
Identifier ident;
}
class Scope() {
Dictionary<Identifier,Declaration> identifiers;
}
What I want to know is, is keying a dictionary with a property of the key's corresponding value bad practice? Is there a better way to do this?