The first project involves modifying the attached lexical analyzer and the compi
The first project involves modifying the attached lexical analyzer and the compilation listing generator code. You need to make the following modifications to the lexical analyzer, scanner.l:
1. The following reserved words should be added: else, elsif, endfold, endif, fold, if, left, real, right, then Each reserved words should be a separate token. The token name should be the same as the lexeme, but in all upper case.
2. Two additional logical operators should be added. The lexeme for the first should be | and its token should be OROP. The second logical operator added should be ! and its token should be NOTOP.
3. Five relational operators should be added. They are =, <>, >, >= and <=. All of the lexemes should be represented by the single token RELOP.
4. One additional lexeme should be added for the ADDOP token. It is binary operator – that is the subtraction operator.
5. One additional lexeme should be added for the MULOP token. It is/ that is the division operator.
6. A new token REMOP should be added for the remainder operator. Its lexeme should be %.
7. A new token EXPOP should be added for the exponentiation operator. Its lexeme should be ^.
8. A new token NEGOP should be added for the unary minus operator. Its lexeme should be ~.
9. A second type of comment should be added that begins with -- and ends with the end of line. As with the existing comment, no token should be returned.
10. The definition for the identifiers should be modified so that underscores can be included, however, no more than two consecutive underscores are permitted, but leading and trailing underscores should not be permitted.
11. One additional type of integer literal should be added, which are hexadecimal integers. The begin with the # character followed by one of more decimal digits, or the letter A-F, in either upper or lower case.
12. A real literal token should be added. It should begin with a sequence of zero or more digits following by a decimal point followed by one or more additional digits. It may optionally end with an exponent. If present, the exponent should begin with an e or E, followed by an optional plus or minus sign followed by one or more digits.
13. The definition for the character literals should be modified so that five additional escape characters are also allowed: 'b', 't', 'n', 'b' and 'f'.
Leave a Reply