posted on Tuesday, September 26, 2006 8:44 AM
by
timbarcz
Lexical Scanning and Parsing Part 1
A few years back for my honors project as a senior in college I built my own computer language. It wasn't object oriented (that would've been cool) and looked like a cross between C and Pascal. I wrote everything in C++. Looking back I can't remember what got me interested in compiler theory and thinking that building a compiler would be a good idea. Regardless I defined a language and built a compiler for that language. It was pretty slick. It could handle looping structure (for and while), conditionals (if, if/else), arithmetic, variables, boolean expressions, and functions, basically anything a "normal" language should handle. It was originally built to be used in entry level programming classes at the college I attended. The computer science department had made the switch from Pascal to Java as the learning language a few years after I had passed through. The problem with Java was that it was somewhat complex for beginners. You have to import libraries at the beginning of each of your .java files. It forced you right into object oriented thinking before you understood what a struct, conditional, or array was. Nothing against Java, but you're required to trust a lot of the innerworkings before you understand them. The same can be said of many languages out there today. My language was supposed to ease all that by allowing a person to learn the basics of programming with a lightweight compiler.
In order to compile the source code into an executable, my lexical parser/scanner would go through the source code, and write Intel assembly to a file which was then processed to make an executable. There was an added benefit to the architecture that allowed the assembly to be viewed after the executable was generated. Upperclassmen, in their advanced courses, could type an expression in my language, and view the subsequent Intel assembly (much like MSIL). It was a great way to bridge the gap when learning assembly.
It was something I was very passionate about at the time. I spend hundreds of hours working on the darn thing. I remember on summer nights during break when friends were going out to a movie and I had to pass because I had to figure out how to get the value returned from a function into a variable, all in assembly. When building it I never thought it would help me in the real world and it was simply an exercise in geekiness. Soon after I gave my presentation to the honors committee, all knowledge of the language I had written, was relegated to the far reaches of my brain, where Ace of Base and other early 90's pop musical lyrics are stored, most likely never to serve me again.
Just this past month, I came across the second time that assumption was wrong.
(More in part 2 tomorrow)
Comments