On Dec 1, 2008, at 9:57 AM, Sam Harwell wrote:

> Here's a fictional example of why you might want to distinguish "any
> node or tree" from "any node" in a tree parser.
>
> Input: (3)+(2)
> Resulting Tree: ^(+ ^(expr 3) ^(expr 2))
> Goal: pattern rewrite in a filter tree parser to remove some nodes
> resulting from unnecessary parentheses.
>
> Pattern:
>
> remove_parens_atomicblock
>  : ^(binary_op ^(expr left=.) ^(expr right=.))
>    -> ^(binary_op $left $right)
>  ;
>
> Result: ^(+ 3 2)
>
> This works as long as '.' means "any node", but may fail due to  
> order of
> operations if the parenthesized expression is not a primary  
> expression.

Yes, you must predicate the -> to ensure operator prec isn't an issue.

But you don't have a '.' in root position here.

>
>
> On a sidenote, the reason I said ^(.) is not currently allowed in a  
> tree
> parser earlier is this:
>
> ANTLR.g3 line 534:
>
> tree_
>       :       TREE_BEGIN^
>               treeRoot ( element )+
>               RPAREN!
>       ;
>
> One possible resolution add a 'WILDCARD_TREE' rule in ANTLR.g3 as
> follows, and add it as an alt to 'terminal'. This clears up both the
> wildcard-as-root issue and the "any node"/"any node or tree"  
> ambiguity.
> It would be allowed anywhere in a tree parser except as a tree root.
>
> WILDCARD_TREE : '^.';

Yeah, i'll be looking into it.

Ter

List: http://www.antlr.org:8080/mailman/listinfo/antlr-interest
Unsubscribe: 
http://www.antlr.org:8080/mailman/options/antlr-interest/your-email-address


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"il-antlr-interest" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/il-antlr-interest?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to