Pr #26 added an int alternation to the exp non-terminal, I don’t think it is correct.
I think I have a solution that doesn’t require the int alternation in the exp non-terminal.
Click here to view my solution. (I am not sure that whether I should put my solution here. But how should I explain myself?)
The idea is that we flatten the expression tree into an addition chain. Then partition the terms in the chain into two groups:
- The group that only contains *int*s.
- The group that only contains `(read)`s and `(- (read))`s.
Each group could be empty. Then we compute the sum of the first group, and add the second group to the result.
The *exp* non-terminal corresponds to the second group in my solution, which doesn’t need *int* alternation since they are all in the first group.
Is there something I missed? Is the int alternation really necessary?
Pr #26 added an int alternation to the exp non-terminal, I don’t think it is correct.
I think I have a solution that doesn’t require the int alternation in the exp non-terminal.
Click here to view my solution. (I am not sure that whether I should put my solution here. But how should I explain myself?)
The idea is that we flatten the expression tree into an addition chain. Then partition the terms in the chain into two groups: - The group that only contains *int*s. - The group that only contains `(read)`s and `(- (read))`s. Each group could be empty. Then we compute the sum of the first group, and add the second group to the result. The *exp* non-terminal corresponds to the second group in my solution, which doesn’t need *int* alternation since they are all in the first group.Is there something I missed? Is the int alternation really necessary?