Implement block scopes and control flow statements (if/else, while, and for loops)#5
Open
hand-burger wants to merge 6 commits into
Open
Implement block scopes and control flow statements (if/else, while, and for loops)#5hand-burger wants to merge 6 commits into
hand-burger wants to merge 6 commits into
Conversation
… and add CI workflow
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.
Summary
This PR adds support for block scopes and control flow statements in the RCC compiler. It introduces nested block statements ( { ... } ), if / else conditionals, while loops, and C-style for loops.
Changes
• Added tokenization support for the new keywords: if , else , while , and for .
• Extended the Statement AST enum with Block , If , While , and For variants.
• Implemented recursive parsing of block statements containing lists of nested statements.
• Added parser support for conditional constructs: if (cond) stmt else stmt .
• Added parser support for loops: while (cond) stmt and for (init; cond; post) stmt .
• Redesigned the variable mapping system from a flat table to a vector stack representing block-local scopes to correctly support block-level lexical scoping.
• Migrated code generation to a single-exit function design with a return_bb basic block, avoiding duplicate terminator instructions inside branches and loops.
• Implemented basic block routing and branch logic for if / else , while loops, and for loops.
• Fixed a nested if warning in src/main.rs to satisfy Clippy CI checks.
• Adjusted codegen unit test assertions to match the single-exit block generation style.
• Added end-to-end integration tests verifying block scoping, if / else evaluation, while loop iteration, for loop step execution, and deeply nested loops and conditionals.