Support parenthesized sub-expressions - #5
Conversation
( and ) group terms and override operator precedence. "(" only opens
a fresh group -- at the start, after an operator, or after another
"(" -- and is otherwise ignored rather than guessing at an implied
operator; two groups need an explicit operator between them.
Evaluation moves from a flat multiply-then-add fold to a small
recursive-descent parser so nested groups compute correctly.
Co-authored-by: Cursor <cursoragent@cursor.com>
pressOperator already turns a leading operator at the top of the line into an implicit zero, so "- 3 + 4 =" gives 1. That branch only fired on an empty token list, so the same keys inside a group fell through to the plain append, put an operator first in the group, and parseFactor rejected it: "( - 3 + 4 ) =" gave Error, and so did the "( - 1 + 4 )" half of a longer expression. The ± key was the only way to enter a negative operand inside parentheses. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
|
Reviewed this against I pushed one fix, 1fa9f8a. Four things I did not touch, because they are all one design question —
Two smaller notes. |
Eg: (2 + 3) × 4 gives 20