The problem is your prog
rule:
prog: kword+
| stat+
;
This rule states that the program consists of one or more kword
rules or one or more stat
rules. There is no program that includes both a kword
and stat
. What you probably meant to write is the following, which allows any sequence of kword
or stat
rules. Note that I changed +
to *
to allow an empty program. Even if your compiler shouldn't allow the program to be empty, this error is better left for validation in a visitor or listener.
prog
: ( kword
| stat
)*
;