[antlr-interest] newbie faces unexpected tokens

Mo m.axmed at gmail.com
Tue Jul 11 10:45:07 PDT 2006


Hi all,
 i'm an antlr newbie and realise it has probably been posted before,
but i cant find much

i'm trying to read strings in the form of:   foo.bar.foo and parse
them into a tree structure for later  and have the following simple
grammar definitions

in the   lexer

DOT : '.' ;
IDENT
      options {testLiterals=true;}
      : ('a'..'z'|'A'..'Z') ('a'..'z'|'A'..'Z'|'0'..'9')*
      ;


and in the parser an simple test case

event
      : "on"^ IDENT  LBRACE!
          symbol SEMI!
           RBRACE!
    ;

symbol
        :  IDENT   (DOT^ IDENT )*
        ;


however any attempt at reading:  foo.bar.foo;
returns the following error

 unexpected char: 'b'

using

 symbol
         :  IDENT   ("."^ IDENT )*
         ;

returns

expecting SEMI, found 'barfoo'


coincidentally if i replace the DOT in  the symbol definition with
something else i.e. COMMA it works ...

could anybody be kind enough to point out were i'm being stupid here !

your time and help is much appreciated --
cheers
 mo


More information about the antlr-interest mailing list