[antlr-interest] assigning token LABEL
chintan rao
chintanraoh at gmail.com
Wed Jun 20 06:18:18 PDT 2007
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
I tried out your grammar with few changes in antlrworks
<code starts >
grammar label_test;
LABEL //had to make this LABEL instead of 'label'
: ID[false] ':' ID[true]
;
fragment ID [ boolean isID ] // gave errors without fragment
: ( ('a'..'z'|'A'..'Z')+ ){ if (!isID) {$type=LABEL ;} }
;
test : LABEL;
<code ends>
Now this gives me the following error
{
label_testLexer.java:90: cannot find symbol
symbol : variable _type
location: class label_testLexer
if (!isID) {_type=LABEL ;}
^
1 error
}
I tried to make more changes to the code and make it work but could not
Please help me out
On 6/20/07, Johannes Luber <jaluber at gmx.de> wrote:
> 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