Skip to content

feat: support increment and decrement statements (++/--) - #9

Merged
AdamHameed merged 1 commit into
mainfrom
feature/increment-decrement
Jul 15, 2026
Merged

feat: support increment and decrement statements (++/--)#9
AdamHameed merged 1 commit into
mainfrom
feature/increment-decrement

Conversation

@AdamHameed

Copy link
Copy Markdown
Owner

PR Description

Adds ++ and -- in both prefix and postfix form, valid in statement position and in the for-loop post clause (for (int i = 0; i < n; i++)).

  • Lexer: PlusPlus / MinusMinus tokens.
  • Parser: new parse_assignment_statement entry point (shared with the compound-assignment path from feat: support compound assignment operators (+=, -=, *=, /=, %=) #8) desugars all four forms to x += 1 / x -= 1.
  • Safety: targets are restricted to plain variables with a dedicated InvalidIncrementTarget error. This is deliberate: *p++ in C means *(p++), and since rcc has no pointer arithmetic yet, quietly treating it as (*p)++ would silently diverge from C — so it's a parse error instead.

Tests: lexer distinguishes ++ from + +; parser tests for prefix/postfix desugaring and the *p++ rejection; e2e tests including i++ in for-post. 32 unit + 32 e2e green, verified against clang.

cc @hand-burger

🤖 Generated with Claude Code

- Lexer emits PlusPlus/MinusMinus tokens
- Prefix and postfix forms are accepted in statement position and the
  for-loop post clause, desugared to compound assignment by 1
- Targets are restricted to plain variables with a dedicated
  InvalidIncrementTarget error, so forms like *p++ (whose C semantics
  would be *(p++)) are rejected rather than silently misinterpreted
- Lexer/parser unit tests and e2e coverage; verified against clang

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@AdamHameed
AdamHameed merged commit 1c4ef0b 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