Implement goto statement and labeled statements - #115
Merged
Conversation
- Add GotoStatement and LabeledStatement AST nodes - Add grammar actions in CParser.jay for both rules - Add function-scoped label registry in FunctionContext - Add ResolveGotoLabel/DefineGotoLabel methods to EmitContext - Add CheckLabels validation after function compilation - Add GotoTests with 9 test cases (forward, backward, nested, errors) - Update AGENTS.md to remove "No goto" limitation Agent-Logs-Url: https://github.com/praeclarum/CLanguage/sessions/ba96b912-1cf8-4ca6-99e6-532546744425 Co-authored-by: praeclarum <323548+praeclarum@users.noreply.github.com>
Agent-Logs-Url: https://github.com/praeclarum/CLanguage/sessions/ba96b912-1cf8-4ca6-99e6-532546744425 Co-authored-by: praeclarum <323548+praeclarum@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Implement goto statement in C parser
Implement goto statement and labeled statements
Mar 31, 2026
praeclarum
marked this pull request as ready for review
March 31, 2026 21:23
praeclarum
approved these changes
Mar 31, 2026
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.
gotowas parsed by the grammar but had no action code — no AST nodes were created. Labeled statements (label:) were similarly unimplemented.Changes
GotoStatementemitsJumpto a resolved label;LabeledStatementdefines a label and wraps the subsequent statementCParser.jayforGOTO IDENTIFIER ';'andIDENTIFIER ':' statementDictionary<string, Label>inFunctionContext. Both goto and label definitions resolve throughResolveGotoLabel/DefineGotoLabelonEmitContext, so forward references work naturally via sharedLabelobjects.CheckLabels()after function emission reports undefined labels (error 9999) and duplicate labels (error 140)goto" from Known LimitationsExample
Tests
9 cases: forward goto, backward goto, multi-label chains, nested block jumps, loop breakout, and error cases for undefined/duplicate labels.