2 * FML interpreter. Europagate, 1995
5 * Revision 1.3 1995/02/23 08:32:06 adam
8 * Revision 1.1.1.1 1995/02/06 13:48:10 adam
9 * First version of the FML interpreter. It's slow and memory isn't
10 * freed properly. In particular, the FML nodes aren't released yet.
20 struct fml_sym_info info;
29 struct fml_sym **array;
32 struct fml_sym_tab *fml_sym_open (void)
34 struct fml_sym_tab *tab;
37 tab = malloc (sizeof (*tab));
42 tab->array = malloc (sizeof(*tab->array) * tab->hash);
48 for (i = 0; i<tab->hash; i++)
53 void fml_sym_close (struct fml_sym_tab **tabp)
55 struct fml_sym *sym, *sym1;
57 for (i = (*tabp)->hash; --i >= 0; )
58 for (sym = (*tabp)->array[i]; sym; sym = sym1)
68 void fml_sym_push (struct fml_sym_tab *tab)
73 void fml_sym_pop (struct fml_sym_tab *tab, void (*ph)(struct fml_sym_info *i))
78 assert (tab->level > 0);
79 for (i = tab->hash; --i >= 0; )
84 if ((*fsp)->level == tab->level)
102 static unsigned fml_sym_hash (const char *s, unsigned hash)
111 static struct fml_sym_info *sym_add (struct fml_sym_tab *tab,
112 const char *s, int level)
116 struct fml_sym **sym_entry;
118 cp = malloc (strlen(s)+1);
123 sym = malloc (sizeof (*sym));
129 sym_entry = tab->array + fml_sym_hash (s, tab->hash);
131 sym->next = *sym_entry;
137 struct fml_sym_info *fml_sym_add (struct fml_sym_tab *tab, const char *s)
139 return sym_add (tab, s, 0);
142 struct fml_sym_info *fml_sym_add_local (struct fml_sym_tab *tab, const char *s)
144 return sym_add (tab, s, tab->level);
147 static struct fml_sym_info *sym_lookup (struct fml_sym_tab *tab,
148 const char *s, int level)
151 struct fml_sym *sym0 = NULL;
152 struct fml_sym **sym_entry;
154 sym_entry = tab->array + fml_sym_hash (s, tab->hash);
155 for (sym = *sym_entry; sym; sym = sym->next)
156 if (!strcmp (sym->name, s))
157 if (!sym0 || sym->level > sym0->level)
161 assert (sym0->level <= tab->level);
162 if (level && sym0->level != level)
170 struct fml_sym_info *fml_sym_lookup (struct fml_sym_tab *tab, const char *s)
172 return sym_lookup (tab, s, 0);
175 struct fml_sym_info *fml_sym_lookup_local (struct fml_sym_tab *tab,
178 return sym_lookup (tab, s, tab->level);