Skip to content

feat: support compound assignment operators (+=, -=, *=, /=, %=) - #8

Merged
AdamHameed merged 1 commit into
mainfrom
feature/compound-assignment
Jul 15, 2026
Merged

feat: support compound assignment operators (+=, -=, *=, /=, %=)#8
AdamHameed merged 1 commit into
mainfrom
feature/compound-assignment

Conversation

@AdamHameed

Copy link
Copy Markdown
Owner

PR Description

Adds C compound assignment operators: +=, -=, *=, /=, %=.

  • Lexer: new PlusEqual/MinusEqual/StarEqual/SlashEqual/PercentEqual tokens (one-character lookahead in the existing operator arms).
  • AST/Parser: VarAssignStatement now carries op: Option<BinaryOp> (None for plain =). The = / op= tail parsing is factored into a shared parse_assignment helper used by both statement position and the for-loop post clause, so for (...; ...; i += 1) works.
  • Codegen: emits the lvalue address once, then load → apply → store for compound ops (works through pointer targets like *p += 2); compound assignment is type-checked to int targets.

Tests: lexer + parser unit tests and 3 e2e tests (all five operators chained, compound assignment through a pointer, compound assignment in for-post). Suite is 29 unit + 30 e2e green, clippy/fmt clean, and the behavior is differentially verified against clang.

cc @hand-burger — this is the compound-assignment follow-up mentioned on #7; ++/-- coming next on top of this.

🤖 Generated with Claude Code

- Lexer emits PlusEqual/MinusEqual/StarEqual/SlashEqual/PercentEqual
- VarAssignStatement carries an optional compound BinaryOp; parsing is
  shared between statement position and for-loop post expressions
- Codegen emits the lvalue once, then load-apply-store for compound ops,
  restricted to int targets
- Unit tests for lexing/parsing plus e2e tests including compound
  assignment through a pointer and in for-post; verified against clang

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@AdamHameed
AdamHameed merged commit d57e599 into main Jul 15, 2026
1 check passed
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