4 ms·
Building an interpreter or a compiler from a grammar is an interesting idea. I can't immediately see how to go about it - the grammar would need to match on SSA
by JonChesterfield 3y ago
Building an interpreter or a compiler from a grammar is an interesting idea. I can't immediately see how to go about it - the grammar would need to match on SSA or similar.
The examples have a lisp-like interpreter at https://github.com/ohmjs/ohm/blob/main/examples/simple-lisp/src/simple-lisp.mjs https://github.com/ohmjs/ohm/blob/main/examples/simple-lisp/... which definitely uses a grammar for parsing and might use a generic AST representation.
Will have to think more - a grammar might be a worthwhile way to specify a nanopass style compiler pipeline.
- pjmlp 3y agoWell that was one of the ways attribute grammars and compiler toolkits were all about a couple of decades ago, like Silver, Coco/R, JavaCC, ANTLR, Amsterdam Compiler toolkit. Usually they never end up in production, as while quite productive to prototype, they aren't that good in error recovery and meaningfull error messages.