Do an update75 to get the starting point files for this project. This will create the directories cs75/projects/1a and cs75/projects/1b.
Implementing the code for the lexical analyzer is straight forward once you have developed a correct DFA that accepts all of the tokens in the language. Therefore, you will complete parts 1-3 (given below) and turn them in before beginning on the implementation in part 4.
/* a comment that can go for several lines */ // a single line comment, where everything to the right is ignoredWhen a comment is encountered, the lexical analyzer should return the next valid token following the comment. Comments should NOT produce tokens.
Below is an example of C-- code that can be used to test your scanner. Note that your actual token names do not need to be the same as the ones shown in this examples.
// this will be ignored int main() { x = 0; _abc = 8; /* this too will be ignored */ if (x & 10) write x; else ; return 0000042 }
Notice that there are a number of errors in this code, some can be caught by the scanner, some by the parser, and some can only be recognized in code generation. For example the last statement is missing a semi-colon. This error can be recognized by the parser, but not by the scanner. Also, variables must be declared at the top of a block in C--, but the variables x and _abc have not been declared. This error can be caught in code generation, but not by the scanner. However the scanner can recognize that the && operator must consist of two ampersands. In addition, the scanner can recognize that an integer may not begin with leading zeros. In both of these cases, the scanner returns an err token with an associated message.
Here is the type of output that should be produced by the scanner for the above test file.
int id main lparen rparen lbrace id x assign num 0 semi id _abc assign num 8 semi if lparen id x err Line 10: missing ampersand in and num 10 rparen write id x semi else semi return err Line 15: integers cannot have leading zeros 0000042 rbrace done
Run handin75 by the end of Monday, Jan. 31 to turn in parts 1-3. Run it again by the end of Monday, Feb. 7 to turn in part 4, the implemented scanner.