Hi,

I don't understand what's happening here. I am generating an ANTLR
grammar with XText. Xtext introduces rules like shown below with
'someGeneratedRule1' and 'someGeneratedRule2', which I can't influence.
One of the generated rules ("someGeneratedRule2") isn't actually used,
but seems to provoke an ambiguity. How could that be possible?

When checking this (stripped down) grammar ANTLR yields 'error(202):
grammar_min2.g:14:14: the decision cannot distinguish between
alternative(s) 1,2 for input such as "RULE_INT '.' EOF EOF"' 
Obviously this has something to to with the EOF's Xtext introduces.

When I remove the rule "someGeneratedRule2" the problem disappears.

{{{
grammar grammar_min2;

someGeneratedRule1: rulemodule EOF;

rulemodule:
        'module' RULE_ID ruleCOLON
        ruleunaryexpr 
        ('end' 'module' |rulePERIOD)
;

// PROVOKES THE PROBLEM
someGeneratedRule2: ruleunaryexpr EOF;

ruleunaryexpr:
        RULE_INT
        |ruleDOUBLECONST
;

ruleEXPONENT:
        ('e' |  'E') ('+'|'-')? RULE_INT
;

ruleDOUBLECONST:
        ( RULE_INT '.' (RULE_INT)? (ruleEXPONENT)?)
        |         ('.'  RULE_INT   (ruleEXPONENT)?)
        |              (RULE_INT    ruleEXPONENT)
;

ruleCOLON:':';
rulePERIOD:'.';

// lexer

RULE_ID:('a' .. 'z' | 'A' .. 'Z' | '_' ) ( 'a' .. 'z' | 'A' .. 'Z' | '_'
| '0' .. '9' ) * ;
RULE_INT:('0' .. '9' ) + ; 
RULE_WS:(' ' | '\t' | '\r' | '\n')+;
RULE_ML_COMMENT:'%{' (options {greedy = false; } : . ) * '}%' ;
RULE_SL_COMMENT : '%' ~ ( ( '\n' | '\r' ) ) * ( '\r' ? '\n' ) ? ;
}}}

Additionally ANTLRWorks doesn't visualize the error, just writes it to
the console.

Any ideas?

Thanks,
Martin


List: http://www.antlr.org/mailman/listinfo/antlr-interest
Unsubscribe: 
http://www.antlr.org/mailman/options/antlr-interest/your-email-address

-- 
You received this message because you are subscribed to the Google Groups 
"il-antlr-interest" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/il-antlr-interest?hl=en.

Reply via email to