Live data from Hacker News

Writing a C Compiler: Build a Real Programming Language from Scratch

nostarch.com

11–20 of 159 posts

Re: Writing a C Compiler: Build a Real Programming Language from Scratch

#12
post #4
post #3

I swear I've seen this cover before... is this a new release or an updated edition of an older book?

Book is not yet published but in early access since a couple of years Was featured here a couple of times. Unfortunately the timing of the release is quite unfortunate with regards to the summer holidays. Will take a look at it next year

> Book is not yet published but in early access since a couple of years

According to the top post's link, it was released in July 2024.

Re: Writing a C Compiler: Build a Real Programming Language from Scratch

#13
post #4
post #3

I swear I've seen this cover before... is this a new release or an updated edition of an older book?

Book is not yet published but in early access since a couple of years Was featured here a couple of times. Unfortunately the timing of the release is quite unfortunate with regards to the summer holidays. Will take a look at it next year

It’s actually out now, I have a copy! Ordered directly fro No Starch Press.

Re: Writing a C Compiler: Build a Real Programming Language from Scratch

#14
So what's different about writing a compiler in 2024 than say 10, 20, or 30 years ago? When I started writing compilers in the 80's and 90's lex/flex and yacc/bison were popular. ANTLR came out but I never had a chance to use it. Everything after lexing and parsing was always hand rolled.

Re: Writing a C Compiler: Build a Real Programming Language from Scratch

#15
Weird that this is about building a C compiler[0] in OCaml. I expected the implementation language to also be C both for consistency but also because i'm willing to bet that there are more people who can read C than OCaml.

[0] actually from the readme in the github repo[1] it seems to be a C subset, not all of C

[1] https://github.com/nlsandler/nqcc2

Re: Writing a C Compiler: Build a Real Programming Language from Scratch

#16
post #14

So what's different about writing a compiler in 2024 than say 10, 20, or 30 years ago? When I started writing compilers in the 80's and 90's lex/flex and yacc/bison were popular. ANTLR came out but I never had a chance to use it. Everything after lexing and parsing was always hand rolled.

Parser-generators were always academic projects that had little relevance to making real-world programming languages -- where parsing is very easy to write, and necessarily benefits from doing it (ie., you can get better error handling/etc.).

Today most languages are front-ends for LLVM IR, but LLVM is very slow and takes a long time to optimize. Many new languages target x86/arm directly with their own weakly optimized backends, and output an LLVM IR for "release builds".

Re: Writing a C Compiler: Build a Real Programming Language from Scratch

#18
post #14

So what's different about writing a compiler in 2024 than say 10, 20, or 30 years ago? When I started writing compilers in the 80's and 90's lex/flex and yacc/bison were popular. ANTLR came out but I never had a chance to use it. Everything after lexing and parsing was always hand rolled.

Parser-generators were always academic projects that had little relevance to making real-world programming languages -- where parsing is very easy to write, and necessarily benefits from doing it (ie., you can get better error handling/etc.). Today most languages are front-ends for LLVM IR, but LLVM is very slow and takes a long time to optimize. Many new languages target x86/arm directly with their own weakly optimi…

Could you give some specific examples of those new languages with their own backends for faster builds?

Re: Writing a C Compiler: Build a Real Programming Language from Scratch

#19
post #14

So what's different about writing a compiler in 2024 than say 10, 20, or 30 years ago? When I started writing compilers in the 80's and 90's lex/flex and yacc/bison were popular. ANTLR came out but I never had a chance to use it. Everything after lexing and parsing was always hand rolled.

Parser-generators were always academic projects that had little relevance to making real-world programming languages -- where parsing is very easy to write, and necessarily benefits from doing it (ie., you can get better error handling/etc.). Today most languages are front-ends for LLVM IR, but LLVM is very slow and takes a long time to optimize. Many new languages target x86/arm directly with their own weakly optimi…

When your computer was anemic, and could barely do the tasks required for it, eking out a few percent — or a 2x! — from an optimizer was important.

Now-a-days, the difference between "big compiler optimized" and "little compiler not optimized" can be quite dramatic; but, is probably no more than 4x — certainly within range of the distinction between "systems programming language" and "high tuned JITted scripting language". I think most people are perfectly fine with the performance of highly-tuned scripting languages. The result is that all of the overhead of "big compiler" is just ... immaterial; overhead. This is especially true for the case of extremely well-tuned code, where the algorithm and — last resort — assembly, will easily beat out the best optimizer by at least an order-of-magnitude, or more.

Re: Writing a C Compiler: Build a Real Programming Language from Scratch

#20

Weird that this is about building a C compiler[0] in OCaml . I expected the implementation language to also be C both for consistency but also because i'm willing to bet that there are more people who can read C than OCaml. [0] actually from the readme in the github repo[1] it seems to be a C subset, not all of C [1] https://github.com/nlsandler/nqcc2

OCaml? Thanks for saving me a click!
Post reply on HN