[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: AST transformations



About the form rewriting rules should take.
There are two kinds I am considering for inclusion in a parser generator
I have written (and haven't had tome to work on):

(1) macros:

	macro <nt> : <right-side> --> <replacement>

The replacement consists nonterminals that occur in
the right side, and terminals.
The production <nt> : <right-side> is parses as usual, but when it is
reduced, instead of replacing the right side by the nonterminal,
you push the replacement back into the input stream, pop the right side
from the stack, and reparse.  There's two variations on this, depending
on whether you unparse the nonterminals or not.

(2) tree replacements

	replace <nt> : <right-side> --> <replacement>

Similar to the above, but a check in performed at parser generation
time that the replacement is indeed parsable as the <nt>.
Thus when recognising the production, you can immediately proceed to
parse-tree rewriting.

-- hendrik@topoi.cam.org