[antlr-interest] Not generating parts of AST (argh!)

Monty Zukowski monty at codetransform.com
Mon Oct 25 11:06:02 PDT 2004


On Oct 25, 2004, at 10:35 AM, Paul J. Lucas wrote:

>
> On Sun, 24 Oct 2004, Monty Zukowski wrote:
>
>> There are language specific ways to manually ^ a node, but your code
>> actually looks cleaner.
>
> 	IMHO, '^' should be allowed on non-terminals.  Terrence: any
> 	reason it isn't?
>

Because it doesn't make sense to root a whole tree and currently ANTLR 
isn't smart enough to know if the rule is returning a single node or a 
tree.

>> On second thought, how about this:
>>
>> 		comparisonExpr
>> 		    : rangeExpr
>> 		      (co:comparisonOp! rangeExpr { ##=#(co,##); })?
>> 		    ;
>
> 	:-O
>
> 	Where, if anywhere, is "##" documented?
>

mmm, antlr.g?  just shorthand for #ruleName.

>> The following would work for sure:
>>
>> 		comparisonExpr
>> 		    : re1:rangeExpr
>> 		      (co:comparisonOp! re2:rangeExpr! { #comparisonExpr = #(co, 
>> re1,
>> re2); })?
>> 		    ;
>
> 	Yes, it does; thanks.
>
> 	- Paul
>
> 	P.S.: After getting more into it, the tree-construction syntax
> 	is seeming more and more arcane.  One thing I don't understand
> 	is why a rule as a whole ought to have an optional '!' to
> 	suppress insertion into the tree.  The ANTLR compiler scans the
> 	user-code anyway to look for #ruleName -- if it see's one, then
> 	the '!' on the rule is implied.  No?
>

No.  Often I want to add an imaginary root to the tree already built.  
Even the above relies on auto building for re1 though it later uses 
#comparisonExpr.

Monty



 
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