4 ms·
At uni I went through a module on compilers which basically covered all the Dragon book. I then followed this on-line course where you actually write a compile
by pulsarpietro 9y ago
At uni I went through a module on compilers which basically covered all the Dragon book.
I then followed this on-line course where you actually write a compiler for the COOL language. It has been one of the best educative things I've ever done in my life and I can't help recommending it.
https://lagunita.stanford.edu/courses/Engineering/Compilers/Fall2014/about https://lagunita.stanford.edu/courses/Engineering/Compilers/...
I'd love to do something like that in my professional career but unfortunately 90% of the time I ended up carrying out way less interesting work (writing application for end users).
- jasim 9y agoThere's no better advertisement for the utility of learning to write a compiler than this introduction from the excellent "Engineering a Compiler" by Cooper and Torczon: Why Study Compiler Construction? A compiler is a large, complex program. Compilers often include hundreds of thousands, if not millions, of lines of code, organized into multiple subsystems and components. The various parts of a compiler interact in complex ways. Design decisions made for one part of the compiler have important ramifications for other parts. Thus, the design and implementation of a compiler is a substantial exercise in software engineering. A good compiler contains a microcosm of computer science. It makes practical use of greedy algorithms (register allocation), heuristic search techniques (list scheduling), graph algorithms (dead-code elimination), dynamic programming (instruction selection), finite automata and push-down automata (scanning and parsing), and fixed-point algorithms (data-flow analysis). It deals with problems such as dynamic allocation, synchronization, naming, locality, memory hierarchy management, and pipeline scheduling. Few software systems bring together as many complex and diverse components. Working inside a compiler provides practical experience in software engineering that is hard to obtain with smaller, less intricate systems.
- Someone 9y ago”A compiler is a large, complex program” Writing a compiler isn’t much harder than writing an interpreter, if at all. Assuming your language can be parsed without running it (Perl, for instance, cannot, in general. See https://www.perlmonks.org/?node_id=663393 https://www.perlmonks.org/?node_id=663393), it is just a matter of doing that and emitting code for every statement, plus some bookkeeping in order to fix up branches. If the language you are compiling is simple, that’s not hard to do. The result will not be the fastest possible, but it will be compiled code, and it will be faster (sometimes significantly so) than interpreting the program.
- ttd 9y agoAre you trying to dispute that compilers are large and complex? It seems like you are saying that if the language is simple, a non-optimizing compiler for it can be simple, which seems somewhat obvious. I think the "microcosm of computer science" and associated complexity become apparent when the source language is not simple, the middle end contains many optimization passes, and the back end requires more than simple statement emission.
- Someone 9y agoYes. The categorical statement “compilers are large and complex” is incorrect, and IMO is detrimental to getting people interested in the field. We don’t say “Web applications are large and complex”, either. Just as you can start simple with a web application and, if needed, grow it, you can start with a simple compiler and, if needed, grow it. (And, on current hardware, I think the complexity of the language matters less than it used to. Single pass languages such as pascal still are easier targets, but computers have plenty of RAM, so fixing up things is easier than it used to be.
- nine_k 9y agoWriting a trivial and inefficient compiler is indeed not that complex, especially if you choose a simple language. Writing a smart optimizing compiler must be a pretty different kettle of fish.
- detaro 9y agoAnd a good, optimizing interpreter also is "a large, complex program". Both can be fairly easy if implemented naively, but gain complexity quick.
- wglb 9y agoIt is unclear if Perl is actually a language.
- wglb 9y agoThis a terrific quote. Having written a production compiler in a previous lifetime, and talked with developers over the years since then, it is clear the difference that knowledge makes in their day-to-day programming.