[antlr-interest] Advanced matching in Tree Parsers

Martin Probst mail at martin-probst.com
Fri Apr 15 14:55:36 PDT 2005


Hi,

> Another option is to use syntactic predicates and recursion...

That's actually what I meant to say with point two (actually the first
one of the two points I labeled two ... err, you'll know what I
mean ;-)).

> 
>    // this is the entry point
>    root:
>       ( (pattern) => takeaction
>       |
>          // first instance of root is "down"; second is "to the right"
>          #(. (root)? ) (root)?
>       );
>    pattern:
>       #(A B)
>    ;

I didn't know you could reference whole rules in syntactic predicates -
this beautifies that approach a lot.

It will still have to check for some conditions manually. It would be
really nice if it was possible to hand-code checks into syntactic
predicates, with accessing the so far matched tree parts, e.g. something
like:

pattern:
    #( A b:B { vartable.lookup(#b.var) == current }? )

So by writing
   ( pattern ) => ...
it would also be made sure that the expression meets these conditions.

I think that would be a sane feature, it's exactly what semantic
predicates are meant for, isn't it?

Regards,
Martin



More information about the antlr-interest mailing list