[antlr-interest] assigning token LABEL
chintan rao
chintanraoh at gmail.com
Wed Jun 20 07:39:24 PDT 2007
Hi thanks for the solution again
>LABEL
> : ('a'..'z'|'A'..'Z')+ ':'
> ;
The problem with the solution is that colon gets assigned with label too
for example
input:
lb:
output:
now LABEL token will be 'lb:'
I want to it to be 'lb'
and may be assign a diffrent token for ':'
On 6/21/07, Johannes Luber <jaluber at gmx.de> wrote:
> chintan rao wrote:
> > Hi,
> > firstly thanks for your time
> >
> >> 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:
> >
> > What wanted was some thing like this
> > input :
> > la :
> > ouput given by lexer :
> > la gets assigned token LABEL
> >
> > input:
> > la
> > ouput given by lexer :
> > la gets assigned token ID
>
> Looking at your sample input I discovered that I misread your
> specification. I thought that after the label had to come an ID. My
> mistake. The following grammar works with ANTLRworks and parses my test
> input correctly. Just don't forget a whitespace rule in your actual grammar.
>
> LABEL
> : ('a'..'z'|'A'..'Z')+ ':'
> ;
>
> ID
> : ('a'..'z'|'A'..'Z')+
> ;
>
> test
> : (LABEL|ID)*
> ;
>
> Best regards,
> Johannes Luber
>
More information about the antlr-interest
mailing list