Compiler Construction

Compiler construction was the worst course I took in college. Frankly I did not learn anything. When I was working in Xinjiang University, once I even asked Ghalip, a friend of mine who teaches compilers, how he could teach that horrible, boring class. After almost 10 years, I am taking compiler class in this semester. The instructor has very good reputation. I am also much more confident about the class, since I think I learned a lot about formal languages and automaton. I like those regular expressions and DFAs. I often play with the regular expressions too. As I expected, this time compilers class is fun. It is nothing like the compilers class I took in college. I liked the lectures. But I especially liked the projects, in which we build a real compiler. First project was Lexer and Parser. 2nd project was building the AST. 3rd project was type checking. Yesterday, I have finished the 3rd project. Now, I can parse a program, build the AST representation, traverse the AST, collect the symbols, and statically type check. Basically, if you have “i=1;” in your code, I can tell the assignment is not type correct because the “i” is boolean.  The projects are interesting, but time consuming. I spent many nights for the 3rd project. I really feel “To Iterate is Human, to Recurse, Divine” now. Think about “x=b.i.k.j+a[a[a[a[c]]]]  != foo()”. Right hand side of the assignment is an expression, which includes 3 expressions. What if foo() return null? How about the field expression  “b.i.k.j” or the array a[a[a[a[b]]]]? Recursion made it easy, or possible if I am not wrong. Now, I can read a source code and rewrite it with beautiful indentation from the internal representation of the code. Isn’t it cool? Before I took this class, compiler is about translating the source code the the machine code. I was wrong. I learned so much stuff, but we even did not talk about the code generation yet. It is just one stage among those many stages we are learning. Next project is posted. With that project, I can tell the “x=1” in your code is never used, Eclipse tells you anyway.  Maybe I can do more. I can’t wait to start the next project. I am ready to spend many days with frustration, feeling otiose, joy, anger and pleasure of achievements.

This entry was posted in Uncategorized. Bookmark the permalink.

Leave a comment