Don’t know of a document but it would be useful. Espeically on design considerations.
Some possible evaluation strategies I’ve used:
- Obviously Parse, but it doesn’t offer much more than recognising tokens. It’s awkward to manage the evaluation.
- In rowsets.r I wanted a SQL like dialect for series. I selectively bind the SQLish keywords in a block then just DO the block. The keywords when used together with their arguments form a chained expression.
- In math.reb I used a Top Down Operator Precedence Parser (Pratt Parser). This is the go to example for Pratt parsing. Pratt parsing can be arbitrarily more complex. I think there is a good fit for Pratt parsing in Rebol dialects. However, all the work @hostilefork has put into evaluation in the DO dialect (enfix, etc), takes quite a bit of territory that Pratt parsing covers, so it makes sense to seek to leverage Ren-c’s Do where possible before resorting to Pratt.
- I have used expression rewriting in a number of places including rewriting parse rules. It’s a good trick to keep up one’s sleeve. Rewrite was written by Gabriele for pattern rewriting blocks, I’ve modified it heavily. Only problem with it is if you’ve rewritten the expression and have an error then reporting back to the user where the error occurred could be a problem (you rewrote it!).
I’ve spent quite a bit of time trying to get varied articles on Pratt parsing so I’m just going to dump them here for posterity:
Top Down Operator Precedence (Vaughan R. Pratt)
- https://tdop.github.io/ (remastered version)
- The repo for this site contains a link to the original version.
Top-Down operator precedence parsing (Eli Bendersky)
Pratt Parsers: Expression Parsing Made Easy (Bob Nystrom)
Top Down Operator Precedence (Douglas Crockford)
- Note the commentary on statements in the above and at https://pythonhosted.org/PrattParse/tutorial.html#adding-statements
A Monadic Pratt Parser (Matthew Manela) - see discussion of someFunction.
- (for background on function call syntax in haskell see https://www.fpcomplete.com/school/starting-with-haskell/basics-of-haskell/function-application)
A number of good articles by the one author on Pratt (Andy Chu)
- See the blog for the other articles, in particular comments on other articles I’ve referenced here.
Top Down Operator Precedence Parsing in Go (Cristian Dima)
- Implementing a small dynamic language
CGOL - An algebraic notation for MACLISP users (Vaughan R. Pratt)
- Contains additional explanations related to the algorithm.