Project 2 - For Statement#6
Open
Mend25 wants to merge 4 commits into
Open
Conversation
- Added a new `Statement::For` variant to the AST for three-part `for` loops. - Implemented a parser for `for` statements, allowing declaration or assignment in the initialization clause and requiring a block body. - Updated the statement dispatcher to recognize `for` before other statements. - Reserved the `for` keyword to prevent its use as an identifier. - Added integration tests covering various `for` statement scenarios, including valid and invalid forms. This change lays the groundwork for future type checking and execution semantics in subsequent milestones.
- Added multiple tests to validate the parser's handling of `for` statements, including checks for empty clauses and complex conditions. - Introduced a new fixture file `parser_for_loop.minic` to test a complete program with a `for` loop. - Updated existing tests to ensure correct parsing and structure of `for` statements within various contexts, such as inside `while` loops and with return statements. These enhancements improve the robustness of the parser and ensure compliance with the defined language specifications.
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.
Grupo
Summary
Introduce full syntactic support for C-style
forloops in the MiniC language, including AST integration, parser support for optional header clauses, keyword reservation, and supporting documentation/specification.This PR implements the
forconstruct at the parsing level, adding end-to-end syntactic support in MiniC through a newStatement::ForAST variant and parser logic capable of handling optional initialization, condition, and update clauses. It also reservesforas a language keyword to prevent identifier conflicts.Type checking and interpretation for
forloops are intentionally left unimplemented at this stage, with explicit errors added to make that limitation clear until Milestone 2. In addition, the PR includes detailed design documentation, requirements, scenarios, and task breakdowns, while remaining fully backward compatible with the existing language.Changes Made
AST (
ast.rs)Statement::For { init, cond, update, body }variantforloop with:Parser (
statements.rs)Add parsing support for C-style
forstatementsSupported syntax:
for (init; cond; update) blockHeader clause rules:
initis optionalcondis optionalupdateis optionalAdd helper parsers for:
Update statement dispatch order so
for_statementis parsed before declaration and assignmentUpdate grammar documentation and parser comments to reflect the new syntax
Language Rules
foras a keywordforfrom being used as an identifierSpecification, Design & Planning
openspecdocumentation covering:Tooling / Infra
flake.nixto simplify the dev shell definition