-
Notifications
You must be signed in to change notification settings - Fork 0
/
dataStructures.c
52 lines (41 loc) · 1.32 KB
/
dataStructures.c
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
#include "dataStructures.h"
/*
Searches for a symbol with the given name in the global Table, starting from symbolTableHead.
Input: String name of ymbol to search for.
Output: Pointer to the Symbol with the given name, or Null if it doesn't exist in the table.
*/
Symbol *findInSymbolsTable(char name[])
{
Symbol *currSymbol = symbolTableHead;
while (currSymbol) {
if (strcmp(currSymbol->name, name) == 0) /* currSymbol.name = given name */
return currSymbol;
currSymbol = currSymbol->next;
}
return NULL;
}
/*
Test function which prints the Symbols table.
Input: none
Output: none but prints the symbol table to the console
*/
void printSymbols() {
Symbol *curr = symbolTableHead;
char method[20] = "", type[10] = "";
while (curr) {
if (curr->method == external)
strcpy(method, "external");
else if (curr->method == entry)
strcpy(method, "entry");
else
strcpy(method, "relocatable");
if (curr->type == code)
strcpy(type, "code");
else if (curr->type == data)
strcpy(type, "data");
else if (curr->type == mdefine)
strcpy(type, "mdefine");
printf("row; %s | %d | %s | %s\n", curr->name, curr->value, method, type);
curr = curr->next;
}
}