-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsymbol.c
52 lines (42 loc) · 1.24 KB
/
symbol.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
52
#include "symbol.h"
#include "constants.h"
#include <string.h>
#include <stdlib.h>
struct symbol{/*represents a row in the symbol table*/
char symbolName[MAX_SYMBOL_LENGTH];
int baseAddress;
int offset;
int attributeCount;
char attributes[MAX_ATTRIBUTES][MAX_ATTRIBUTE_NAME_LENGTH];
};
Symbol *createSymbolArray(int size){
return (Symbol *)calloc(size, sizeof(Symbol));
}
Symbol *getSymbolAtIndex(Symbol *symbolArray, int index){
return symbolArray+index;
}
char *getAttributesLine(Symbol *symbol, int index){
return symbol->attributes[index];
}
char *getSymbolName(Symbol *symbol){
return symbol->symbolName;
}
int getBaseAddress(Symbol *symbol){
return symbol->baseAddress;
}
int getOffset(Symbol *symbol){
return symbol->offset;
}
int getAttributesCount(Symbol *symbol){
return symbol->attributeCount;
}
void increaseAttributeCount(Symbol *symbol){
symbol->attributeCount++;
}
void createSymbol(Symbol *table, int index, char *newSymbolName, char *attr ,int base, int offset){
strcpy((table + (index))->symbolName, newSymbolName);
(table+index)->baseAddress = base;
(table+index)->offset = offset;
strcpy(((table+index)->attributes)[0], attr);
((table+index)->attributeCount) = 1;
}