Where to get the statements for checkSemantics()

In order to get more info about the AST tree, I assume we should create a Statement property for the AST tree right :? So that I can have the code (namely the AST structure) for checkSemantics and further executions. I guess, because just having External Declarations does not help much when we want to analyse expressions and do the type checking.

What would that do?

The program is well-typed exactly if all external declarations are well-typed. Note that those (in particular, function definitions) contain statements.

The statement property would let me to reach all nodes (maybe recursively?) and to check whether I have all statements well typed.
But I guess from what you are saying that, I don’t need to have that since external declarations would suffice for all semantic checking and also let me for reaching all statements :?

Consider, for example, the following program

int foo() {
  return 1 + 2;
}

after parsing, your list of external declaration will contain one function definition. You then check whether that function definition is well-typed. It only is if the contained block { return 1 + 2; } is. Thus you then check that statement for well-typedness, which of course also involves checking whether 1 + 2 has appropiate type…

2 Likes