-
Notifications
You must be signed in to change notification settings - Fork 42
Expand file tree
/
Copy pathsym.h
More file actions
51 lines (39 loc) · 781 Bytes
/
sym.h
File metadata and controls
51 lines (39 loc) · 781 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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#ifndef SYM_TABLE
#define SYM_TABLE
#define MAX_SYMBOL_TABLE_SIZE 100
#include <stdlib.h>
#include <string.h>
struct Table
{
int id;
int val;
char *name;
};
struct Table* symbol_table[MAX_SYMBOL_TABLE_SIZE];
int table_size = 0;
struct Table *get_sym(int id)
{
return symbol_table[id];
}
int add_sym(char *name)
{
int i;
for (i = 0; i < table_size; i++) {
if (strcmp(symbol_table[i]->name, name) == 0)
return symbol_table[i]->id;
}
struct Table *item = malloc(sizeof(struct Table));
item->id = table_size;
item->name = name;
symbol_table[table_size] = item;
return table_size++;
}
void set_sym(int id, int val)
{
symbol_table[id]->val = val;
}
int get_table_size()
{
return table_size;
}
#endif