Skip to content

Conversation

lwgray
Copy link
Owner

@lwgray lwgray commented Dec 9, 2024

Parser Improvements for Expressions

This PR fixes issues with parsing parenthesized expressions and unary operations, while adding comprehensive test coverage for expression evaluation.

Changes

Parser Updates

  • Added explicit handling of parenthesized expressions in grammar rules
  • Fixed unary minus operation handling
  • Simplified primary expression rules
  • Improved operator precedence handling

Interpreter Updates

  • Added dedicated handling for unary minus operations in evaluate_operation
  • Modified operation evaluation to check operator type before accessing operands

New Tests

Added TestExpressionEvaluation class with test cases for:

  • Basic parenthesized expressions (e.g., 2 * (3 + 4))
  • Nested unary operations (e.g., - -42)
  • Complex nested expressions (e.g., (a + b) * (c - d))
  • Proper operator precedence

Testing

All tests pass, including new test cases that verify:

  • Correct evaluation of basic arithmetic with parentheses
  • Proper handling of unary minus operations
  • Complex nested expressions with multiple operators
  • Operator precedence rules

Notes for Reviewers

Key areas to review:

  1. Grammar rule changes in parser.py
  2. Unary operation handling in interpreter.py
  3. Comprehensive test coverage in test_integration.py

…perations

- Fix parsing of basic parenthesized expressions like '2 * (3 + 4)'
- Add proper handling of unary minus operations
- Update grammar rules to maintain correct operator precedence
- Add comprehensive tests for expression evaluation

Key changes:
- Add LPAREN expression RPAREN to expression rule
- Simplify primary_expr rule and fix handling of parentheses
- Add dedicated uminus handling in evaluate_operation
- Add TestExpressionEvaluation class with test cases for:
  - Nested unary operations
  - Complex nested expressions
  - Parenthesized expressions
  - Operator precedence
@lwgray lwgray self-assigned this Dec 9, 2024
@lwgray lwgray merged commit e75cf13 into develop Dec 9, 2024
3 checks passed
@lwgray lwgray deleted the new_tests branch December 9, 2024 17:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant