You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
While it is correct that 1 + 2 has to be reduced first, the way the stepper visualizes this contraction by removing parentheses can create confusion to some students as shown in the picture (like why wouldn't 2 * 3 be reduced first due to PEMDAS rule).
On the other hand, the stepper tries to add unnecessary parentheses (as shown in the video).
There might be an issue with parentheses insertion. Hopefully, this will be resolved in a future version of the stepper.
Because the sourceRunner uses the Acorn parser without Parenthesized Expressions to prevent unnecessary parentheses, the current stepper must convert the parsed AST to a string and add parentheses where needed. Readding parenthesized AST might help, but there should be a better solution.
The text was updated successfully, but these errors were encountered:
Yes, there definitely should be a better solution. Basically when unparsing an AST, you need to check if you have a binary operator expression b2 as an operand of another binary operator expression b1. In that case you need to check the position of b2 in b1 and the operators. You need to place parentheses around b2, if the operator of b2 has lower precedence than the operator of b1. If the operators have the same precedence, you may or may not need parentheses, depending on the position of b2 in b1 and the operator associativity.
Similar if you have a binary operator expression b2 as an operand of a unary operator expression b1. (In that case, I think you always need to place parentheses, because unary operators have higher precedence than binary operators.)
Considering the expression
(1 + 2) * (3 + 4)
.While it is correct that
1 + 2
has to be reduced first, the way the stepper visualizes this contraction by removing parentheses can create confusion to some students as shown in the picture (like why wouldn't2 * 3
be reduced first due to PEMDAS rule).On the other hand, the stepper tries to add unnecessary parentheses (as shown in the video).
Source.Academy.Mozilla.Firefox.2025-03-02.21-11-08.mp4
There might be an issue with parentheses insertion. Hopefully, this will be resolved in a future version of the stepper.
Because the sourceRunner uses the Acorn parser without Parenthesized Expressions to prevent unnecessary parentheses, the current stepper must convert the parsed AST to a string and add parentheses where needed. Readding parenthesized AST might help, but there should be a better solution.
The text was updated successfully, but these errors were encountered: