Unhelpful error message in ANTLR 4.5

46 views
Skip to first unread message

Runhang Li

unread,
Jan 22, 2018, 12:17:11 PM1/22/18
to antlr-discussion
Hi, all

I discovered an issue in ANTLR 4.5 and would like to seek some help here.

This issue is reproducible with:

    ANTLR version 4.5
    Code generation target: Java

With the following grammar and start rule name [1] being `exprEof`,

grammar G;

exprEof
    : expr EOF
    ;

expr
    : Uident
    | expr '(' Uident ')'
    ;

Uident
    : [A-Z][a-z]*
    ;

WS
    : [ \n\t]+ -> skip
    ;

expression `Foo(A B)` gives me meaningful error message as expected:

line 1:6 extraneous input 'B' expecting ')'
(exprEof (expr (expr Foo) ( A B )) <EOF>)

However, without changing start rule name, **if I add a new rule expr2, which will not be used at all**:

grammar G;

exprEof
    : expr EOF
    ;

expr
    : Uident
    | expr '(' Uident ')'
    ;

expr2
    : expr '(' Uident ')'
    ;

Uident
    : [A-Z][a-z]*
    ;

WS
    : [ \n\t]+ -> skip
    ;

Error message then becomes the following, which gives no clue at all:

line 1:3 mismatched input '(' expecting <EOF>
(exprEof (expr Foo) ( A B )) 

 

Mike Lischke

unread,
Jan 23, 2018, 3:27:32 AM1/23/18
to antlr-di...@googlegroups.com
expression `Foo(A B)` gives me meaningful error message as expected:

line 1:6 extraneous input 'B' expecting ')'
(exprEof (expr (expr Foo) ( A B )) <EOF>)

However, without changing start rule name, **if I add a new rule expr2, which will not be used at all**:

Error message then becomes the following, which gives no clue at all:

line 1:3 mismatched input '(' expecting <EOF>
(exprEof (expr Foo) ( A B )) 

Looks like a bug in ANTLR4 to me. Try the latest one (4.7.1) to see if that has been fixed.


Runhang Li

unread,
Feb 20, 2018, 4:50:40 PM2/20/18
to antlr-discussion
Hi, Mike

I can still reproduce this in 4.7.1.

We are pretty troubled by this bug.Do you have any suggestion what we can do here? We are very happy to help.

Mike Lischke

unread,
Feb 21, 2018, 2:49:39 AM2/21/18
to antlr-di...@googlegroups.com
> I can still reproduce this in 4.7.1.
>
> We are pretty troubled by this bug.Do you have any suggestion what we can do here? We are very happy to help.

What's the test input for that grammar? Have you tried varying things like the name of the new rule, its position, its content?

Mike
--
www.soft-gems.net

Reply all
Reply to author
Forward
0 new messages