CPSC 371: Assignment for 1/26/99. Due next Tuesday. Preliminaries: You need to download and install the JLex and Java_Cup programs. You also should download the "Tiger Compiler Modules." All these are available from the textbook's homepage. 1. Do the problem described on page 34 of the text. That is, write the lexical analyzer portion of your compiler. Be sure to use the java_cup.runtime.Symbol class and the 'sym' class already provided. You may find the Tiger.lex file helpful, but if I were you I wouldn't start right away with that. Study that file as well as the sample .lex file I have provided to decide the best way to proceed. Demonstrate your program on some of the sample "tiger" programs. Look at the Parse/Main.java file to see how to use the lexer produced by JLex. Note that you will be required to handle comments (including nested comments) in your lexer. For this you might want to refer to the sample.lex file that came as part of the JLex package. 2. Part two of this week's assignment asks you to solve the following problem: Many programming languages have two forms of conditional statements: 'if-then' statements and 'if-then-else' statements. Consider the following naive grammar for specifying these statements: Stmt ::= if Expr then Stmt | if Expr then Stmt else Stmt | Otherstmts; Here, Expr is naturally meant to be the non-terminal associated with (boolean) expressions and Stmt with statements. "Otherstmts" is meant to produce other types of statments. Consider the following statement: ____________ if A then if B then C; else D; -------------------- The lines above and below the statment represent two distinct ways to parse this string according to the grammar above: it's ambiguous. You are asked to rewrite the grammar to eliminate this ambiguity by always matching each 'else' statement with the *nearest* 'if' statement. That is, the above expression should be interpreted as if it were the same as: if A then { if B then C; else D; } Make sure your grammar does not produce other ambiguities. Keep it simple (no page-long grammars please!)