Live data from Hacker News

C Compiler from Scratch

github.com

21–30 of 68 posts

Re: C Compiler from Scratch

#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 string.

Re: C Compiler from Scratch

#22
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…

> Tell me about a project that has a gigabyte of source files, please.

Here's one, apparently: http://lists.llvm.org/pipermail/cfe-dev/2019-October/063459....

Re: C Compiler from Scratch

#23

This is fantastic work. I believe learning to write a compiler is similar to learning a functional programming language. It completely changes the way you approach problems. I'm curious why BNF was chosen vs EBNF. I'm new to parsers and grammar. Isn't EBNF easier/simpler to write complex rules?

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?

Re: C Compiler from Scratch

#24

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!

Re: C Compiler from Scratch

#25
post #22
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…

> Tell me about a project that has a gigabyte of source files, please. Here's one, apparently: http://lists.llvm.org/pipermail/cfe-dev/2019-October/063459....

This is actually not about a source repository being larger than a gigabyte, but a problem that arises with the C-preprocessor, where for a certain use, a certain header file is included many, many times, and where the position for all includes is kept. Typically a case of severe C-preprocessor abuse, I would say, which probably could be solved in a much better way. This shows how the C-preprocessor is both a blessing and a curse: it fixes many problems, but often causes compilation to be slow, because huge intermediate representations are produced which have to be parsed by the compiler.

Re: C Compiler from Scratch

#26

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/...

> 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. If you want to understand how people build production (or even prototype) compilers, this is not going to be a good source. Most compiler courses are going to take you from a compiler from the frontend through the middle-end and into the backend. But, if you we…

Is there any course you've found to be more along the lines of how real compilers work ?

Re: C Compiler from Scratch

#27
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…

At my first job they used a programming language that worked on top of c somehow developed by their sister company(used to be the same but split) all that to make a shitty ERP and eh...it was many, many gigabytes partially written by people now retired. I don't think the few images and other such stuff used were part of that (it also had a few random cobol files i encountered) and it had everything from the UI rendering and handling to a webserver i had to communicate with but about which nobody knew how it worked because the guy who made it was enjoying his olden days.

To be totally fair it was the biggest inefficient coding mess I've seen. I still regret not scanning and keeping the customerlist because if I did i'd be deep in that business right now making bank.

Re: C Compiler from Scratch

#28

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 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.

Re: C Compiler from Scratch

#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

Post reply on HN