Live data from Hacker News

Want to write a compiler? Just read these two papers (2008)

prog21.dadgum.com

121–130 of 173 posts

Re: Want to write a compiler? Just read these two papers (2008)

#121
post #46

Would a practical approach be parsing the source into clang's AST format. Then let it make the actual executable.

You'd more likely want to emit LLVM IR rather than try to match clang's internal AST. That's essentially what most new language projects do now (Rust, Swift, Zig all use LLVM as their backend). You get optimization passes and codegen for multiple architectures for free, and the IR is well-documented. The tradeoff is you skip learning about the backend, which is arguably the most interesting part.

Re: Want to write a compiler? Just read these two papers (2008)

#122

Earlier quoted context omitted.

No, the problem is much more basic than "taking over your computer," it looks like the compiler generates incorrect assembly. Upon visual inspection I found a huge class of infinite loops, but I am sure there are subtle bugs that can corrupt running user/OS processes... including Docker, potentially. Containerization does not protect you from sloppy native code. > Don't use it to compile production code! This is an u…

You have not provided any evidence that can be refuted, only vague assertions. The compiler is indeed useless for any purpose other than learning how compilers work. It has all the key pieces such as a lexer, abstract syntax tree, parser, code generator, and it is easy to understand. If the general approach taken by the compiler is wrong then I would agree it is useless even for learning. But you are not making that…

The thing that is obviously and indisputably wrong, terrible for learners, is the test cases. They are woefully insufficient, and will not find those infinite loops I discovered upon reading the code. The poor test coverage means you should assume I am correct about the LLM being wrong! It is rude and insulting to demand I provide evidence that some lazy vibe-coded junk is in fact bad software. You should be demanding evidence that the project's README is accurate. The repo provides none.

The code quality is of course unacceptably terrible but there is no point in reviewing 1500 lines of LLM output. A starting point: learners will get nothing out of this without better comments. I understand what's going on since this is all Compilers 101. But considering it's a) stingily commented and b) incorrect, this project is 100% useless for learners. It's indefensible AI slop.

Re: Want to write a compiler? Just read these two papers (2008)

#123
post #22

*Donald Knute -> Donald Ervin Knuth is the author of the book "The Art of Computer Programming" (in progress for a couple of decades, currently volume 4c is being written). It is quite advanced, and it will likely not cover compilers anymore (Addison-Wesley had commissioned a compiler book from Knuth when he was a doctoral candidate, now he is retired and has stated his goal for the series has changed). I disagree wi…

The dragon book almost convinced me never to try to write a compiler. I don't know why people recommend it. I guess you're a lot smarter than I am. There are some excellent books out there. In its own way, the dragon book is excellent, but it is a terrible starting place. Here are a bunch of references from the same vintage as OP. I recommend starting with a book that actually walks through the process of building a…

Great thread. If you have 1 hour to get started, I recommend opening Engineering a Compiler and studying Static Single-Assignment (SSA) from ch 9.3.

The book is famous for its SSA treatment. Chapters 1-8 are not required to understand SSA. This allows you to walk away with a clear win. Refer to 9.2 if you're struggling with dominance + liveness.

http://www.r-5.org/files/books/computers/compilers/writing/K...

Re: Want to write a compiler? Just read these two papers (2008)

#124

Earlier quoted context omitted.

You have not provided any evidence that can be refuted, only vague assertions. The compiler is indeed useless for any purpose other than learning how compilers work. It has all the key pieces such as a lexer, abstract syntax tree, parser, code generator, and it is easy to understand. If the general approach taken by the compiler is wrong then I would agree it is useless even for learning. But you are not making that…

The thing that is obviously and indisputably wrong, terrible for learners, is the test cases. They are woefully insufficient, and will not find those infinite loops I discovered upon reading the code. The poor test coverage means you should assume I am correct about the LLM being wrong! It is rude and insulting to demand I provide evidence that some lazy vibe-coded junk is in fact bad software. You should be demandin…

Sorry I disagree. I have written compilers by hand and this compiler generated by Claude is pretty good for learning.

I am only asking you to backup your own assertions. If you can't then I would have to assume that you are denigrating AI because you are threatened by it.

Re: Want to write a compiler? Just read these two papers (2008)

#125

Earlier quoted context omitted.

The thing that is obviously and indisputably wrong, terrible for learners, is the test cases. They are woefully insufficient, and will not find those infinite loops I discovered upon reading the code. The poor test coverage means you should assume I am correct about the LLM being wrong! It is rude and insulting to demand I provide evidence that some lazy vibe-coded junk is in fact bad software. You should be demandin…

Sorry I disagree. I have written compilers by hand and this compiler generated by Claude is pretty good for learning. I am only asking you to backup your own assertions. If you can't then I would have to assume that you are denigrating AI because you are threatened by it.

[deleted]

Re: Want to write a compiler? Just read these two papers (2008)

#127

Earlier quoted context omitted.

The thing that is obviously and indisputably wrong, terrible for learners, is the test cases. They are woefully insufficient, and will not find those infinite loops I discovered upon reading the code. The poor test coverage means you should assume I am correct about the LLM being wrong! It is rude and insulting to demand I provide evidence that some lazy vibe-coded junk is in fact bad software. You should be demandin…

Sorry I disagree. I have written compilers by hand and this compiler generated by Claude is pretty good for learning. I am only asking you to backup your own assertions. If you can't then I would have to assume that you are denigrating AI because you are threatened by it.

[flagged]

Re: Want to write a compiler? Just read these two papers (2008)

#128

Earlier quoted context omitted.

Sorry I disagree. I have written compilers by hand and this compiler generated by Claude is pretty good for learning. I am only asking you to backup your own assertions. If you can't then I would have to assume that you are denigrating AI because you are threatened by it.

[flagged]

You claimed bugs, and when asked for evidence of said bugs, you said it is rude to ask for evidence, and I should simply "assume" you are right. Okay. I think people can make up their own minds as to what that means.

Re: Want to write a compiler? Just read these two papers (2008)

#129

An Incremental Approach to Compiler Construction Abdulaziz Ghuloum http://scheme2006.cs.uchicago.edu/11-ghuloum.pdf Abstract Compilers are perceived to be magical artifacts, carefully crafted by the wizards, and unfathomable by the mere mortals. Books on compilers are better described as wizard-talk: written by and for a clique of all-knowing practitioners. Real-life compilers are too complex to serve as an education…

Nada Amin has a nice implementation of Aziz's approach, with tests:

https://github.com/namin/inc

Post reply on HN