Section 3 with Remik (rz33@cornell.edu) Meeting #7 Notes ---------------------------------------------------------------------------- Administrivia: Assignment #3 will be out this Friday Review: Common mistakes in Assignment #2 How to approach the following Assignments The intuition behind FBR and frames Common mistakes in Assignment #2 ---------------------------------------------------------------------------- Our compilers were not robust enough to handle the grammar in the general case. For example, comments should be allowed anywhere within a Bali program, so don't just 'look' for it before a function. We could encounter % add two variables r = x + y; r = r / 2; % and get their average Also, be aware of keyword usage. We say that our keywords are 'reserved' if we don't allow them to be used as variables or functions. If we did, then our parsing could get a little confusing. Would we interpret a variable as a malformed expression or what? Handling this is easy, because we know a priori what words to look for. Our compilers can and do have state, so use your favorite data structures to 'remember' particular properties about an atomic thing like a variable. An obvious property for variables in Bali is type, among others. How to approach compiler design ---------------------------------------------------------------------------- Before reading this, I refer you to p.255 of Brookshear, "Computer Science: An Overview" on more about compilers (yes, this class has a book!). You should take advantage of Java and modularize your compiler. Handle the input in phases, each doing something pretty specific. Recall our comments in Bali. Well, in a 'Lexical Analysis' step, all that junk can be filtered. |------------------| Bali Code --->| Lexical Analysis |---> Bali Code w/o comments |------------------| Of course to do that you may need to extend CS211In and make it a bit more customized. That's fine, because we're allowing you to do just that for all the following assignments. The intuition behind FBR and frames ---------------------------------------------------------------------------- Consider a frame as a contract between two parties: a caller and callee. The caller is who gave birth to the frame, and the callee looks in there for the goodies, like function parameters. When the callee has done its thing, it ALWAYS puts something back at offset -1, 'rv' (return value). 'main' is the only exception. When you wish to add function handling in the compiler, be sure to use the suite of SAM templates in the CS212 Lecture #8 notes as a way to start.