1
votes

If I save the grammar

grammar L;

tree: 't' ;
a: tree | 'b' ;

in a file name L.g4 and invoke antlr4 L.g4 (Version 4.7.1) , it outputs an incomprehensible error message without any line or column numbers:

L.g4::: syntax error: mismatched character '|' expecting 'g'

The ::: part is where the line/column numbers of the errors usually go.

If I instead save

grammar L;

tre: 't' ;
a: tre | 'b' ;

as L.g4 and run antlr4 on it, it runs without errors.

What's wrong with the tree identifier? It's not listed in the list of reserved keywords:

import, fragment, lexer, parser, grammar, returns, locals, throws, catch, finally, mode, options, tokens

1

1 Answers

1
votes

tree is a reserved keyword in ANTLR v3. I guess the documentation could be incomplete or it could be a bug. The documentation also mentions non-keywords that can't be used as rule name (like the word rule), so it's possible that tree is similar - not a real keyword yet not allowed everywhere.

According to this unresolved ANTRL4 bug report for your issue, it works if you remove the space between tree and :.