int b;
is a localDecl
, which according to the block
rule in your grammar cannot appear after the first statement
. If you had instead relaxed your grammar by using the following, then you could have used a parse tree listener to produce a meaningful error message after the parse completed successfully.
block
: '{'
(localDecl ';' | statement)*
expr?
'}'
;