aboutsummaryrefslogtreecommitdiff
path: root/include/semantic/semantic_analyzer.h
diff options
context:
space:
mode:
authorCori Barker <coribarker2@gmail.com>2026-02-05 09:32:20 +0000
committerCori Barker <coribarker2@gmail.com>2026-02-05 09:32:20 +0000
commitddedc416185954051ff2a826c24fc1cc608204f1 (patch)
tree4dca1a13fc43ab9eb8c415aa116c02c8c543d074 /include/semantic/semantic_analyzer.h
parent44eb8234648bfd6c4607d4fd0d804bbfb9168589 (diff)
Written some class declarations for the semantics, updated README
Diffstat (limited to 'include/semantic/semantic_analyzer.h')
-rw-r--r--include/semantic/semantic_analyzer.h46
1 files changed, 46 insertions, 0 deletions
diff --git a/include/semantic/semantic_analyzer.h b/include/semantic/semantic_analyzer.h
new file mode 100644
index 0000000..0d56599
--- /dev/null
+++ b/include/semantic/semantic_analyzer.h
@@ -0,0 +1,46 @@
+#pragma once
+
+class SemanticAnalyzer {
+public:
+ explicit SemanticAnalyzer();
+ bool analyze(ASTNode* ast);
+ std::vector<Error> getErrors();
+ std::vector<Error> getWarnings();
+ bool hasErrors();
+
+ // Main visitor method
+ std::string visit(ASTNode* ast);
+
+ // Visitor methods for program structure
+ std::string visitProgram(ProgramNode* node);
+ std::string visitFunctionDecl(FunctionDeclNode* node);
+ std::string visitParameter(ParameterNode*);
+
+ // Visitor methods for statements
+ std::string visitVarDeclaration(VarDeclNode* node);
+ std::string visitAssignment(AssignmentNode* node);
+ std::string visitIfStatement(IfStatementNode* node);
+ std::string visitWhileStatement(WhileStatementNode* node);
+ std::string visitForStatement(ForStatementNode* node);
+ std::string visitReturnStatement(ReturnStatementNode* node);
+ std::String visitExpressionStatement(ExpressionStatementNode* node);
+
+ // Visitor methods for expressions
+ std::string visitBinaryExpression(BinaryExprNode* node);
+ std::string visitUnaryExpression(UnaryExprNode* node);
+ std::string visitFunctionCall(FunctionCallNode* node);
+ std::string visitIdentifier(IdentifierNode* node);
+ std::string visitLiteral(LiteralNode* node);
+
+ // Type checking helper methods
+ bool checkTypeCompatibility(std::string target, std::string source);
+ std::string inferBinaryOpType(std::string op, std::string left, std::string right);
+
+private:
+ SymbolTable symbol_table;
+ std::vector<Error> errors;
+ std::vector<Error> warnings;
+ FunctionDeclNode* current_function;
+ std::string current_function_return_type;
+ bool has_main_function;
+};