[antlr-interest] Comments / White-Space and All The Rest

Terence Parr parrt at cs.usfca.edu
Fri Nov 24 11:40:00 PST 2006


On Nov 24, 2006, at 11:30 AM, Randall R Schulz wrote:
> How do I get at the tokens? How do I navigate the token stream? I  
> notice
> that TokenStream.LB(int) is protected, so I cannot even call it from
> parse action code.

Didn't this method leap out at you?

	/** Return absolute token i; ignore which channel the tokens are on;
	 *  that is, count all tokens not just on-channel tokens.
	 */
	public Token get(int i) {
		return (Token)tokens.get(i);
	}

Looking at the generated code and looking at the source code for the  
run time is very important.

> I also notice that rules that return a single value (which is all but
> two of the rules in my grammar) don't trigger the generation of return
> types that descend from ParserRuleReturnScope. In those cases, how  
> do I
> get at the start and stop tokens?

Ask and ye shall receive. ANTLR senses it and turns on multiple  
return values to return start and stop for you.  Just try it and see  
what happens. that is the name of the game.

Ter



More information about the antlr-interest mailing list