[antlr-interest] Advanced matching in Tree Parsers

Bryan Ewbank ewbank at gmail.com
Thu Apr 14 10:26:43 PDT 2005


Can you rewrite it with cascading predicates, thus?

   #( ROOT f:FIRST
      ( { #f.myfield.equals(something) }? foundit:.
         {
            // foundit!  operate on it...
         }
      | missedit:.
         {
            // ROOT FIRST ..., but not what I wanted
         }
      )?
   )

Or perhaps with a prepass that does something like:
  #(ROOT f:FIRST
     { if (#f.myfield.equals(something)) f->setType(FIRST_MATCH); }
  );
And a postpass, if necessary to revert FIRST_MATCH to FIRST.

On 4/14/05, Martin Probst <mail at martin-probst.com> wrote:
> Hi all,
> I have a problem with tree parsers. I'm trying to match tree fragments in a
> tree parser. The problem is, we use a special AST node type which carries
> lots of payload, and I have to match on that payload in many cases. I'd like
> to use a semantic predicate within a syntactic predicate, but this doesn't
> seem to work:
> 
> E.g.
> expr:
>         ( #( ROOT f:FIRST { #f.myfield.equals(something) }? . ) ) => #( ROOT
> FIRST . )
>         | ...
>         ;
> 
> This does not give an error, but it also doesn't assign anything to #f and
> consequently results in a null pointer exception. Is there a way to achieve
> what I want?
> 
> Regards,
> Martin
> 
>


More information about the antlr-interest mailing list