[antlr-interest] TreeParsing with various roots

Paul J. Lucas pauljlucas at mac.com
Wed Nov 3 14:31:30 PST 2004


	Suppose I have in a parser:

		compExpr
		    : re1rangeExpr
		      (co:compOp! re:rangeExpr!
		      	{
			    ## = #(co, re1, re2)
			}
		      )?
		    ;

		compOp
		    : EQ | NE | LT | LE | GT | GE
		    ;

	How to I write the corresponding Treeparser?

		compExpr
		    : #( xxx re1=rangeExpr re2=RangeExpr )
		    ;

	What goes in the place of the "xxx"?  Ideally, I'd like to
	share the code for all compOps.

	I *could* do:

		compOp
		    : (EQ | NE | LT | LE | GT | GE)
		    	{
			    ##.setType( COMP_OP );
			}
		    ;

	then:

		compExpr
		    : #( co:COMP_OP re1=rangeExpr re2=RangeExpr )
		    	{
			    // do something with co.getText()
			}
		    ;

	But having to use the text of the original token seems a bit
	hokey to me.  Is there a better way?

	- 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