[antlr-interest] More on TokenWithIndex

Paul J. Lucas pauljlucas at mac.com
Wed Oct 27 10:18:25 PDT 2004


On Wed, 27 Oct 2004, Monty Zukowski wrote:

> Well, doing it in actions is the ANTLR way.  You do have to tell ANTLR 
> which regions are interesting and which aren't.  If ANTLR were to 
> support that it would mean annotating your parser with yet another 
> symbol, which is actually ok with me but not with Terence.

	It could be done via "options"... something like:

		declareThing
		  options {
		    pushLeftTokens = true;
		  }
		  : DECLARE! ( thing1 | thing2 | yadda )
		  ;

	(or something like that).  This would have the effect of either
	"pushing" the left tokens "down" to the rules to the right so
	that when their ASTs are constructed, their left "edge"
	includes the left tokens of the caller.

	For the enclosedExpr case, perhaps something like:

		enclosedExpr
		  options {
		    includeEdgeTokens = true;
		  }
		  : '(' expr ')'
		  ;

	so that '(' and ')' are included in the min/max indicies.

	I do tend to agree that adding yet more "magic" symbols to
	tokens gets a bit crazy.  Perhaps more mnemonic symbols:

		DECLARE<K,P>	// (K)ill = current '!'; (P)ush down

	but only if the options addition wouldn't work.

	- Paul



 
Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/antlr-interest/

<*> To unsubscribe from this group, send an email to:
    antlr-interest-unsubscribe at yahoogroups.com

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





More information about the antlr-interest mailing list