2 keyword.cc -- keywords and identifiers
7 #include "my-lily-lexer.hh"
9 /* for the keyword table */
20 Keyword_table (Keyword_ent *);
21 int lookup (char const *s) const;
27 tabcmp (void const * p1, void const * p2)
29 return strcmp (((Keyword_ent const *) p1)->name,
30 ((Keyword_ent const *) p2)->name);
33 Keyword_table::Keyword_table (Keyword_ent *tab)
38 for (maxkey = 0; table[maxkey].name; maxkey++);
41 qsort (table, maxkey, sizeof (Keyword_ent), tabcmp);
45 lookup with binsearch, return tokencode.
48 Keyword_table::lookup (char const *s)const
62 result = strcmp (s, table[cmp].name);
70 if (!strcmp (s, table[lo].name))
72 return table[lo].tokcode;
74 return -1; /* not found */