antlr 3 bug?

86 views
Skip to first unread message

Oleg Bolshakov

unread,
Jan 15, 2014, 9:17:48 AM1/15/14
to antlr-di...@googlegroups.com
Hello. I'm using a famous instrument for generating text editor for Eclipse (Xtext). Xtext generates an antlr grammar to create parser. When working with this instrument I got some errors and started to test antlr and I found some strange thing. For the next grammar (which is a simplified version of generated one):
grammar InternalMyDsl2;

model
: translation_unit;

translation_unit
: (declaration ';')*;

entryRulenest_rule
:    
    nest_rule
    EOF
;

nest_rule
: ID?;

entryRuledeclaration
:
    declaration      
    EOF
;

declaration
: 'decl' nest_rule ID EOF?;

fragment LETTER
: ('$'|'A'..'Z'|'a'..'z'|'_');
ID
: LETTER (LETTER|'0'..'9')*;
WS
: (' '|'\t'|'\r'|'\n')+;
ANY_OTHER
: .;

I get the next error from antlr3.5:
>java -jar antlr-3.5-complete.jar InternalMyDsl2.g
error(202): InternalMyDsl2.g:12:12: the decision cannot distinguish between alternative(s) 1,2 for input such as "ID EOF EOF"

Why? Can anybody explain me - where are these alternatives?

Terence Parr

unread,
Jan 15, 2014, 1:51:09 PM1/15/14
to antlr-di...@googlegroups.com
nest_rule can match ID EOF by taking ID in nest_rule OR by matching nothing and matching in declaration. This is SLL vs LL.
Ter
--
You received this message because you are subscribed to the Google Groups "antlr-discussion" group.
To unsubscribe from this group and stop receiving emails from it, send an email to antlr-discussi...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Oleg Bolshakov

unread,
Jan 15, 2014, 4:49:19 PM1/15/14
to antlr-di...@googlegroups.com
I'm very sorry. That was my mistake when posting the message.

The rule declaration was:
declaration: 'decl' nest_rule ID;



--
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/6zZvuhVikx0/unsubscribe.
To unsubscribe from this group and all its topics, send an email to antlr-discussi...@googlegroups.com.

Oleg Bolshakov

unread,
Jan 15, 2014, 6:39:56 PM1/15/14
to antlr-di...@googlegroups.com
So the problem is that I get this message for the edited version of grammar. The two EOFs are just in entryrules and entryrules do not call (or contain) each other. I can't suppose how ID EOF EOF may be parsed
Reply all
Reply to author
Forward
0 new messages