checkSemantics() confusion

Hi, as I understand checkSemantics() should go through all externalDeclarations and functionDefinitions and check each one of them? I dont understand what should I call for the cheking? should I modify Expression and Statement interfaces and add some functions? if so what are the nessesary functions? I’ve read the paper but it’s all really general how everything works, I need help implementing the semantics part

Yes!

You will need quite a lot. Have a look at the project presentation where we suggest some.

That I understood, One more question, How can I get the Type for every Expression? should I just check the TokenKind or should I create a Type instance from AstFactory inside of an Expression class?

You get the types using the miracle of recursion ™.

For the primary expressions, you have constants (where you can just create an instance of the proper type).
For variables, you will need a scope that allows you to refer back to the declaration, which has the type.

Once you have those, you can determine the type of your unary and binary expressions by getting the type of the subexpression(s) first (recursively) and applying the rules.

To create the actual return value, you can just return a new instance of the proper class. (You’ll likely want to call the constructor directly, using the ASTFactory for this is unnecessarily complicated).

3 Likes