From 08d574d88cf47fd87b4de1db12d52483d0d13374 Mon Sep 17 00:00:00 2001 From: Jonathan Evans Date: Wed, 8 Apr 2020 17:55:34 +0000 Subject: [PATCH] changed valuetype to support various types --- SymbolTable.h | 2 -- SymbolTableEntry.h | 35 ++++++++++++++++++++++++++++++----- 2 files changed, 30 insertions(+), 7 deletions(-) diff --git a/SymbolTable.h b/SymbolTable.h index 30df58a..8ba3dca 100644 --- a/SymbolTable.h +++ b/SymbolTable.h @@ -7,8 +7,6 @@ #include "SymbolTableEntry.h" using namespace std; - - class SYMBOL_TABLE { private: diff --git a/SymbolTableEntry.h b/SymbolTableEntry.h index 1b579a3..1a7bab7 100644 --- a/SymbolTableEntry.h +++ b/SymbolTableEntry.h @@ -2,6 +2,8 @@ #define SYMBOL_TABLE_ENTRY_H #include +#include +#include using namespace std; #define UNDEFINED -1 // Type codes @@ -19,20 +21,43 @@ using namespace std; #define LOGICAL 11 #define RELATIONAL 12 -typedef struct +union TYPE_VALUE{ + char* text; + bool boolean; + int number; +}; + +struct TYPE_INFO { - //value can be int, bool or str not sure how to do this correctly - int value; //place holder + TYPE_VALUE value; + // one of the above type codes int type; // numParams and returnType only applicable if type == FUNCTION - int numParams; + int numParams; int returnType; // operatorType is only applicable if production is an operator int operatorType; -} TYPE_INFO; + + friend ostream& operator<<(ostream& os, const TYPE_INFO& rhs){ + switch(rhs.type){ + case INT: + os << rhs.value.number; + break; + case STR: + os << rhs.value.text; + break; + case BOOL: + os << rhs.value.boolean; + break; + default: + throw std::invalid_argument("invalid type at print"); + } + return os; + } +}; class SYMBOL_TABLE_ENTRY { -- GitLab