blob: 0a777b0d503900f90f6e28269503aaf556c3a42f (
plain)
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
|
#include <u.h>
#include <libc.h>
#include "hoc.h"
#include "y.tab.h"
static Symbol *symlist = 0; /* symbol table: linked list */
Symbol*
lookup(char* s) /* find s in symbol table */
{
Symbol *sp;
for (sp = symlist; sp != (Symbol *) 0; sp = sp->next)
if (strcmp(sp->name, s) == 0)
return sp;
return 0; /* 0 ==> not found */
}
Symbol*
install(char* s, int t, double d) /* install s in symbol table */
{
Symbol *sp;
sp = emalloc(sizeof(Symbol));
sp->name = emalloc(strlen(s)+1); /* +1 for '\0' */
strcpy(sp->name, s);
sp->type = t;
sp->u.val = d;
sp->next = symlist; /* put at front of list */
symlist = sp;
return sp;
}
void*
emalloc(unsigned n) /* check return from malloc */
{
char *p;
p = malloc(n);
if (p == 0)
execerror("out of memory", (char *) 0);
return p;
}
Formal*
formallist(Symbol *formal, Formal *list) /* add formal to list */
{
Formal *f;
f = emalloc(sizeof(Formal));
f->sym = formal;
f->save = 0;
f->next = list;
return f;
}
|