[antlr-interest] assigning token LABEL

Johannes Luber jaluber at gmx.de
Wed Jun 20 02:20:37 PDT 2007


chintan rao wrote:
> Hi,
> I am new to antlr3 / compilers / parsers .
> I have problem assigning token LABEL .
> if there is ':' after ID it must be labeled as LABEL .
> if there is no colon then it must be named as ID that is  IDENTIFIER .
> 
> This may be a simple problem but i am stuck with this .
> please help me out.

As you haven't sent your grammar with your question I have to improvise
the snippets. Create first an imaginary LABEL token and have rules like
this:

label
   :   ID[false] ':' ID[true]
   ;

ID[boolean isID]
   :   ('a'..'z'|'A'..'Z')+ { if (!isID) $type = LABEL ; }
   ;

Hope this helps!
Johannes Luber



More information about the antlr-interest mailing list