| # | Problem | Pass Rate (passed user / total user) |
|---|---|---|
| 10469 | hw4 - appendix |
|
| 10474 | problem1 |
|
Description
#include#include #include #include /* Something like Python >> y = 2 >> z = 2 >> x = 3*y + 4/(2*z) */ /* the only type: integer everything is an expression statement := END | expr END expr := term expr_tail expr_tail := ADDSUB term 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 */ #ifndef __LEX__ #define __LEX__ #define MAXLEN 256 typedef enum {UNKNOWN, END, INT, ID, ADDSUB, MULDIV, ASSIGN, LPAREN, RPAREN} TokenSet; char lexeme[MAXLEN]; extern int match (TokenSet token); extern void advance(void); #endif // __LEX__ static TokenSet getToken(void); static TokenSet lookahead = UNKNOWN; TokenSet getToken(void) { int i; char c; while ( (c = fgetc(stdin)) == ' ' || c== '\t' ); // deal with space if (isdigit(c)) { lexeme[0] = c; c = fgetc(stdin); i = 1; while (isdigit(c) && i Input
Output
Sample Input Download
Sample Output Download
Tags
Discuss
Description
Modify the code of ‘calculator.c’ (in 10469) to add the capability of equality and inequality.
The token of equality is set as ‘@’, and that of inequality is ‘#’. If the condition of the expression is correct, the output is 1; otherwise, the output is 0.
For example, if the input is ‘1 + 2 + 3 @ 6 –5’, the output is 0. if the input is ‘1 + 2 + 3 # 6 –5’, the output is 1.
Now there are several expressions, please show the condition of each expression.
Input
The first line gives a number N(N<=10), which means there are N expressions in the input.
The length of each expression is less than 50 and each expression is ended with a new line character.
Output
Show the condition of each expression once in a line.
You are asked to add a new line character at the end.