-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsymbol.c
More file actions
37 lines (33 loc) · 810 Bytes
/
symbol.c
File metadata and controls
37 lines (33 loc) · 810 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
//
// Created by sapbh on 2/2/2018.
//
#include "global.h"
#define STRMAX 999
#define SYMMAX 100
char lexemes[STRMAX];
int lastchar = -1;
struct entry symtable[SYMMAX];
int lastentry = 0;
int lookup(char s[]) {
int p;
for (p = lastentry; p > 0; p = p - 1) {
if (strcmp(symtable[p].lexptr, s) == 0) {
return p;
}
}
return 0;
}
int insert(char s[], int tok) {
int len;
len = strlen(s);
if (lastentry + 1 >= SYMMAX)
error("symbol table full");
if (lastchar + len + 1 >= STRMAX)
error("lexemes array full");
lastentry = lastentry + 1;
symtable[lastentry].token = tok;
symtable[lastentry].lexptr = &lexemes[lastchar + 1];
lastchar = lastchar + len + 1;
strcpy(symtable[lastentry].lexptr, s);
return lastentry;
}