I Appreciate Compilers A Lot More Now
Fall 2024Overall Rating (3.9 / 5): ★★★★☆
Professor Rating (2.5 / 5): ★★★☆☆
Lecture Rating (3.6 / 5): ★★★★☆
Difficulty (3.6 / 5):
Workload: 15 hours/week
Pros:
1. Was honestly really cool writing a compiler (for a toy, example language though) and learning how a basic one actually works
2. Lectures were surprisingly engaging. Subject is dry but the professor does seem like he genuinely likes to teach
3. No big final project (I hate final projects)
4. You get to practice your Java (you don't need to know it ahead of time, it's very easy to pick up the couple Java-isms needed)
Cons:
1. Professor can come across as an annoying personality especially if you ask questions (I do think he is nice though in terms of how he grades and structures the class. I'll say he averages out as just average then)
2. Midterm and final were okay but seemed sorta pointless, did not learn much from them
3. Pacing of projects was very off. 2nd by far took the most effort. I think they should have spread it out better. Not sure why you had to go all the way up to level 3, when they could have made you go to level 2 first, and call that its own project.
Detailed Review:
Pro #1 definitely holds. Used to get very annoyed by compiler errors, now I get less annoyed :). Makes a lot of sense in hindsight, but I never realized a compiler is really just doing a massive string parse of your entire program. So it now makes sense when an error is thrown because it's not in the format it expects. Again, sounds dumb and basic writing it out, but it was cool for it to actually click.
Advice for actually completing the projects: takes a bit to wrap your mind around the first project and the second one too. For the very first one, they'll post examples on the forums which help a lot. You'll quickly realize you basically always want a space for your return value, then your input variables right at the top, then do your operations on those by first making copies of them, consuming them as you do your operations. Then once you have your final result, go store it to the space you made for the return value, and then pop everything else off. To make your life a whole lot more easier for project 2, make sure that your push and store operations are only the relative ones, not the absolute position ones, and that all the code you write works so long as your inputs are on top of the stack, doesn't matter how big the stack is. So like make sure your concat will, no matter how big the stack is, so long as there is two strings at the very top, once you entire concat code runs, you will be left with just the concatenated string at the very top, the inputs will be consumed and gone. If want to make your life even more easier, make sure any named labels you do use are unique for each function you write. You'll understand why that's needed when you do project 2. Get used to debugging here too by stepping over each line and command. You will definitely need to do that a lot later on
For project 2, I think there a couple ways to do it, as in formatting your code and the overall approach you take. I think the least amount of issues will occur if you are fine with doing the entire compilation in not just one go around (I can't remember if it's this project or the next one, but you will realize that you can use functions before they are declared so you need some way to know whether they exist, which means you need to loop through the program text twice). The hardest thing to figure out is expressions: just remember that it doesn't matter how much spaghetti code you write, and you can definitely take advantage of global variables since you are writing java code, all you have to make sure is you return a correct program that passes all the test cases. It's useful to have a temporary file that you can write example test cases on and try to compile that with your code often. For the documentation they give you, all you really need is the one page that shows you the token type and all the commands you can call on it. It's useful to find the actual Java class code that does this and have it open in a separate page in your IDE and get used to the various functions you can use. Finally, making a recursive function for each grammar/language line that will return a string of compiled code is definitely the best way to structure your compiler.
If you can do the above project, you will be completely fine for the rest of the class. You have quite a bit of time to get it done, just be sure to start early and really think about it how to do it, and take it one grammar rule at a time. It's pretty satisfying when you get it all working.
Midterm/final were kinda annoying with some tricky questions. Make sure to watch and rewatch the lectures. Midterm was mostly just multiple choice and fill in the blank, but final actually required paragraph answers. Again, if you understand the practice tests given to you (and carefully read the diagrams and/or understand the question being asked) and really understand the concepts being discussed in the lectures, you will be fine.