[antlr-interest] TokenStream in ANTLR V3

chain one chainone at gmail.com
Wed Dec 3 05:41:43 PST 2008


I found in ANTLR V3, before Parser rules began to be appiled, all the tokens
have been recognized(That is also to say that all the Lexer Rules have been
applied.).

Such as this rule:


IDENT

: ('a'..'z'|'A'..'Z'|'_') ('a'..'z'|'A'..'Z'|'_'|'0'..'9')*
{
     $type=globalSearchId($text);
}
;

globalSearchId() will be called N times before any parser rule is about to
be appiled


Is it right?
Is there any way to let the Lexer rule of the token to be applied just
before this token is met by the Parser?

If it works in this way, in the above example, globalSearchId will be called
once the IDENT is met in the Parser Rule like:

type_id :  id=IDENT { addId($id.getText(),TYPE_IDENT); $s=$id.getText(); }


As far as I know, ANTLR V2 works in this way.
Is there any way to do that in ANTLR V3?


Thanks very much.

Best Regards,
chainone
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20081203/93f6a73c/attachment.html 


More information about the antlr-interest mailing list