[antlr-interest] [newbie] Precedence of rules
Felix Dorner
felix_do at web.de
Wed Jul 9 04:01:08 PDT 2008
Hi Robert.
>
> startup:
> first=STRING COMMA second=STRING
> {
> System.out.println($first.text + " and " + $second.text);
> }
> ;
>
> COMMA : ',';
> STRING : ('a'..'z'|'A'..'Z')+;
>
> STRING_WITH_COMMA : STRING (COMMA STRING)+ ;
>
>
I am pretty sure this rule bites with the "startup" rule. I am also
pretty sure that you would not want this to be a Lexer but a Parser rule
(i.e. should start with a lower Case.) Then you would have:
startup: STRING COMMA STRING {...};
string_with_comma: STRING (COMMA STRING)+;
Now it depends how those rules are invoked. If they have a common
"superrule", then the grammar would be ambiguous.
Felix
More information about the antlr-interest
mailing list