Skip to content

Fix #1029: correct left-associativity for arithmetic operators#1069

Merged
facontidavide merged 1 commit intomasterfrom
fix/issue-1029
Feb 1, 2026
Merged

Fix #1029: correct left-associativity for arithmetic operators#1069
facontidavide merged 1 commit intomasterfrom
fix/issue-1029

Conversation

@facontidavide
Copy link
Collaborator

@facontidavide facontidavide commented Feb 1, 2026

Summary

  • Fix left-to-right associativity for +, -, *, / operators in the script parser
  • A - B + C was incorrectly evaluated as A - (B + C) due to conflicting binding power levels in lexy's operation list
  • Adds regression tests for arithmetic associativity

Test plan

  • New test: ScriptParser.Associativity_Issue1029
  • All existing tests pass (298/298)

Closes #1029

Summary by CodeRabbit

  • Bug Fixes

    • Fixed operator associativity handling in scripting, resolving precedence conflicts with string concatenation and arithmetic operations.
  • Tests

    • Added test suite validating left-associativity for arithmetic and string operations (Issue1029).

✏️ Tip: You can customize this high-level summary in your review settings.

…ipt parser

The scripting engine evaluated "A - B + C" as "A - (B + C)" instead of
"(A - B) + C". The root cause was that string_concat's operand chain
referenced math_sum, causing it to appear twice in lexy's operation list
with conflicting binding power levels. Changed string_concat::operand
from math_sum to math_prefix to eliminate the duplicate entry.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@coderabbitai
Copy link

coderabbitai bot commented Feb 1, 2026

Caution

Review failed

The pull request is closed.

📝 Walkthrough

Walkthrough

A targeted fix to the scripting operator grammar where string_concat's operand type is changed from math_sum to math_prefix to correct left-associativity behavior in arithmetic expressions, accompanied by test coverage validating operator precedence and associativity.

Changes

Cohort / File(s) Summary
Operator Grammar Fix
include/behaviortree_cpp/scripting/operators.hpp
Changed operand type in string_concat struct from math_sum to math_prefix to correct associativity binding chain and resolve operator precedence conflicts.
Operator Associativity Tests
tests/script_parser_test.cpp
Added comprehensive test case OperatorAssociativity_Issue1029 with assertions validating left-associativity for arithmetic operations (addition/subtraction, multiplication/division), mixed precedence evaluation, and string concatenation behavior.

Estimated Code Review Effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Poem

🐰 Hops of joy, the order's right!
No more math that gives a fright,
A minus B plus C now flows,
Associativity clearly shows,
Grammar fixed with one small change

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix/issue-1029

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@facontidavide facontidavide merged commit 51df1e0 into master Feb 1, 2026
11 of 12 checks passed
@facontidavide facontidavide deleted the fix/issue-1029 branch February 1, 2026 17:29
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.

Mathematical order of opperations in script is wrong

1 participant