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

Re: [antlr-interest] AST matching and N-ary tree nodes.

Expand Messages
  • Monty Zukowski
    ... The tree rule would be identical to what you had before, substituting ARGLIST for COMMA. Your tree used to be #(COMMA arg1 arg2 ...) now it is #(ARGLIST
    Message 1 of 2 , Oct 7, 2004
    • 0 Attachment
      On Oct 7, 2004, at 7:21 AM, Bryan Ewbank wrote:

      >
      > Hi Folks,
      >
      > I've been building flattened trees for things like argument lists, but
      > am
      > now encountering a question of how to process these nodes in a general
      > way,
      > since AST matching is generous...
      >
      > // Used to use this
      > arglist : arg ( COMMA^ arg )*
      >
      > // Now use this
      > arglist : arg ( COMMA! arg )*
      > { #arglist = #( #[ARGLIST], #arglist)
      >
      > The problem is that I don't know how many kids the ARGLIST node can
      > have,
      > and I don't see a way (v 2.7.4) to easily walk the children.
      >

      The tree rule would be identical to what you had before, substituting
      ARGLIST for COMMA. Your tree used to be #(COMMA arg1 arg2 ...) now it
      is #(ARGLIST arg1 arg2 ...).

      arglist: #(ARGLIST (arg)*);

      You won't know how many are in there until you walk them all. If you
      wanted you could keep count in the parser and store that in the ARGLIST
      node if you make a custom tree node class to hold that info.

      > Am I building this tree in a non-ANTLR style? Do I need to go back to
      > using
      > the "COMMA^" model?
      >
      > - Bryan Ewbank
      > "The best tool for requirements analysis and design is a crayon"
      >
      >
      >
      >
      > Yahoo! Groups Links
      >
      >
      >
      >
      >
      >
      >
      >
      >
    Your message has been successfully submitted and would be delivered to recipients shortly.