The first (and only) project for my CS 570 class (Theory of Computation) was to write a parser for a context-free LL(1) language made up by our instructor. I won't get into the specifics, but this was the basic structure of my entry: use a function for each non-terminal, and only check for the first of the "right hand side" of each grammar rule. I made the very easy and glaringly bad decision to declare a global token variable, which was modified directly by every function. So, essentially, there was just the one variable and each function got to check it out when it was its turn. This was especially cringe-worthy in the do-while loops; if the token was equal to a specific character at a specific point in time, it would jump into the "do" part. The functions in the "do" would modify the token, and then it would be checked at the end in the "while" section. Then it would act accordingly. This makes me cringe...
Because I'm a ridiculous nerd, I rewrote the program to utilize local char variables passed between the functions (easy as cake). This was certainly something I should have done in the first place, but I'm not too overly concerned about it, since I still managed to get an A on the project.
Here are the original project and the updated version.
I started working on a third version that optionally takes a file name as an argument when you invoke the program, reads the file, and then parses the sentences accordingly, but this modification will require more insight.
What's the moral of the story? The first project took me about 2 hours to do, I half assed it, and even though it worked, I still feel like I could have done better if I had taken the time to work on it a little longer and put a little more work into it. I also like consistently trying to improve on my older work even when the projects are, at best, trivial (or, in this came, seemingly trivial with applications to far less trivial projects, ie compilers). Practicing the basics never ever hurts, as long as you are able to move on and work on something more substantial and don't spin your wheels over return types, etc.
Hello 2012, I’m Josh. It’s nice to meet you.
12 years ago
No comments:
Post a Comment