RE: »Ø¸´£º RE: [antlr-interest] So I wish one token has two types

Micheal J open.zone at virgin.net
Wed Jun 7 15:13:48 PDT 2006


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.



More information about the antlr-interest mailing list