Verfication Scope

Since we need to name the variables apart to handle shadowing, it is mentioned in the project specification that

This can be achieved by appending a unique number to the name of a varibale.

However, since a variable might have arbitrary many occurances, one needs somehow to refer to the variable’s declaration. Moreover, it was recommended in the project persentation to implement a method Declaration::getFormulaVar, but I don’t really get the purpose of it.

My question is: do I need to have a scope class devoted to verification? Is there some more simple solution?



  • Every declaration gets a unique ID
    • a private static int is completely sufficient here.
  • Every use of a variable knows its declaration (by having the type checker annotate it).
  • Declaration::getFormulaVar returns something like originalName + "_" + uniqueID
1 Like

Oh yes, I totally forgot about the declaration field in the VarExpression. Thanks!

An issue here would be that Declaration is an interface, whose fields are final.
There are 2 classes which implement it: GlobalVariable and DeclarationStatement and there are function parameters which exist in the class FunctionDefinition, so how can I issue a unique ID for every case of those?

I thought about using the line and column info from token but it seems that it does not make sense, especially when it comes to parameters.

Good question. I don’t think there is a canonical design. You will figure something out :slightly_smiling_face: It is, after all, your project.

Note that interfaces can have static fields and members as if they were normal classes.

Also, your interface should have a subclass for / be implemented by each possible kind of declaration, also including function definitions (which declare the function) and parameters (which declare the parameter).