[antlr-interest] [newbie] Precedence of rules

Robert Munteanu robert.munteanu at gmail.com
Tue Jul 8 08:34:20 PDT 2008


Hi,

I am trying to build a larger ANTLR grammar, but I have one single
point of error. It boils down to the following very simple grammar:

grammar Test;

options {
	language = Java;
	output = AST;
}

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 would like the input

hello,world

to be treated as STRING COMMA STRING and to get the output

hello and world

However, all I get is

BR.recoverFromMismatchedToken
line 1:0 mismatched input 'hello,world' expecting STRING

I assume it's something very basic I have overlooked ( only possible
conclusion after staring for about 4 hours at it ).

Can someone please point it out ?

Thank you,

Robert


More information about the antlr-interest mailing list