Brackets Function #25

Open
opened 2025-09-20 13:11:48 +01:00 by Vylpes · 1 comment
Owner

Epic: #21
Story Points:


AS a user, I want expressions with brackets to be evaluated correctly
SO THAT I can control the order of operations in multi-operation expressions

Acceptance Criteria

GIVEN #22 (multiple operations in one expression) is complete
WHEN I evaluate an expression containing brackets in CLI interactive mode
THEN bracketed sub-expressions are solved before the surrounding operations

GIVEN #22 is complete
WHEN I evaluate (2 + 3) * 4
THEN the result is 20

GIVEN #22 is complete
WHEN I evaluate 2 + (3 * 4)
THEN the result is 14

GIVEN #22 is complete
WHEN I evaluate a nested bracketed expression such as ((2 + 3) * 2) - 1
THEN each inner bracketed group is solved before outer operations and the result is 9

GIVEN #22 is complete
WHEN I evaluate an expression with optional spaces such as ( 2 + 3 ) * 4
THEN spaces are ignored and the result matches (2 + 3) * 4

GIVEN #22 is complete
WHEN I evaluate an expression with unclosed or unmatched brackets such as (2 + 3 or 2 + 3) or ((2 + 3)
THEN a clear error message is shown and no result is produced

GIVEN #22 is complete
WHEN I run calculator cli "(2 + 3) * 4" (single-expression mode)
THEN 20 is printed to stdout

GIVEN I am in GUI mode
WHEN I evaluate an expression containing brackets
THEN bracketed sub-expressions are solved before the surrounding operations, consistent with CLI behaviour

Subtasks

  • Extend expression parser to support round brackets ( )
  • Evaluate nested bracketed sub-expressions before outer operations
  • Return a clear error for unclosed or unmatched brackets
  • Add unit tests for bracket evaluation and error cases
  • Enable bracketed expression evaluation in GUI (may require expression-entry support)

Notes

  • Depends on #22 (multiple operations in one expression)
  • Round brackets only; square brackets are out of scope
  • Operator precedence outside brackets follows #22 (left-to-right unless overridden by a future BIDMAS story)
Epic: #21 Story Points: --- AS a user, I want expressions with brackets to be evaluated correctly SO THAT I can control the order of operations in multi-operation expressions ## Acceptance Criteria GIVEN #22 (multiple operations in one expression) is complete WHEN I evaluate an expression containing brackets in CLI interactive mode THEN bracketed sub-expressions are solved before the surrounding operations GIVEN #22 is complete WHEN I evaluate `(2 + 3) * 4` THEN the result is `20` GIVEN #22 is complete WHEN I evaluate `2 + (3 * 4)` THEN the result is `14` GIVEN #22 is complete WHEN I evaluate a nested bracketed expression such as `((2 + 3) * 2) - 1` THEN each inner bracketed group is solved before outer operations and the result is `9` GIVEN #22 is complete WHEN I evaluate an expression with optional spaces such as `( 2 + 3 ) * 4` THEN spaces are ignored and the result matches `(2 + 3) * 4` GIVEN #22 is complete WHEN I evaluate an expression with unclosed or unmatched brackets such as `(2 + 3` or `2 + 3)` or `((2 + 3)` THEN a clear error message is shown and no result is produced GIVEN #22 is complete WHEN I run `calculator cli "(2 + 3) * 4"` (single-expression mode) THEN `20` is printed to stdout GIVEN I am in GUI mode WHEN I evaluate an expression containing brackets THEN bracketed sub-expressions are solved before the surrounding operations, consistent with CLI behaviour ## Subtasks - [ ] Extend expression parser to support round brackets `(` `)` - [ ] Evaluate nested bracketed sub-expressions before outer operations - [ ] Return a clear error for unclosed or unmatched brackets - [ ] Add unit tests for bracket evaluation and error cases - [ ] Enable bracketed expression evaluation in GUI (may require expression-entry support) ## Notes - Depends on #22 (multiple operations in one expression) - Round brackets only; square brackets are out of scope - Operator precedence outside brackets follows #22 (left-to-right unless overridden by a future BIDMAS story)
Vylpes added this to the 0.2.0 milestone 2025-09-20 13:11:48 +01:00
Author
Owner

Blocked by #22

Blocked by #22
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
RabbitLabs/calculator#25
No description provided.