Assuming the entry point of your grammar is translation_unit
, it looks like the parser simply stops after it matched a single external_declaration
. Try adding the EOF
(end of file) token at the end of that rule so that the parser is forced to match the entire input:
translation_unit
: external_declaration+ EOF
;
However, I don't see how an external_declaration
would ever match an if
-statement (a selection_statement
) in your grammar. Perhaps you want to add a statement
to your external_declaration
:
translation_unit
scope Symbols; // entire file is a scope
@init {
$Symbols::types = new HashSet();
}
: (external_declaration)+ EOF
;
external_declaration
: function_definition
| declaration
| statement
;
after which your input will get properly parsed.