Live data from Hacker News

C Compiler from Scratch

github.com

31–40 of 68 posts

Re: C Compiler from Scratch

#31

I misread and thought someone created a C-compiler in Scratch. That'd have been extremely impressive... :))

That sounds like a challenge someone might actually try...

Along the same lines, you may find this amusing: https://news.ycombinator.com/item?id=7882066

Re: C Compiler from Scratch

#32
post #29

Do you know of similar types of tutorials / repos except for language parsers (like markdown or json) ? How difficult would it be to implement in comparison to a compiler ? Where should I start looking ? (I want to build a compiler at some point but I want to get my feet wet building a simple language parser first) Thanks in advance

Just take any tutorial about writing a compiler and stop at the Abstract Syntax Tree generation.

There is not that much difference between parsing a programming language like C and something like JSON. JSON grammar is smaller but the ideas are the same. In fact, JSON is essentially a subset of JS, and JS has a C-like syntax.

What makes a compiler a compiler is what comes after the parser, i.e. code generation.

Re: C Compiler from Scratch

#33

This might be relevant A Retargetable C Compiler: Design and Implementation by David Hanson and Chritopher Fraser https://www.amazon.com/Retargetable-Compiler-Design-Implemen... Written in a literate programming style.

Happy new year to you Ravi!

Thanks Jacques. Same to you, (and everyone on HN!)

Re: C Compiler from Scratch

#34
post #21

I feel that many introductions to scanning and parsing are based on old techniques when memory were scarce. In those times storing your files in memory, was simply impossible. But we live in times where we have gigabytes of ram and there are not many projects that could not be read into memory. (Tell me about a project that has a gigabyte of source files, please.) So, why not assume your input to be stored in a strin…

The parser stores the entire AST in memory, it is not acting as if it was scarce.

As for the idea of not starting with a string but instead reading the file on the fly, I think it is actually simpler. The point of storing the entire file in memory is to enable going back and forth, but why would you want to do that? State machine based parsers are fast, robust, and based on a solid theoretical grounds, at least for "simple" (context-free) languages.

Re: C Compiler from Scratch

#35
post #23

Earlier quoted context omitted.

Compiler Construction Using Java, JavaCC, and Yacc Book by Anthony J. Dos Reis Uses similar approach with much more details on theory and implementation. I learned so much from this book. It teaches you to write a hand written compiler and by using tools like javacc/yacc as well. But I really love how the author explains the knots and bolts on creating a hand written compiler. Get this book if you're interested in cr…

JavaCC was my favorite way of playing with compilers back in early 2000, sadly it appears not to be developed any longer, with a couple of forks floating around the Internet. Any Idea what is the actual state?

github repo is very active: https://github.com/javacc/javacc

Re: C Compiler from Scratch

#36

Earlier quoted context omitted.

Interesting. But you have to register for this. Does anyone have any links to some good compiler classes on YouTube or elsewhere?

Is that an issue given the course is free?

Yes. Not everyone likes to give away their personal information - especially (paradox) in exchange for access to a free resource.

Re: C Compiler from Scratch

#37

I'm learning from the Compiler course offered freely from Stanford [0] and the dragon book. I still feel great about it. And I think this GitHub project submitted will be an excellent practical source for analysis of how real world compiler might looks like from its beginning. [0]: https://lagunita.stanford.edu/courses/Engineering/Compilers/...

Interesting. But you have to register for this. Does anyone have any links to some good compiler classes on YouTube or elsewhere?

The entire course on YouTube:

https://www.youtube.com/playlist?list=PLDcmCgguL9rxPoVn2ykUF...

Re: C Compiler from Scratch

#38
post #14

I'm learning from the Compiler course offered freely from Stanford [0] and the dragon book. I still feel great about it. And I think this GitHub project submitted will be an excellent practical source for analysis of how real world compiler might looks like from its beginning. [0]: https://lagunita.stanford.edu/courses/Engineering/Compilers/...

I applaud you for reading the dragon book. It's a pretty tough book to read.

Yeah, I find MTW's Gravitation easier going, and Knuth's treatise more fun.

Re: C Compiler from Scratch

#39
I remember the time when writing a compiler for Pascal - complete with a code generator (for 8086) - was a routine assignment for CS students at the end of the first semester of the second year.

Re: C Compiler from Scratch

#40

Earlier quoted context omitted.

I want to dive into creating a language / compiler finally but I might do it with the Writing an Interpreter / Compiler series in Golang. Just so I can dive in and try to digest it all. Course I always heard of the dragon book and have wanted it since.

> Course I always heard of the dragon book and have wanted it since. I wouldn’t read it except out of historical interest - it’s not how we build compilers anymore, with its super-heavy emphasis on parsing and syntax-directed translation.

Is there something close to it in the modern sense then?
Post reply on HN