ANTLR4 C# generates different results from Java version (NuGet Antlr4.Runtime.4.4.1-alpha001)

85 views
Skip to first unread message

Roberto Mencia Franco

unread,
Apr 8, 2015, 11:34:32 PM4/8/15
to antlr-di...@googlegroups.com
The problem I've experienced is in the latest C# implementation that comes with as a NuGet package Antlr4.Runtime.4.4.1-alpha001 (I haven't tried in previous ones)
I have reduced the grammar to the bare minimum to show the issue that I'm experiencing.

In the grammar below, to try the error recovery, if I parse :XXXX (which is missing the fieldName) in the error listener that I have added to capture the parser errors I get 1 error "no viable alternative at input ':'"
However, in the parsing tree I get 2 error nodes:
[Antlr4.Runtime.Tree.ErrorNodeImpl] = {:}
[Antlr4.Runtime.Tree.ErrorNodeImpl] = {value}

If I test the same grammar and input using IntelliJIdea ANTLR4 pluggin, I get a different result "extraneous input ':' expecting {'(', Term}"
And the parse tree shows in red the : token but then it recovers and the second token is displayed as a proper tree using the second field rule value, which is what I was expecting.

I'm not sure of the reason, but it seems to me that the C# version is not behaving the same as the Java version.

grammar Combined1;
compileUnit :    field EOF    ;
field:       
    fieldName ':' value   
    |   value;
fieldName:   Term;
value: 
    '(' value ')'   
    |    Term;

Term:    TERM_START_CHAR TERM_CHAR*;
fragment TERM_START_CHAR:   ~( ' ' | '\t' | '\n' | '\r' | ':' );
fragment TERM_CHAR : (TERM_START_CHAR | '.' );
WS  :    [ \t\r\n\f]+ -> skip;


Eric Vergnaud

unread,
Apr 9, 2015, 11:21:26 AM4/9/15
to antlr-di...@googlegroups.com
Hi,

it would be useful to know whether you encounter the same issue with the C# runtime that you can download from the antlr web site.

Eric

robertical .

unread,
Apr 9, 2015, 4:02:07 PM4/9/15
to antlr-di...@googlegroups.com

I have tried with 4.3 from nuget package and also the 4.5 version that I downloaded from the web site and the result is the same.

--
You received this message because you are subscribed to a topic in the Google Groups "antlr-discussion" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/antlr-discussion/_6ixCDtQfFo/unsubscribe.
To unsubscribe from this group and all its topics, send an email to antlr-discussi...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Eric Vergnaud

unread,
Apr 9, 2015, 7:48:13 PM4/9/15
to antlr-di...@googlegroups.com
Thanks.
Not sure we can fix this rapidly, but we'll certainly look into it. Please file an issue on GitHub.
Eric

Roberto Mencia Franco

unread,
Apr 9, 2015, 8:13:31 PM4/9/15
to antlr-di...@googlegroups.com
I have tested generating Java and using the TestRig and it seems consistent with the result from C#.
The one that is not the same is the tree generated using the Plugin in IntelliJIdea.
I'm not sure how that one runs the parsing, but it seems that the recovery does a better job.

Roberto Mencia Franco

unread,
Apr 9, 2015, 8:21:47 PM4/9/15
to antlr-di...@googlegroups.com

I tried to include the images before but I wasn't successful. 

I'll try again to show the differences between TestRig and IntelliJIdea Plugin:

Also error messages are different:

Java => line 1:0 no viable alternative at input ':'

IntelliJIdea => line 1:0 extraneous input ':' expecting {'(', Term}


Reply all
Reply to author
Forward
0 new messages