Compiler
One course that I was disappointed in from my college days was my compiler (theory) class. The reason it disappointed me was that it was/is something I have interest in, but I really didn’t learn much from the class. There are multiple reasons for that: the department could barely find a professor for the class (ended up with an EE professor), the class was in Java and a barely knew any Java at the time which made the class much more difficult, and it used some random text book instead of the Dragon book.
So, to resolve my disappointment I’m going to implement a compiler. Or rather an interpreter. Or both. I’ve downloaded ANTLR and I’m going to play around with it. I will build up a grammar, a lexer, a parser, generate an AST. And from that point, I’ll probably implement something to walk the tree and interpret. Beyond that, it is pretty much up in the air. I could turn it into a VM of sorts by serializing the AST or I could do some real code generation.
Then there is the matter of what language to implement. I could make my own, I’ve wanted to do that. But my thoughts of how the language should be have evolved and will likely continue to evolve, and I should probably hold off and see how it evolves after some practical implementation experience. For some perverse reason, I think I will do PHP. This is partially because I think the language itself is relatively simple. I can probably get a good head start by looking at a C or Java grammar.
And the implementation will be done in C++ — because it’s been years since I’ve done any serious C++, and every time I hack up C code, I wish for certain things that exist in C++ but not in C (scoped resources being one - RAII). I was never a C++ guru, and I would definitely like to brush up. Use it or lose it, I guess.
But wait, what about your other random personal projects? Yeah, it’s some sort of mental stimulation/ADD issue. My top personal project is very different (much less technical, but still involves quite a bit of learning and experimentation) and has a much shorter timeline. This would be my #2 project, and with a much longer timeline. Hopefully, they’ll tickle different parts of my brain, and I can jump in between them as I get bored.










August 20th, 2007 at 8:09 pm
There was some discussion of parsing PHP on the JavaCC list a while back. I think Tim solved the difficulties with the include operator using the precedence climbing technique.
August 21st, 2007 at 10:30 pm
That’s quite interesting. Thanks for the heads up.
I’m nowhere near that level of detail yet.
In use, I’ve always basically treated it as a function but I guess I’ll need to take more caution when implementing it.