feat: support increment and decrement statements (++/--) - #9
Merged
Conversation
- 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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
PR Description
Adds
++and--in both prefix and postfix form, valid in statement position and in thefor-loop post clause (for (int i = 0; i < n; i++)).PlusPlus/MinusMinustokens.parse_assignment_statemententry point (shared with the compound-assignment path from feat: support compound assignment operators (+=, -=, *=, /=, %=) #8) desugars all four forms tox += 1/x -= 1.InvalidIncrementTargeterror. 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 includingi++in for-post. 32 unit + 32 e2e green, verified against clang.cc @hand-burger
🤖 Generated with Claude Code