Example tree rewriting with patterns

Skip to end of sidebar
Go to start of sidebar
Skip to end of metadata
Go to start of metadata

So, let's do some rewriting using the pattern matching filter=true mode. Again, the VecMath.g parser will build trees but we'll avoid building an entire tree grammar. We'll focus on some patterns we want to rewrite.

Here's the grammar to build trees.

And now, let's distribute scalar-vector multiplies. 4*[1,2] -> [4*1,4*2].

Give it a shot:

Output:

Now for stuff that needs to repeatedly get applied to subtrees.

Test code:

Running:

I'm replacing multiply with shift left by 1 and then combining shifts.

Labels: