2 keyword.cc -- keywords and identifiers
8 #include "my-lily-lexer.hh"
12 /* for the keyword table */
23 Keyword_table(Keyword_ent *);
24 int lookup(char const *s) const;
30 tabcmp(void const * p1, void const * p2)
32 return strcmp(((Keyword_ent const *) p1)->name,
33 ((Keyword_ent const *) p2)->name);
36 Keyword_table::Keyword_table(Keyword_ent *tab)
41 for (maxkey = 0; table[maxkey].name; maxkey++);
44 qsort(table, maxkey, sizeof(Keyword_ent), tabcmp);
48 lookup with binsearch, return tokencode.
51 Keyword_table::lookup(char const *s)const
65 result = strcmp(s, table[cmp].name);
73 if (!strcmp(s, table[lo].name))
75 return table[lo].tokcode;
77 return -1; /* not found */