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.

SymbolTable.h 1.56 KB
Newer Older
Jonathan Evans's avatar
Jonathan Evans committed
1 2 3 4 5 6 7 8 9
#ifndef SYMBOL_TABLE_H
#define SYMBOL_TABLE_H

#include <map>
#include <string>
#include <iostream>
#include "SymbolTableEntry.h"
using namespace std;

Hogan's avatar
Hogan committed
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
#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 
 
typedef struct  
{    
	int type;
	// one of the above type codes
    int numParams;  
	// numParams and returnType only applicable if type == FUNCTION   
	int returnType;       
} TYPE_INFO; 

Jonathan Evans's avatar
Jonathan Evans committed
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66
class SYMBOL_TABLE 
{
private:
  std::map<string, SYMBOL_TABLE_ENTRY> hashTable;

public:
  //Constructor
  SYMBOL_TABLE( ) { }

  // Add SYMBOL_TABLE_ENTRY x to this symbol table.
  // If successful, return true; otherwise, return false.
  bool addEntry(SYMBOL_TABLE_ENTRY x) 
  {
    // Make sure there isn't already an entry with the same name
    map<string, SYMBOL_TABLE_ENTRY>::iterator itr;
    if ((itr = hashTable.find(x.getName())) == hashTable.end()) 
    {
      hashTable.insert(make_pair(x.getName(), x));
      return(true);
    }
    else return(false);
  }

  // If a SYMBOL_TABLE_ENTRY with name theName is
  // found in this symbol table, then return true;
  // otherwise, return false.
  bool findEntry(string theName) 
  {
    map<string, SYMBOL_TABLE_ENTRY>::iterator itr;
    if ((itr = hashTable.find(theName)) == hashTable.end())
      return(false);
    else return(true);
  }

};

#endif  // SYMBOL_TABLE_H