Writing compilers is actually rather easy. The hard part is dealing with other programs. For example, last week I finally tracked a bug down to the documentation on how the function ABI worked was simply wrong.
Compiler writing isn't the easiest thing in the world by any stretch, but it's something that we manage to achieve all the time, unlike the mythical "program to do my programming" we are so quick to imagine.
I just finished writing a compiler for a CS class. I was surprised at how logical it ended up being. For me, it really took away a lot of the mystic nature surrounding compilers.
Writing a compiler for a small language with minimal optimization features and an easy to understand assembly/bytecode format is actually relatively straightforward.
But a lot of programmers think compilers are magic. Maybe because they read about stuff like parser generators, register allocators, optimizations, etc., that are not strictly necessary. It's empowering to remind people that a seemingly hard task is within their reach.
Writing a compiler is easy. Optimizing one, not so much, but setting "writing a compiler" as some kind of difficult thing that requires arcane magic irritates me.
I agree with you. In fact I would say understanding compilers is really pretty easy. They are some of the most well researched and documented subjects (in CS) out there. Almost all compilers are going to follow a similar structure of lex -> parse -> pass0 -> passN -> generation.
The challenge these days seems to be in the passes which can become numerous and complex.
Compiler writing is easy? No. (I've built compilers for large subsets of C and Java, as well as my own languages)
Lord help you if you try to write a perfectly conforming compiler for C++ (has it ever been done?), and the U.S. legal system is at least an order of magnitude more complex than that.
reply