Peter Goodman schrieb: > 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). > 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.
Hi, I'm doing similar things with pyPEG. I think, a "don't include that non-terminal symbol" sign should be enough, there is no real need for a "raise children" sign (just describe your grammar the right way). I have defined, that non-terminal symbols which start with an underscore don't appear in the AST. My second patch to PEG is there because of runtime problems with Python (pyPEG is a pure Python implementation): I added "common" RegEx to PEG. Sounds strange, but if the language is regular, it's faster to use the Perl RegEx implementation Python includes in the language - and it's even more comfortable (PEG extension, anyone? ;-) I will add PEG ASCII language now. I think, most cases where a plain RegEx implementation should be used can be detected without problems, so the only thing to add is the semantics that leading underscores in non-terminal symbols modify the AST. Maybe this can be an option for you, too. Before people are telling me to implement PEG hard coded so I will not need a reference to RegEx any more: I really need the modifiability of the grammar while runtime and I'm prototyping in Python. BTW: does anybody know a PEG implementation for C where the grammar can be modified while runtime? Yours, VB. -- X-Pie Software GmbH Nobelstrasse 32, 88131 Lindau (Bodensee) mailto:v...@x-pie.de http://www.x-pie.de
signature.asc
Description: OpenPGP digital signature
_______________________________________________ PEG mailing list PEG@lists.csail.mit.edu https://lists.csail.mit.edu/mailman/listinfo/peg