From 32a1609b59fcbbfe24e223c078d51f8bfa08566f Mon Sep 17 00:00:00 2001 From: Cori Barker Date: Tue, 10 Mar 2026 22:53:50 +0000 Subject: continued development of the semantic analyzer and symbol table generation --- include/scope.hpp | 1 + include/symbol.hpp | 26 ++++++++++++-------------- include/type.hpp | 24 ------------------------ 3 files changed, 13 insertions(+), 38 deletions(-) (limited to 'include') diff --git a/include/scope.hpp b/include/scope.hpp index 69c70f6..4c90813 100644 --- a/include/scope.hpp +++ b/include/scope.hpp @@ -4,6 +4,7 @@ class Scope { public: explicit Scope(int scope_level); + add symbol private: std::vector symbols; int scope_level; diff --git a/include/symbol.hpp b/include/symbol.hpp index d7be206..9b48a0a 100644 --- a/include/symbol.hpp +++ b/include/symbol.hpp @@ -1,30 +1,28 @@ #pragma once -#include "symbol_type.hpp" #include "type.hpp" #include #include #include +enum SymbolType { + VARIABLE, + FUNCTION, +}; + class Symbol { public: std::string identifier; + SymbolType symbol_type; + Type data_type; + Type return_type; + std::vector parameter_identifiers; + std::vector parameter_types; int line; int column; - virtual ~Symbol() = default; -}; - -class FunctionDeclarationSymbol : public Symbol { - Type return_type; - std::vector parameters; - - FunctionDeclarationSymbol(std::string identifier, Type return_type, std::vector parameters, int line, int column) : identifier(identifier), return_type(return_type), parameters(parameters), line(line), column(column) { } -}; - -class VariableDeclarationSymbol : public Symbol { - Type type; + Symbol(std::string identifier, Type data_type, int line, int column) : identifier(identifier), data_type(data_type), line(line), column(column), symbol_type(SymbolType::VARIABLE) { } - VariableDeclarationSymbol + Symbol(std::string identifier, Type return_type, std::vector parameter_identifiers, std::vector parameter_types, int line, int column) : identifier(identifier), data_type(data_type), return_type(return_type), parameter_identifiers(parameter_identifiers), parameter_types(parameter_types), line(line), column(column), symbol_type(SymbolType::FUNCTION) { } }; diff --git a/include/type.hpp b/include/type.hpp index 9b25d24..1726764 100644 --- a/include/type.hpp +++ b/include/type.hpp @@ -8,28 +8,4 @@ enum struct TypeKind { FLOAT, DOUBLE, VOID, - FUNCTION, -}; - -struct Type { - TypeKind kind; - - Type* return_type = nullptr; - std::vector param_types; - - static Type makeInt() { return { TypeKind::INT }; } - static Type makeChar() { return { TypeKind::CHAR }; } - static Type makeBool() { return { TypeKind::BOOL }; } - static Type makeString() { return { TypeKind::STRING }; } - static Type makeFloat() { return { TypeKind::FLOAT }; } - static Type makeDouble() { return { TypeKind::DOUBLE }; } - static Type makeVoid() { return { TypeKind::VOID }; } - - static Type makeFunction(Type* return_type, std::vector param_types) { - Type t; - t.kind = TypeKind::FUNCTION; - t.return_type = return_type; - t.param_types = std::move(param_types); - return t; - }; }; -- cgit v1.2.3