Loading ...
Sorry, an error occurred while loading the content.

Re: [antlr-interest] Partial tree transformation

Expand Messages
  • Terence Parr
    ... That is a different philosophy than the tree grammar approach. However, in old Sorcerer I had support routines that worked like fscanf called tscant or
    Message 1 of 2 , Sep 8, 2002
    • 0 Attachment
      On Sunday, September 8, 2002, at 05:16 AM, renyedi wrote:

      > Greetings
      >
      > Suppose we have an AST generated by ANTLR. Is there a way to perform a
      > transformation for only certain tree patterns without defining rules
      > that lead to that pattern?

      That is a different philosophy than the tree grammar approach.
      However, in old Sorcerer I had support routines that worked like fscanf
      called tscant or something that let you ask for all references to trees
      of a certain form. There is something similar in ANTLR, but can't
      remember the name right off the top of my head.

      > For example, let's say that having a Java AST generated by the java.g
      > grammar (the one from the ANTLR example grammars) one wants to filter
      > out the final modifier. Based on java.tree.g, only the "modifier" rule
      > should be defined. The nodes that do not match the "modifier" pattern
      > should be copied by default to the resulting AST. However, if I do
      > this way, the "modifier" rule is never matched but I get an unexpected
      > node error.
      >
      > Is there a way to do this?

      Ah. Yes, try this class

      antlr.ASTIterator

      it has a next() method that keeps looking for subtrees I think. You
      are really just asking for a depth first search. Easy to add if we
      don't have precisely what you need. :)

      Terence
      --
      Co-founder, http://www.jguru.com
      Creator, ANTLR Parser Generator: http://www.antlr.org
    Your message has been successfully submitted and would be delivered to recipients shortly.