Reputation: 101
I have a sample grammar written in ANTLR 4
query : select from ';' !? EOF!
I have understood
query : select from ';'
how it works
What does !? EOF!
means in the grammar and how it works?
Upvotes: 1
Views: 5806
Reputation: 170278
The exclamation marks is used in ANTLR v3 grammars to denote that a certain node should be omitted from the generated AST. Since ANTLR v4 does not have AST's, this construct is no longer used.
In both v3 and v4, the ?
denotes that a rule (lexer or parser) is optional and EOF
means the end-of-file constant.
To summarize ';'!?
means: optionally match a ';'
and exclude it from the AST. And EOF!
means: match the end-of-file and exclude this token from the AST.
So, the v3 parser rule:
query : select from ';'!? EOF!
should look like this in a v4 grammar:
query : select from ';'? EOF
Upvotes: 4