aboutsummaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorCori Barker <coribarker2@gmail.com>2026-03-07 18:33:21 +0000
committerCori Barker <coribarker2@gmail.com>2026-03-07 18:33:21 +0000
commit50a51df0404ee4f057fbc19657672d1c7d3eef68 (patch)
tree9cb9ed4572a357448f2b78c4ac0add7eaf6a1e7e /include
parent6761fdd434a7e54551fe28398361f9eed5268406 (diff)
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
Diffstat (limited to 'include')
-rw-r--r--include/ast_node.hpp1
-rw-r--r--include/parser.hpp4
-rw-r--r--include/semantic_analyzer.hpp47
-rw-r--r--include/symbol.hpp11
-rw-r--r--include/symbol_table.hpp12
5 files changed, 20 insertions, 55 deletions
diff --git a/include/ast_node.hpp b/include/ast_node.hpp
index 96300c2..4484959 100644
--- a/include/ast_node.hpp
+++ b/include/ast_node.hpp
@@ -1,6 +1,5 @@
#pragma once
-#include "node_type.hpp"
#include "type.hpp"
#include <string>
diff --git a/include/parser.hpp b/include/parser.hpp
index f986ce2..6ec505e 100644
--- a/include/parser.hpp
+++ b/include/parser.hpp
@@ -1,7 +1,7 @@
#pragma once
-#include "lexer/token.hpp"
-#include "parser/ast_node.hpp"
+#include "token.hpp"
+#include "ast_node.hpp"
#include <vector>
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 <string>
-#include <vector>
+#include "symbol_table.hpp"
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;
+ Scope* current_scope;
+ int current_scope_level;
};
-
-
-SemanticAnalyzer::SemanticAnalyzer() : symbol_table(), errors(), warnings(), current_function(nullptr), current_function_return_type(), has_main_functions(false) { }
diff --git a/include/symbol.hpp b/include/symbol.hpp
index c3c7ef4..a388f04 100644
--- a/include/symbol.hpp
+++ b/include/symbol.hpp
@@ -1,13 +1,18 @@
#pragma once
+#include "symbol_type.hpp"
+#include "type.hpp"
+
+#include <variant>
+#include <string>
+
class Symbol {
public:
explicit Symbol();
private:
std::string identifier;
- Type type;
+
+ SymbolType symbol_type;
std::variant<int, bool, std::string> value;
};
-
-Symbol::Symbol(std::string identifier, Type type, std::variant<int, bool, std::string> value) : identifier(identifier), type(type), value(value) { }
diff --git a/include/symbol_table.hpp b/include/symbol_table.hpp
index 55de65a..42c6cd7 100644
--- a/include/symbol_table.hpp
+++ b/include/symbol_table.hpp
@@ -1,12 +1,14 @@
#pragma once
+#include "scope.hpp"
+
+#include <vector>
+
class SymbolTable {
public:
-
+ explicit SymbolTable();
+ void addScope(Scope* scope);
private:
- std::vector<Scope> scopes;
- Scope* current_scope;
-
-
+ std::vector<Scope*> scopes;
};