Confusion About Declarations

Hello,

i am a bit confused because the grammar states that declarations only can appear in blocks but in ASTFactory there is a method called createDeclarationStatement so i wonder if a Declaration is also a valid Statement (even without appearing in a block).

A DeclarationStatement is a valid statement that can only appear inside a block (block as defined in the grammar, not as in BlockStatement).

However, that is not something to need to check:
A declaration can either be inside a function or not. If it’s in a function, it’s also in a block (as you can see in the grammar).

If it is not in a function, then it is an ExternalDeclaration. The parser will detect this and call the appropriate method.