X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=lily%2Fkeyword.cc;h=378ad4e1683cfc9057b185d5647ef153faace639;hb=4516c9ff0c6b1cfc9b0245486a37a90cf487318e;hp=965630964e1997aef969216c281cde2bf921b4e4;hpb=dbed556ca13bc2371e83774890eaa06bc8b04def;p=lilypond.git diff --git a/lily/keyword.cc b/lily/keyword.cc index 965630964e..378ad4e168 100644 --- a/lily/keyword.cc +++ b/lily/keyword.cc @@ -1,79 +1,36 @@ /* keyword.cc -- keywords and identifiers - */ - -#include - -#include "glob.hh" -#include "my-lily-lexer.hh" -//#include "mudobs.hh" -//#include "gram.hh" - -/* for the keyword table */ -struct Keyword_ent -{ - char const *name; - int tokcode; -}; +*/ -struct Keyword_table -{ - Keyword_ent *table; - int maxkey; - Keyword_table(Keyword_ent *); - int lookup(char const *s) const; -}; +#include "keyword.hh" +#include +#include /* for qsort */ -int - tabcmp(void const * p1, void const * p2) +int tabcmp (Keyword_ent const &p1, Keyword_ent const &p2) { - return strcmp(((Keyword_ent const *) p1)->name, - ((Keyword_ent const *) p2)->name); + return strcmp (p1.name_, p2.name_); } -Keyword_table::Keyword_table(Keyword_ent *tab) +Keyword_table::Keyword_table (Keyword_ent *tab) { - table = tab; - - /* count keywords */ - for (maxkey = 0; table[maxkey].name; maxkey++); + while (tab->name_) + { + table_.push (*tab++); + } - /* sort them */ - qsort(table, maxkey, sizeof(Keyword_ent), tabcmp); + table_.sort (tabcmp); } -/* - lookup with binsearch, return tokencode. -*/ int -Keyword_table::lookup(char const *s)const +Keyword_table::lookup (char const *s) const { - int lo, - hi, - cmp, - result; - lo = 0; - hi = maxkey; - - /* binary search */ - do - { - cmp = (lo + hi) / 2; - - result = strcmp(s, table[cmp].name); - - if (result < 0) - hi = cmp; - else - lo = cmp; - } - while (hi - lo > 1); - if (!strcmp(s, table[lo].name)) - { - return table[lo].tokcode; - } else - return -1; /* not found */ + Keyword_ent e; + e.name_ = s; + int idx = binary_search (table_, e, tabcmp); + if (idx >= 0) + return table_[idx].tokcode_; + else + return -1; } -