checkSemantics()

Regarding the class Compiler, if I’m not mistaken, the method checkSemantics() should apply the static semantics rules on the AST, which it gets from the parsing part, and annotate it with semantics information. However, there are two fields in Compiler a diagnostic and astFactory (which I added) and there is no parameter for checkSemantics(). I’ve read the tests in order to figure out how the method checkSemantics() operates on the AST or even get it, but I couldn’t. Therefore, my question is, how the AST is delivered to checkSemantics() in the class Compiler?

The compiler has the AST factory.
And the AST factory knows everything important about the program.
It has all connections to the relevant program parts for static semantics checking.
Take a look at what you store inside the AST factory.

1 Like

According to the project specification, the only thing to store inside ASTFactory is a list of external declarations. All other methods are factory methods.

Do you mean that: all nodes of AST (except external declarations) are children of the function definitions?

Yes, in the end, the program is just the list of declarations you have constructed and stored in createExternalDeclaration and createFunctionDefinition. All constructed AST nodes (that are relevant for further execution) eventually end up in there.

1 Like

How can I get them (external decl.) from the ASTfactory? I tried to use a getter but it doesn’t work since the ASTFactory interface doesn’t have a getter too.

Since you create and store the ASTFactory yourself in the compiler, you can just change the field to MyASTFactory (or whichever name your implementation is called). This allows you to call any additional methods you add.

1 Like