=?gb2312?q?=BB=D8=B8=B4=A3=BA=20RE:=20=BB=D8=B8=B4=A3=BA=20RE:=20[antlr-i?=
=?gb2312?q?nterest]=20So=20I=20wish=20one=20token=20has=20two=20types?=
=?gb2312?q?=CB=EF=BC=CD=B8=D5=20Jigang=20(Robert)=20Sun?=
sunjigang1965 at yahoo.com.cn
Wed Jun 7 15:34:19 PDT 2006
Micheal,
Sorry for being so silly, I put {$setType(ID);} outside (...)* :
ID: LowerCaseChar {$setType(CHAR);} ( LowerCaseChar)* {$setType(ID);}
I got it. It is a very good idea.
I love antlr because of the mailing list.
Jigang
--- Micheal J <open.zone at virgin.net>дµÀ:
> Jigang,
>
> > > > I have two kinds of tokens, CHAR and ID, to identify
> > > >
> > > > CHAR: LowerCaseChar;
> > > > ID: (LowerCaseChar)+;
>
> > > Can't be resolved in a lexer (well, it may be possible but
> > it usuallly
> > > gets very messy). Let the parser resolve it.
>
> > If the grammar is
> >
> > CHAR: LowerCaseChar;
> > id: (CHAR)+;
> >
> > What got is a tree other than a token/string. So I have to
> > use actions to get the string. Do you mean token/string
> > creation should be done in parser?
>
> In your original post, ID is a lexer rule. It should still be.
>
> In your parser:
> - wherever a single-char literal is expected, use CHAR.
> - wherever an indentifier is expected use (CHAR | ID) [since identifier
> can also be single-char]
> - wherever only a multi-char character sequence/string is expected use ID
>
>
> Micheal
>
> -----------------------
> The best way to contact me is via the list/forum. My time is very limited.
>
>
__________________________________________________
¸Ï¿ì×¢²áÑÅ»¢³¬´óÈÝÁ¿Ãâ·ÑÓÊÏä?
http://cn.mail.yahoo.com
More information about the antlr-interest
mailing list