[antlr-interest] Re: Reading contents of file using Antlr

micheal_jor <open.zone at virgin.net> open.zone at virgin.net
Thu Jan 23 19:48:38 PST 2003


--- In antlr-interest at yahoogroups.com, Sharon Li <hushlee83 at y...> 
wrote:
> 
> Sorry another question,
> Do I specify the tokens in the tokens {...} section anywhere in my 
code? What does specifiying the tokens do ? 

The placement of the tokens {...} section is as I have illustrated 
with ###[1] in your grammar (i.e. just after the "class" decaration 
and it's options {...} section.

Specifying the tokens identifies the respective sequence of 
characters as a Token (each Token has it's own integer Token-ID). You 
can then refer to the tokens directly in the parser e.g.: 

entry 
: ANGLE FACTOR 
| BACK DISTANCE
......
......
| RENDER MODE
| VIEW POINT
| Z BUFFER
;

record : ((r:entry) (sc: SEMICOLON)? (n:RECORD)* (COMMENT)?)

Ordinarily, all such strings would be lumped together as 
ID/IDENT/IDENTIFIER or whatever Token-ID is defined for identifiers. 
As I mentioned before, tokens{...} entries are assumed not to be 
identifers. If that isn't the case with your grammar, see the link in 
my original message for one solution.

Micheal




 

Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/ 



More information about the antlr-interest mailing list