-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSymTab.cpp
More file actions
116 lines (78 loc) · 2.3 KB
/
Copy pathSymTab.cpp
File metadata and controls
116 lines (78 loc) · 2.3 KB
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
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
//
// Implementation of the symbol table class. This is the format I want for commenting functions.
//
#include "stdafx.h"
#include "SymTab.h"
#include "Errors.h"
/**/
/*
AddSymbol()
NAME
AddSymbol() - Adds a symbol to the SymbolTable
SYNOPSIS
void SymbolTable::AddSymbol( const string &a_symbol, int a_loc );
a_symbol --> a string holding the label
a_loc --> integer holding the location of symbol
DESCRIPTION
This function will check if a symbol is already in the table, and then
if it is, the function will set the location of that symbol as -999.
If the symbol is not currently in the table, it will be added into
the symbol Table
RETURNS
Returns void
AUTHOR
Victor Miller
DATE
4:19pm 12/19/2021
*/
/**/
void SymbolTable::AddSymbol( const string &a_symbol, int a_loc )
{
// If the symbol is already in the symbol table, record it as multiply defined.
map<string, int>::iterator st = m_symbolTable.find( a_symbol );
if( st != m_symbolTable.end() ) {
st->second = multiplyDefinedSymbol; // sets location of symbol to -999
string currError = "Multiply Defined symbol: ";
cout << currError << a_symbol << endl;
Errors::RecordError(currError);
return;
}
// Record a the location in the symbol table.
m_symbolTable[a_symbol] = a_loc;
}
/**/
/*
DisplaySymbolTable()
NAME
DisplaySymbolTable() - Displays symbol Table
SYNOPSIS
void SymbolTable::DisplaySymbolTable();
DESCRIPTION
This function will display the symbol Table with header.
RETURNS
Returns void
AUTHOR
Ryan Garaffa
DATE
4:19pm 12/19/2021
*/
/**/
void SymbolTable::DisplaySymbolTable() {
cout << "SYMBOL TABLE:" << endl;
cout << "Symbol # " << "Symbol " << " Location" << endl;
counter = 0;
//create iterator to display symboltable
map<string, int>::const_iterator it = m_symbolTable.begin();
while(it != m_symbolTable.end()) {
cout << counter << " " << it->first << " " << it->second << endl;
it++;
counter++;
}
cout << endl << "Type anything to Continue" << endl;
string enterToContinue;
cin >> enterToContinue;
}
//Briefly called in AddSymbol() function
bool SymbolTable::LookupSymbol(const string &a_symbol, int &a_loc) {
return true;
}