Peter Goodman wrote: > 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).
I did something quite similar, but with the set of non-excludable rules stored separately from the grammar as a list of rule names. I found this convenient when using the same grammar for different purposes. It's also helpful in debugging a grammar to exclude nothing to see everything that is being tried without needing to alter the grammar. For creating a human-readable parse tree, on the other hand, I usually want it to drop everything it possibly can. I have a rule for parse tree simplification that seems to be equivalent to yours. I called this "elision", and the rules on which it is allowed I call "elidable". Actually there may be one difference. My simplification rule is that a match is replaced by its child only when they match the same run of input symbols (i.e. started and ended at the same positions in the input stream). This is significant when terminals are dropped from the tree, which I do also. So if you have: IntegerLiteral ← PosInt / NegInt PosInt ← Digits NegInt ← "-" Digits Assuming that the "-" is never added to the tree (as it contains no information that is not already conveyed by NegInt having succeeded) then NegInt will have only one child. However, it still won't be a candidate for elision, since NegInt will have matched one character more than its Digits child. An IntegerLiteral, on the other hand, would never appear in the reduced parse tree (assuming it is in the set of elidable rules as specified by the user). This looks similar to what you are doing with using non-terminals in the tree as flag values. -- http://inimino.org/~inimino/blog _______________________________________________ PEG mailing list PEG@lists.csail.mit.edu https://lists.csail.mit.edu/mailman/listinfo/peg