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

Walking an AST with a TreeParser

Expand Messages
  • Remi
    I am looking for a way to traverse completely an AST with a TreeParser. How can you visit all the leafs with a simple rule ? sibling : #( . sibling) | .
    Message 1 of 2 , Jul 31, 2002
    • 0 Attachment
      I am looking for a way to traverse completely an AST with a TreeParser.
      How can you visit all the leafs with a simple rule ?

      sibling : #( . sibling) | . sibling ;

      doesn't work, it ends with a "<AST>: unexpected end of subtree"

      My intent is to look only for special nodes without
      either handcode in java or import a whole grammar.

      Rémi
    • mzukowski@yci.com
      A grammar is the wrong way to do what you want. You would need a syntactic predicate in the rule below, and also have to handle the case where the node has
      Message 2 of 2 , Jul 31, 2002
      • 0 Attachment
        A grammar is the wrong way to do what you want. You would need a syntactic
        predicate in the rule below, and also have to handle the case where the node
        has both a child and a sibling.

        Instead try using the findAll() or findAllPartial() methods defined in
        AST.java and implemented in BaseAST.java.

        Monty

        > -----Original Message-----
        > From: Remi [mailto:remi.koutcherawy@...]
        > Sent: Wednesday, July 31, 2002 6:18 AM
        > To: antlr-interest@yahoogroups.com
        > Subject: [antlr-interest] Walking an AST with a TreeParser
        >
        >
        > I am looking for a way to traverse completely an AST with a
        > TreeParser.
        > How can you visit all the leafs with a simple rule ?
        >
        > sibling : #( . sibling) | . sibling ;
        >
        > doesn't work, it ends with a "<AST>: unexpected end of subtree"
        >
        > My intent is to look only for special nodes without
        > either handcode in java or import a whole grammar.
        >
        > Rémi
        >
        >
        >
        >
        >
        > Your use of Yahoo! Groups is subject to
        > http://docs.yahoo.com/info/terms/
        >
        >
      Your message has been successfully submitted and would be delivered to recipients shortly.