[antlr-interest] Tree Pattern Matching with Rewrite Rules

Matt Fowles matt.fowles at gmail.com
Tue Mar 8 09:36:45 PST 2011


All~

I have a trivial antlr grammar for expressions like `a.b.c + d.e.f`
(Test.g).  Now I want to define a pattern matcher over this grammar
that turns `a.b.c` into `0.1.2`, so I define a Tree Pattern Matcher
(TestWalker.g) and put together a small test program (Main.java).

When I run this program with basic input, I see surprising results:
`a.b.c` -> `0.b.c`
`a.b + d.e` -> `0.b + 0.e`
and so on.

It appears that the `(DOT qualifier_id)*` portion of my rule never
matches and I cannot figure out why.  I have tried adding my rules to
the topdown and the bottomup portions of the Tree Pattern Match.  If I
switch from a filter matcher to a whole tree matcher and add rules to
branch for the `'+'` case appropriately it works, but when the rewrite
is just a smaller fragment of a much larger grammar this becomes
untenable.  Any pointers would be greatly appreciated.

Thanks,
Matt
-------------- next part --------------
A non-text attachment was scrubbed...
Name: pattern-test.tgz
Type: application/x-gzip
Size: 19399 bytes
Desc: not available
Url : http://www.antlr.org/pipermail/antlr-interest/attachments/20110308/1b30dadb/attachment.tgz 


More information about the antlr-interest mailing list