8 YYSTYPE getvar(char *s) /* return value of variable s (usually pointer) */
15 if (islower((int) s[0]))
16 ERROR "no such variable as %s", s WARNING;
18 ERROR "no such place as %s", s WARNING;
24 double getfval(char *s) /* return float value of variable s */
32 void setfval(char *s, double f) /* set variable s to f */
36 if ((p = lookup(s)) != NULL)
40 struct symtab *makevar(char *s, int t, YYSTYPE v) /* make variable named s in table */
41 /* assumes s is static or from tostring */
45 for (p = stack[nstack].p_symtab; p != NULL; p = p->s_next)
46 if (strcmp(s, p->s_name) == 0)
48 if (p == NULL) { /* it's a new one */
49 p = (struct symtab *) malloc(sizeof(struct symtab));
51 ERROR "out of symtab space with %s", s FATAL;
52 p->s_next = stack[nstack].p_symtab;
53 stack[nstack].p_symtab = p; /* stick it at front */
61 struct symtab *lookup(char *s) /* find s in symtab */
66 for (i = nstack; i >= 0; i--) /* look in each active symtab */
67 for (p = stack[i].p_symtab; p != NULL; p = p->s_next)
68 if (strcmp(s, p->s_name) == 0)
73 void freesymtab(struct symtab *p) /* free space used by symtab at p */
77 for ( ; p != NULL; p = q) {
79 free(p->s_name); /* assumes done with tostring */
84 void freedef(char *s) /* free definition for string s */
86 struct symtab *p, *q, *op;
88 for (p = op = q = stack[nstack].p_symtab; p != NULL; p = p->s_next) {
89 if (strcmp(s, p->s_name) == 0) { /* got it */
90 if (p->s_type != DEFNAME)
92 if (p == op) /* 1st elem */
93 stack[nstack].p_symtab = p->s_next;
95 q->s_next = p->s_next;
103 /* ERROR "%s is not defined at this point", s WARNING; */