Peter Goodman wrote: > I wanted to mention one of the way in which I have been building an AST from > my parse tree while the tree itself is being constructed (a more appropriate > term might be: reduced parse tree). I use one rule within the parser and also > two operators within the grammar. One of these operators is already well- > understood and has been mentioned on this list several times. > > My two operators are: > > i) A non-excludable operator (-), which requires that a non/terminal appear > in the reduced parse tree. If no such operator is used, then terminals are > *not* added to the tree as leafs, and non-terminals, where only one child > exists, are replaced with their child (my automatic reduction rule).
ANTLR (v3) has a '!' operator which excludes a child from appearing in the reduced tree (i.e. the opposite of your '-'). It has a similar rule to yours for automatically reducing nodes with only one child. I think that I prefer the approach of including children by default; it means that the default at least includes all of the necessary information. > ii) A raise children operator (^), which puts the derivations of a particular > non-terminal in a production in place of the non-terminal. This allows me to > collect lists of nodes. This is also similar to ANTLR. -- David-Sarah Hopwood ⚥ http://davidsarah.livejournal.com _______________________________________________ PEG mailing list PEG@lists.csail.mit.edu https://lists.csail.mit.edu/mailman/listinfo/peg