This server is intended for use for Academic Classwork related Git repositories only. Projects/repositories will generally be removed after 6 months following close of the semester. Inactive repositories from previous semester are now being archived when no activity for 365 days. They are renamed and marked as 'archived'. After 90 days in that state they will be removed from the system completely.

SymbolTableEntry.h 1.77 KB
Newer Older
Jonathan Evans's avatar
Jonathan Evans committed
1 2 3 4 5 6
#ifndef SYMBOL_TABLE_ENTRY_H
#define SYMBOL_TABLE_ENTRY_H

#include <string>
using namespace std;

jdev52's avatar
jdev52 committed
7 8 9 10 11 12 13 14 15 16 17 18 19 20
#define UNDEFINED     -1   // Type codes 
#define FUNCTION   8 
#define INT    1 
#define STR    2 
#define INT_OR_STR   3 
#define BOOL    4
#define INT_OR_BOOL  5 
#define STR_OR_BOOL  6 
#define INT_OR_STR_OR_BOOL 7     
#define NOT_APPLICABLE   -1 

#define ARITHMETIC          10
#define LOGICAL             11
#define RELATIONAL          12
Jonathan Evans's avatar
Jonathan Evans committed
21

jdev52's avatar
jdev52 committed
22
typedef struct  
23 24 25
{
    	//value can be int, bool or str not sure how to do this correctly
	int value; //place holder	
jdev52's avatar
jdev52 committed
26
	// one of the above type codes
27 28
	int type;

jdev52's avatar
jdev52 committed
29
	// numParams and returnType only applicable if type == FUNCTION   
30
  	int numParams;  
31 32 33 34
	int returnType;
  
  // operatorType is only applicable if production is an operator 
  int operatorType;   
jdev52's avatar
jdev52 committed
35 36
} TYPE_INFO; 

Jonathan Evans's avatar
Jonathan Evans committed
37 38 39 40 41
class SYMBOL_TABLE_ENTRY 
{
private:
  // Member variables
  string name;
jdev52's avatar
jdev52 committed
42
  TYPE_INFO typeInfo;  
Jonathan Evans's avatar
Jonathan Evans committed
43 44 45

public:
  // Constructors
jdev52's avatar
jdev52 committed
46 47 48 49 50 51
  SYMBOL_TABLE_ENTRY( ) { 
    name = "";
    typeInfo.type = UNDEFINED;
    typeInfo.numParams = UNDEFINED;
    typeInfo.returnType = UNDEFINED;
  }
Jonathan Evans's avatar
Jonathan Evans committed
52

jdev52's avatar
jdev52 committed
53
  SYMBOL_TABLE_ENTRY(const string theName, const TYPE_INFO theType) {
Jonathan Evans's avatar
Jonathan Evans committed
54
    name = theName;
jdev52's avatar
jdev52 committed
55 56 57
    typeInfo.type = theType.type;
    typeInfo.returnType = theType.returnType;
    typeInfo.numParams = theType.numParams;
Jonathan Evans's avatar
Jonathan Evans committed
58 59
  }

60 61 62 63 64 65 66 67
  SYMBOL_TABLE_ENTRY(const string theName, const int type = UNDEFINED,
       const int numParams = UNDEFINED, const int returnType = UNDEFINED){
    name = theName;
    typeInfo.type = type;
    typeInfo.returnType = numParams;
    typeInfo.numParams = returnType;  
  }

Jonathan Evans's avatar
Jonathan Evans committed
68 69
  // Accessors
  string getName() const { return name; }
70
  TYPE_INFO getTypeInfo() const { return typeInfo; }
Jonathan Evans's avatar
Jonathan Evans committed
71 72 73
};

#endif  // SYMBOL_TABLE_ENTRY_H