Hi, for the book i need the pattern matching engine now rather than  
later...  doh!  I'm working in my dev branch.  Won't affect 3.1.2.  I  
have cool examples for book.  E.g., I want to distribute a scalar  
multiply across a vector on way down tree and then repeatedly apply  
simplifications to subtrees on way back up.  With filter=true in tree  
grammar you can do:

vmult  options {strategy=downup; order=between;}
     :   ^('*' INT ^(VEC (e+=.)+)) -> ^(VEC ^('*' INT $e)+)
     ;

mult0  //options {strategy=downup; order=downup}
     :  ^('*' a=. b=INT {$b.int==0}?) -> $b // x*0 -> 0
     ;

Test run:

$ cat t1
x = 4 * [0, 5*0, 3]
$ java Test < t1
Original tree: (= x (* 4 (VEC 0 (* 5 0) 3)))
(* 4 (VEC 0 (* 5 0) 3)) -> (VEC (* 4 0) (* 4 (* 5 0)) (* 4 3))
(* 4 0) -> 0
(* 5 0) -> 0
(* 4 0) -> 0
Simplified tree: (= x (VEC 0 0 (* 4 3)))
$

saaaweeet.  No code gen changes that I can tell; amazing.  Using  
existing options to set superClass etc...  More later.

Kay: guess what you're helping me with when you arrive in December! ;)

Ter
_______________________________________________
antlr-dev mailing list
[email protected]
http://www.antlr.org:8080/mailman/listinfo/antlr-dev

Reply via email to