Test output of 03_Precedence is not the same as what is in Readme
vcheckzen opened this issue · 0 comments
vcheckzen commented
What I got
# make test2
cc -o parser2 -g expr2.c interp.c main.c scan.c tree.c
(./parser2 input01; \
./parser2 input02; \
./parser2 input03; \
./parser2 input04; \
./parser2 input05)
15
29
syntax error on line 1, token 1
Unrecognised character . on line 3
Unrecognised character a on line 1
And what is in Readme
Lines 392 to 414 in 14e9397
The parser2's result on input03 is with a wrong token type, it should be 5, not 1. The following is the content of input03
12 34 + -56 * / - - 8 + * 2
Now the parse2 reports error on token +
whose enum value equals 1. It should reports on 34
instead, with enum value 5, because the position of which shoude be an operator.
Lines 96 to 105 in eabf90e
On the preceding code, the operator is checked after parsing the right sub tree. I think the check action should be done first with this code to get a right result.
// Loop working on token at our level of precedence
while (1) {
// Check if the middle position is an operator
int precedence = arithop(tokentype);
// Fetch in the next integer literal
scan(&Token);
// Get the right sub-tree at a higher precedence than us
right = multiplicative_expr();
// Join the two sub-trees with our low-precedence operator
left = mkastnode(precedence, left, right, 0);