OLD | NEW |
1 /* | 1 /* |
2 keyword.cc -- keywords and identifiers | 2 keyword.cc -- keywords and identifiers |
3 */ | 3 */ |
4 | 4 |
5 #include "keyword.hh" | 5 #include "keyword.hh" |
6 | 6 |
7 #include <cstring> | 7 #include <cstring> |
8 #include <cstdlib> | 8 #include <cstdlib> |
9 using namespace std; | 9 using namespace std; |
10 | 10 |
11 /* for qsort */ | 11 /* for qsort */ |
12 bool tab_less (Keyword_ent const &p1, Keyword_ent const &p2) | 12 bool tab_less (Keyword_ent const &p1, Keyword_ent const &p2) |
13 { | 13 { |
14 return strcmp (p1.name_, p2.name_) < 0; | 14 return strcmp (p1.name_, p2.name_) < 0; |
15 } | 15 } |
16 | 16 |
17 Keyword_table::Keyword_table (Keyword_ent *tab) | 17 Keyword_table::Keyword_table (Keyword_ent *tab) |
18 { | 18 { |
19 while (tab->name_) | 19 while (tab->name_) |
20 table_.push_back (*tab++); | 20 table_.push_back (*tab++); |
21 | 21 |
22 vector_sort (table_, tab_less); | 22 vector_sort (table_, tab_less); |
23 } | 23 } |
24 | 24 |
25 vsize | 25 int |
26 Keyword_table::lookup (char const *s) const | 26 Keyword_table::lookup (char const *s) const |
27 { | 27 { |
28 Keyword_ent e; | 28 Keyword_ent e; |
29 e.name_ = s; | 29 e.name_ = s; |
30 vsize idx = binary_search (table_, e, tab_less); | 30 vsize idx = binary_search (table_, e, tab_less); |
31 if (idx != VPOS) | 31 if (idx != VPOS) |
32 return table_[idx].tokcode_; | 32 return table_[idx].tokcode_; |
33 return VPOS; | 33 return -1; |
34 } | 34 } |
OLD | NEW |