Friday, May 20, 2011

Why I've Been So Busy Pt2: Compilers

Took my a while to get time to write this up.  I've been busy moving stuff and getting back to work now that schools out.  Anyways, I took a compilers course last semester, it was a lot of work but it was fun and I learned a lot.  I mainly took it because of this blog post http://steve-yegge.blogspot.com/2007/06/rich-programmer-food.html that was in Hacker Monthly.  After reading it I was all about taking compilers.  Then a month went by and it was time to sign up for classes.  I almost didn't take compilers, in fact I had to read the article again to convince myself to.  I am glad I did.  I have a better understanding how they work, and what errors mean just to name a few things.

Anyways, in the class we made our own interpreter for a language KLOGO, specified by the professor.  It is a "logo" like language, in that it interprets your commands and moves a turtle around to draw a picture.  We used flex and bison for our parser/scanner respectively and the graphics professor at my school programed the graphics part we were to interface with.  After the scanning and parsing an AST was produced, that was type checked and finally executed the code.  It sounds pretty simple when I say it now, but it was a lot of work.  Below is an image of my interpreter interpreting a program I made.  It demonstrates most features of the interpreter.  Note: the output in the terminal was to demonstrate to the professor that it actually was working, and not just an image I drew.