9/10 times when I see a "compiler" on GitHub, it's just an interpreter, or the compilation phase is completely missing.<p>In this case I believe the "compiler" is an "ast printer".
If anyone is curious, I threw together a similar (although not commented yet) example of how I would write this using parser combinators in Haskell: <a href="https://gist.github.com/neilparikh/b8a9c758ebbbb5a3ee9b2ed999740b0d" rel="nofollow">https://gist.github.com/neilparikh/b8a9c758ebbbb5a3ee9b2ed99...</a><p>The JS example wrote everything from scratch, so to do the same, I wrote my own parser combinator library (based on <a href="https://www.cs.nott.ac.uk/~pszgmh/monparsing.pdf" rel="nofollow">https://www.cs.nott.ac.uk/~pszgmh/monparsing.pdf</a>), but you could use an existing library, and get rid of `Parser.hs`.
There was a person who began rewriting this using reason [1]. Sadly, he never got to complete it.<p>I began tinkering with F# recently and found that ML languages are perfect for parsing. Is there a version of this in F# or ocaml?<p>[1] <a href="https://medium.com/@javierwchavarri/building-the-super-tiny-compiler-with-reason-part-1-21460cd4ae7b" rel="nofollow">https://medium.com/@javierwchavarri/building-the-super-tiny-...</a>
Maybe interesting for a comparison: 21 years ago I wrote my own tiny demo compiler in JS, much inspired by Niklaus Wirth.<p><a href="https://www.masswerk.at/demospace/eal/eal.htm" rel="nofollow">https://www.masswerk.at/demospace/eal/eal.htm</a><p>See the page source for the code. (Probably fun, old syntax both for HTML and JS, pre-ECMA JavaScript [meaning, the semicolon isn't a delimiter, but a separator], even the indentation style is outdated. Mind that back then, even the support of JS object literals wasn't guaranteed.)<p>Syntax, etc: <a href="https://www.masswerk.at/demospace/eal/syntax.htm" rel="nofollow">https://www.masswerk.at/demospace/eal/syntax.htm</a><p>Byte code reference: <a href="https://www.masswerk.at/demospace/eal/pcode.htm" rel="nofollow">https://www.masswerk.at/demospace/eal/pcode.htm</a>
Reminds me of this old screencast about writing a compiler in ruby:<p><a href="https://www.destroyallsoftware.com/screencasts/catalog/a-compiler-from-scratch" rel="nofollow">https://www.destroyallsoftware.com/screencasts/catalog/a-com...</a>
I want to dispute the 'modern' claim.<p>I don't know my dates well enough. But is there anything in here that isn't at least 50 years old?<p>The high-level is tokenize->parse->ast_transform->codegen.<p>The low-level looks like `char = input[++current];`