-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsymtab.cpp
More file actions
32 lines (26 loc) · 719 Bytes
/
symtab.cpp
File metadata and controls
32 lines (26 loc) · 719 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#include <map>
#include <string>
#include "symtab.h"
static
std::map<std::string, myType> symbolTable;
// returns the type of the identifier
// returns UNKOWN when the identifier is not in the symbol table
myType getSymbol (const char *name)
{
std::string theName = name;
std::map<std::string, myType>::iterator it;
it = symbolTable.find (theName);
if (it == symbolTable.end())
return UNKNOWN;
return it->second;
}
// return value: 0 if name already exists in symboltable
// otherwise returns 1
int putSymbol (const char *name, myType type)
{
std::string theName = name;
if (symbolTable.count (name))
return 0;
symbolTable [theName] = type;
return 1;
}