From 50a51df0404ee4f057fbc19657672d1c7d3eef68 Mon Sep 17 00:00:00 2001 From: Cori Barker Date: Sat, 7 Mar 2026 18:33:21 +0000 Subject: removed implementations of symbol table related classes, need to fix the parser to use the new AST node classes then i can write the symbol table classes and refactor the lexer and parser to use the symbol table --- include/semantic_analyzer.hpp | 47 +++---------------------------------------- 1 file changed, 3 insertions(+), 44 deletions(-) (limited to 'include/semantic_analyzer.hpp') diff --git a/include/semantic_analyzer.hpp b/include/semantic_analyzer.hpp index 630a267..ec1e4a1 100644 --- a/include/semantic_analyzer.hpp +++ b/include/semantic_analyzer.hpp @@ -1,54 +1,13 @@ #pragma once -#include "ast_node.hpp" - -#include -#include +#include "symbol_table.hpp" class SemanticAnalyzer { public: explicit SemanticAnalyzer(); - bool analyze(ASTNode* ast); - std::vector getErrors(); - std::vector 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 errors; - std::vector warnings; - FunctionDeclNode* current_function; - std::string current_function_return_type; - bool has_main_function; + Scope* current_scope; + int current_scope_level; }; - - -SemanticAnalyzer::SemanticAnalyzer() : symbol_table(), errors(), warnings(), current_function(nullptr), current_function_return_type(), has_main_functions(false) { } -- cgit v1.2.3