aboutsummaryrefslogtreecommitdiff
path: root/include/semantic
diff options
context:
space:
mode:
authorCori Barker <coribarker2@gmail.com>2026-02-22 22:24:27 +0000
committerCori Barker <coribarker2@gmail.com>2026-02-22 22:24:27 +0000
commit5c1f937a7eb7a9cc9cd86cb69b3263f41f24408f (patch)
tree46154166a56f9a074c5b75dbb1a1b9560908b8f1 /include/semantic
parent2cfc45ff22cd9b6166de3cf963aceede21b358aa (diff)
Partially completed lots of changes, refactoring most of the files
Diffstat (limited to 'include/semantic')
-rw-r--r--include/semantic/scope.hpp23
-rw-r--r--include/semantic/semantic_analyzer.hpp46
-rw-r--r--include/semantic/symbol.hpp38
-rw-r--r--include/semantic/symbol_table.hpp25
-rw-r--r--include/semantic/symbol_type.hpp7
5 files changed, 0 insertions, 139 deletions
diff --git a/include/semantic/scope.hpp b/include/semantic/scope.hpp
deleted file mode 100644
index ff20542..0000000
--- a/include/semantic/scope.hpp
+++ /dev/null
@@ -1,23 +0,0 @@
-#pragma once
-
-#include <string>
-#include <memory>
-
-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<std::string, Symbol> getAllSymbols();
- std::string toString();
-
-private:
- std::string scope_name;
- int scope_level
- *Scope parent_scope;
- std::unordered_map<std::string, Symbol> symbols;
-};
diff --git a/include/semantic/semantic_analyzer.hpp b/include/semantic/semantic_analyzer.hpp
deleted file mode 100644
index 0d56599..0000000
--- a/include/semantic/semantic_analyzer.hpp
+++ /dev/null
@@ -1,46 +0,0 @@
-#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;
-};
diff --git a/include/semantic/symbol.hpp b/include/semantic/symbol.hpp
deleted file mode 100644
index 4bee45d..0000000
--- a/include/semantic/symbol.hpp
+++ /dev/null
@@ -1,38 +0,0 @@
-#pragma once
-
-#include <string>
-#include <vector>
-
-#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<std::string> getParameterTypes();
- void setParameterTypes(std::vector<std::string> 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<std::string> parameter_types;
- std::string return_type;
- int line_declared;
- int column_declared;
-};
diff --git a/include/semantic/symbol_table.hpp b/include/semantic/symbol_table.hpp
deleted file mode 100644
index b2b8270..0000000
--- a/include/semantic/symbol_table.hpp
+++ /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<std::unique_ptr<Scope>> scopes;
- Scope* current_scope;
- int scope_level;
- Scope* global_scope;
-};
diff --git a/include/semantic/symbol_type.hpp b/include/semantic/symbol_type.hpp
deleted file mode 100644
index a792c09..0000000
--- a/include/semantic/symbol_type.hpp
+++ /dev/null
@@ -1,7 +0,0 @@
-#pragma once
-
-enum class SymbolType {
- VARIABLE,
- FUNCTION,
- PARAMETER,
-};