Probably asked before but, what is your go-to tool...
# thinking-together
r
Probably asked before but, what is your go-to tool for the implementation of a language prototype in terms of parsing, compiling, etc? Language, library, generator...?
👍 1
c
For me, prototype = typescript. Parsimmon is a great parsing library to start with. Or if you feel fancy you can check out ohm which is a compiler-compiler.
👌 1
Meta 2 is a really cool paper about compiler-compilers btw. Here’s a nice overview:

https://youtu.be/L1rwVBLHGiUâ–ľ

👍 1
âž• 1
e
I think I'll try instaparse for my next experiment https://github.com/Engelberg/instaparse and https://github.com/noprompt/meander to manipulate the parse tree
If you are not sure about clojure for language implementation this talk might be interesting for you:

https://www.youtube.com/watch?v=t8usj1fN9rsâ–ľ

(since strictly typed languages are often considered "the best" for compiler work)
c
I’ve found this library useful in the past, especially for quick parsing tasks. https://github.com/orangeduck/mpc Last time I did a language, I rolled my own tokenizer and lexer. I find things easier to understand that way. I know that Jonathan Blow’s Jai language uses the same hand rolled approach.
It has the nice feature of being able to just pass a grammar to the library, and it builds the parser combinators. Very quick and easy.
j
I find the question a bit underspecified, as which tools one might choose will hinge on both the specifics of what one is building and a variety of personal preferences. In my case, I like languages/environments that allow me to develop new semantics from within them, only worrying about adding syntactic affordances later. If one prefers that approach, it's hard to beat https://racket-lang.org
✔️ 1
âž• 2
m
I use the compiler tools from erlang, leex, yecc, absform and the compiler module
i
I just use kotlin and wrote my own parser, the language feels so nice and expressive that I just keep coming back to it for everything. Basically just find special tokens, create a index of [position, token], then recursively parse it breadth first. tho it isn’t a complete “language”, but a DSL language so it’s easier than full on lang :)
and weird, nobody mentioned ANTLR yet
d
I hand rolled the lexer and parser for Curv in C++, because I didn't want to fight tool limitations in defining the syntax or implementing error recovery. In retrospect, • A regex-based scanner generator like re2c would have made the scanner easier to write. • My hand-written recursive descent parser was easy to write and continues to be easy to modify. No regrets. • After hanging out in FoC for a year, I have IDE envy. To properly implement completions and hints, I need an incremental parser. So maybe I should switch to the tree-sitter parser generator? https://github.com/tree-sitter/tree-sitter • For me, the hard part is the back end, not the parser/lexical analyser. What are the libraries/DSLs for semantic analysis, optimization and code generation?
👍 1