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

Randall R Schulz rschulz at sonic.net
Fri Nov 24 11:44:19 PST 2006


Terence,

On Friday 24 November 2006 11:40, Terence Parr wrote:
> 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);
> 	}

What "i" values do I use? The comment doesn't specify how that parameter 
is interpreted.


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

May I respectfully disagree? I should not have to understand a tool's 
internals to use it, should I?


> > 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.

Trial and error makes for very slow going, which is how it's been for 
me.

Are you sure you won't share some documentation?


> Ter


Randall Schulz


More information about the antlr-interest mailing list