From b3f83360282bfe327c0ccbeecab706e0e7d2c050 Mon Sep 17 00:00:00 2001 From: Cori Barker Date: Mon, 9 Feb 2026 11:59:14 +0000 Subject: Changed .h to .hpp --- include/semantic/scope.h | 23 ----------------- include/semantic/scope.hpp | 23 +++++++++++++++++ include/semantic/semantic_analyzer.h | 46 ---------------------------------- include/semantic/semantic_analyzer.hpp | 46 ++++++++++++++++++++++++++++++++++ include/semantic/symbol.h | 38 ---------------------------- include/semantic/symbol.hpp | 38 ++++++++++++++++++++++++++++ include/semantic/symbol_table.h | 25 ------------------ include/semantic/symbol_table.hpp | 25 ++++++++++++++++++ include/semantic/symbol_type.h | 7 ------ include/semantic/symbol_type.hpp | 7 ++++++ 10 files changed, 139 insertions(+), 139 deletions(-) delete mode 100644 include/semantic/scope.h create mode 100644 include/semantic/scope.hpp delete mode 100644 include/semantic/semantic_analyzer.h create mode 100644 include/semantic/semantic_analyzer.hpp delete mode 100644 include/semantic/symbol.h create mode 100644 include/semantic/symbol.hpp delete mode 100644 include/semantic/symbol_table.h create mode 100644 include/semantic/symbol_table.hpp delete mode 100644 include/semantic/symbol_type.h create mode 100644 include/semantic/symbol_type.hpp (limited to 'include/semantic') diff --git a/include/semantic/scope.h b/include/semantic/scope.h deleted file mode 100644 index ff20542..0000000 --- a/include/semantic/scope.h +++ /dev/null @@ -1,23 +0,0 @@ -#pragma once - -#include -#include - -class Scope { -public: - explicit Scope(std::string name, int level, *Scope parent); - std::string getScopeName(); - int getScopeLevel(); - *Scope getParentScope(); - void define(Symbol symbol); - *Symbol lookup(std::string name); - bool isDeclared(std::string name); - std::unordered_map getAllSymbols(); - std::string toString(); - -private: - std::string scope_name; - int scope_level - *Scope parent_scope; - std::unordered_map symbols; -}; diff --git a/include/semantic/scope.hpp b/include/semantic/scope.hpp new file mode 100644 index 0000000..ff20542 --- /dev/null +++ b/include/semantic/scope.hpp @@ -0,0 +1,23 @@ +#pragma once + +#include +#include + +class Scope { +public: + explicit Scope(std::string name, int level, *Scope parent); + std::string getScopeName(); + int getScopeLevel(); + *Scope getParentScope(); + void define(Symbol symbol); + *Symbol lookup(std::string name); + bool isDeclared(std::string name); + std::unordered_map getAllSymbols(); + std::string toString(); + +private: + std::string scope_name; + int scope_level + *Scope parent_scope; + std::unordered_map symbols; +}; diff --git a/include/semantic/semantic_analyzer.h b/include/semantic/semantic_analyzer.h deleted file mode 100644 index 0d56599..0000000 --- a/include/semantic/semantic_analyzer.h +++ /dev/null @@ -1,46 +0,0 @@ -#pragma once - -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; -}; diff --git a/include/semantic/semantic_analyzer.hpp b/include/semantic/semantic_analyzer.hpp new file mode 100644 index 0000000..0d56599 --- /dev/null +++ b/include/semantic/semantic_analyzer.hpp @@ -0,0 +1,46 @@ +#pragma once + +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; +}; diff --git a/include/semantic/symbol.h b/include/semantic/symbol.h deleted file mode 100644 index 94fe918..0000000 --- a/include/semantic/symbol.h +++ /dev/null @@ -1,38 +0,0 @@ -#pragma once - -#include -#include - -#include "symbol_type.h" - -class Symbol { -public: - explicit Symbol(std::string name, SymbolType type, std::string data_type, int scope_level); - std::string getName(); - SymbolType getSymbolType(); - std::string getDataType(); - int getScopeLevel(); - bool isInitialized(); - void setInitialized(bool init); - bool isParameter(); - void setParameter(bool is_param); - std::vector getParameterTypes(); - void setParameterTypes(std::vector types); - std::string getReturnType(); - void setReturnType(std::string type); - int getLineDeclared(); - void setLineDeclared(int line); - std::string toString(); - -private: - std::string symbol_name; - SymbolType symbol_type; - std::string data_type; - int scope_level; - bool is_initialized; - bool is_parameter; - std::vector parameter_types; - std::string return_type; - int line_declared; - int column_declared; -}; diff --git a/include/semantic/symbol.hpp b/include/semantic/symbol.hpp new file mode 100644 index 0000000..4bee45d --- /dev/null +++ b/include/semantic/symbol.hpp @@ -0,0 +1,38 @@ +#pragma once + +#include +#include + +#include "symbol_type.hpp" + +class Symbol { +public: + explicit Symbol(std::string name, SymbolType type, std::string data_type, int scope_level); + std::string getName(); + SymbolType getSymbolType(); + std::string getDataType(); + int getScopeLevel(); + bool isInitialized(); + void setInitialized(bool init); + bool isParameter(); + void setParameter(bool is_param); + std::vector getParameterTypes(); + void setParameterTypes(std::vector types); + std::string getReturnType(); + void setReturnType(std::string type); + int getLineDeclared(); + void setLineDeclared(int line); + std::string toString(); + +private: + std::string symbol_name; + SymbolType symbol_type; + std::string data_type; + int scope_level; + bool is_initialized; + bool is_parameter; + std::vector parameter_types; + std::string return_type; + int line_declared; + int column_declared; +}; diff --git a/include/semantic/symbol_table.h b/include/semantic/symbol_table.h deleted file mode 100644 index b2b8270..0000000 --- a/include/semantic/symbol_table.h +++ /dev/null @@ -1,25 +0,0 @@ -#pragma once - -class SymbolTable { -public: - explicit SymbolTable(); - ~SymbolTable() = default; - void enterScope(std::string scope_name); - void exitScope(); - Scope* getCurrentScope(); - Scope* getGlobalScope(); - int getScopeLevel(); - void insert(Symbol symbol); - Symbol* lookup(std::string name); - Symbol* lookupCurrentScope(std::string name); - bool isDeclared(std::string name); - bool isDeclaredInCurrentScope(std::string name); - void display(); - std::string toString(); - -private: - std::vector> scopes; - Scope* current_scope; - int scope_level; - Scope* global_scope; -}; diff --git a/include/semantic/symbol_table.hpp b/include/semantic/symbol_table.hpp new file mode 100644 index 0000000..b2b8270 --- /dev/null +++ b/include/semantic/symbol_table.hpp @@ -0,0 +1,25 @@ +#pragma once + +class SymbolTable { +public: + explicit SymbolTable(); + ~SymbolTable() = default; + void enterScope(std::string scope_name); + void exitScope(); + Scope* getCurrentScope(); + Scope* getGlobalScope(); + int getScopeLevel(); + void insert(Symbol symbol); + Symbol* lookup(std::string name); + Symbol* lookupCurrentScope(std::string name); + bool isDeclared(std::string name); + bool isDeclaredInCurrentScope(std::string name); + void display(); + std::string toString(); + +private: + std::vector> scopes; + Scope* current_scope; + int scope_level; + Scope* global_scope; +}; diff --git a/include/semantic/symbol_type.h b/include/semantic/symbol_type.h deleted file mode 100644 index a792c09..0000000 --- a/include/semantic/symbol_type.h +++ /dev/null @@ -1,7 +0,0 @@ -#pragma once - -enum class SymbolType { - VARIABLE, - FUNCTION, - PARAMETER, -}; diff --git a/include/semantic/symbol_type.hpp b/include/semantic/symbol_type.hpp new file mode 100644 index 0000000..a792c09 --- /dev/null +++ b/include/semantic/symbol_type.hpp @@ -0,0 +1,7 @@ +#pragma once + +enum class SymbolType { + VARIABLE, + FUNCTION, + PARAMETER, +}; -- cgit v1.2.3