Conversation
Introduce a visitor pattern for semantic analysis and interpretation. Refactor built-in function handling into stdrot.c/h. Add semantic error reporting and test cases for const assignment, function redefinition, scope, and type mismatch errors. Update Makefile and main to support new semantic and interpreter phases. Update expected test results. Signed-off-by: SIGMazer <mazinasd7@gmail.com>
c8a6225 to
9b3b73f
Compare
Member
Member
Closed
Refactor semantic analyzer to use a unified scope-aware symbol table for variable and function declarations. Implement two-phase analysis: first collect declarations, then perform semantic checks with scope tracking. Improve error reporting for undefined variables, out-of-scope access, const assignment, and function redefinition. Update tests to match new error messages and line numbers. Signed-off-by: SIGMazer <mazinasd7@gmail.com>
Remove outdated and redundant comments from semantic analyzer and related code. Simplify phase descriptions and clarify scope handling. This improves readability and maintains semantic analysis logic without functional changes. ``` Signed-off-by: SIGMazer <mazinasd7@gmail.com>
Refactor interpreter to use the visitor pattern for AST execution, replacing direct statement execution in function calls and control flow. Fix double evaluation bugs for increment/decrement and assignment nodes by skipping auto-visits in visitor.c. Improve array access robustness and type handling in ast.c and interpreter.c. Update expected test results for type mismatch and scope errors. Signed-off-by: SIGMazer <mazinasd7@gmail.com>
Refactored interpreter visitor functions to no longer allocate memory for literal and identifier values, as these are only needed for side effects and not expression evaluation. Updated function call and sizeof handling to match this approach. Introduced a global interpreter pointer for cleanup in main and ensured proper freeing in the cleanup routine. Fixed memory leak for string variables in hash map cleanup. Signed-off-by: SIGMazer <mazinasd7@gmail.com>
leo-aa88
approved these changes
Nov 11, 2025
leo-aa88
reviewed
Nov 11, 2025
|
|
||
| yapping("%d", y); 🚽 This should fail - y is out of scope | ||
| bussin 0; | ||
| } No newline at end of file |
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.


Description
This pull request introduces a major refactor to the Brainrot language implementation by adding a visitor-based architecture for semantic analysis and interpretation, as well as support for built-in functions. The changes lay the foundation for improved error reporting, modularity, and extensibility. Additionally, new semantic error test cases are included to validate the enhanced semantic analysis.
Visitor-based architecture and semantic analysis:
semantic_analyzer.hand corresponding visitor implementation, enabling semantic analysis with error reporting, type checking, and scope validation. This includes new error types, error structures, and utility/type-checking functions.lang.yto run semantic analysis after parsing and before execution; execution now only proceeds if semantic analysis passes. Also improved resource cleanup and file handling. [1] [2] [3]Interpreter and execution:
interpreter.handinterpreter.c, implementing a visitor-based interpreter for AST execution, with modular visitor methods for expressions and statements, and support for scope management and return/break flags. [1] [2]ASTNodestruct to include aline_numberfield for precise error reporting during semantic analysis and interpretation.Built-in functions support:
stdrot.hto define and manage built-in Brainrot functions, including function name checks and execution routing for built-in calls.Makefile) to include new source files for visitor, semantic analyzer, interpreter, and built-in functions.Testing and validation:
test_cases/semantic_error_const.brainrot,test_cases/semantic_error_function_redef.brainrot,test_cases/semantic_error_scope.brainrot, andtest_cases/semantic_error_type_mismatch.brainrotto validate the semantic analysis phase. [1] [2] [3] [4]Related Issue
Fixes #18, #139
Type of Change
Checklist