[antlr-interest] Parsing an IP Address

Ross Bencina rbencina at iprimus.com.au
Mon Mar 31 18:42:30 PST 2003


> ip
>    :    i: seg DOT seg DOT seg DOT seg
>         {Console.Out.WriteLine(i.getText());}
>    ;
>
> I am getting a number of errors: one says that the type or
> namespace 'i' cannot be found, and another says that the type or
> namespace "lexer" cannot be found.

The colon syntax cannot be used for non-terminals.

I'm not exactly sure what you're trying to do, but you might need something
like:

seg  returns [ RefToken result ]
   :    s:IPSEG
        { result=s; }
   ;

ip
{
    RefToken i;
}
   :    i=seg DOT seg DOT seg DOT seg
        {Console.Out.WriteLine(i->getText());}
   ;

I think RefToken is not the correct type, but you should be able to work it
out by examining the generated source.

Ross.


 

Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/ 



More information about the antlr-interest mailing list