[antlr-interest] ANTLR3 interprets a letter in a string as TOKEN

Hiten R antlr3 at gmail.com
Sun Mar 20 16:40:22 PDT 2011


Hi All,

The problem I am facing is while reading a string if a letter matches a
TOKEN it starts acting funny.

Example
text_content
funny boys are Tom Hardy Donald
serious guys are not funny either

grammar
options {
    language=Java;
    k=1;
}

start
  : 'funny' call_funny_parse
  | 'serious' call_serious_parse
  ;

call_funny_parse
@init {
  ArrayList<String> person = new ArrayList<String>(); //this should contain
Tom Hardy Donald
}
  : jackT=TOKEN    //boys
    macT=TOKEN   //are
    (nextPersonT=TOKEN { person.add($nextPersonT.text); })* // Tom Hardy
Donald
  ;

call_serious_parse
@init {
  String line = "";
}
  : (stringT=TOKEN { line = line + $stringT.text; })* // This is where is
fails and says funny is expecting something else


How do I get around this

Thanks
Hiten


More information about the antlr-interest mailing list