[HN Gopher] Let's write a compiler, part 1: Introduction, select... ___________________________________________________________________ Let's write a compiler, part 1: Introduction, selecting a language, and planning Author : ingve Score : 65 points Date : 2021-08-14 18:53 UTC (4 hours ago) (HTM) web link (briancallahan.net) (TXT) w3m dump (briancallahan.net) | waynesonfire wrote: | part 1 isn't parser / lexer???? nice job. "On the next episode: A | lexer" oh, it is. | turminal wrote: | Well, it's the first thing in the pipeline, so why not? | lisper wrote: | > Outputting to C is a well-recognized compilation strategy. | | That's true, but it's not a good choice for _teaching_ how to | write a compiler because the C compiler does too much of the | heavy lifting for you while at the same time imposing unnecessary | constraints. Compiling to C allows you to entirely side-step the | question of how to compile arithmetic and function calls, which | is like 90% of the battle. Also, if you want your source language | to, for example, be able to do non-local transfers of control or | have automatic memory management then you will have to do extra | work that you would not have to do if you were compiling to | assembler or an abstract RTL. | | Finally, compiling to C gives the student the impression that | there is something holy and immutable about C, that C is The Way | and the Truth and the Light and no man comes to the lambda nature | but through C. It's not true, and, to paraphrase Dykstra, the | psychological damage caused by indoctrinating people into this | worldview is hard to undo. | lebuffon wrote: | Everybody knows that CPU stands for: 'C' | Processing Unit | | ;-) | lebuffon wrote: | Krenshaw's classic version is available in C. | | https://github.com/lotabout/Let-s-build-a-compiler | reeealloc wrote: | Wrote a compiler with .NET last year. Used F# for the | Lexing/Parsing to an AST and C# for LLVM IR code gen. Interop was | so easy, but the docs for the C# LLVM bindings were not so great, | so it's a little incomplete. I only got it to effectively | interpret, never actually executed a whole outputted object file. | tester756 wrote: | When I've been messing with this stuff, then I decided to | manually write LLVM IR instead of using C#'s LLVM Bindings | risk wrote: | The author of this is part of the binary grand prix and made my | favorite submission to the contest. Very cool content thanks for | posting it. ___________________________________________________________________ (page generated 2021-08-14 23:00 UTC)