Modify the code of ‘calculator.c’ (in 10469) to add two new capabilities.
1. The capability of modulo operation ‘%’. You can add this feature in MULDIV, by jointly checking the token with the existing ones of multiplication and division.
For example, if the input is ‘4*7 % 5’, the output is 3. If the input is ‘3 + 8 % 5’, the output is 6
You need to
(1) Add code dealing with ‘%’ in getToken().
(2) Add the evaluation of ‘%’ in term().
2. The capability of less than ‘<’ and greater than ‘>’
You need to
(1) Add a new token in TokenSet, named LTGT a.k.a. less than or greater than.
(2) In getToken(), add code to bind the input of ‘>’ and ‘<’ with LTGT.
(3) Change some parts of the grammar as follows:
statement := END | expr END
expr := add_expr expr_tail
expr_tail := LTGT add_expr expr_tail | NIL
add_expr := term add_expr_tail
add_expr_tail := ADDSUB term add_expr_tail | NIL
term := factor term_tail
term_tail := MULDIV factor term_tail | NIL
factor := INT | ADDSUB INT | ADDSUB ID | ID ASSIGN expr | ID | LPAREN expr RPAREN
The previous expression of ADDSUB is lowered by one level and changed its name to add_expr. Meanwhile, expr is used for dealing with LTGT.
When the algorithm is done, the program should be able to deal with the conditions of LTGT. If the condition of ‘less than’ (or ‘greater than’) is true, the output is 1; otherwise the output is 0.
For example, if the input is ‘1 + 2 > 2’, the output is 1. If the input is ‘5 + 4 < 3’, the output is 0.
One expression which is ended with new line character.
The answer of input expression. You are asked to add the new line character in the end.