[antlr-interest] ambiguous grammar

jagad jagad at enciety.com
Mon Oct 6 10:42:17 PDT 2003


Hi All,

I have simple grammar:

rule1  : '(' rule2 (COMMA rule2)* ')'
rule2  : rule1 | expr

expr   : factor (op factor)*
factor : INTEGER | '(' expr ')'
op     : '+' | '-'

the grammar is conflicting because the input like: ((1),(2)) is
undetermine. "(1)" is could be rule1 or expr.
If I force rule1 using:

rule1  : ('(')=>'(' rule2 (COMMA rule2)* ')' | expr

the grammar will valid for "((1),(2))" but fail for: "((1)+1, (2))"
which it should be valid according that "(1)+1" is should be an expr.

Anybody knows how to overcome this problem?

Thanks in Advance and Best Regards

jagad


 

Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/ 




More information about the antlr-interest mailing list