lex.c


DEFINITIONS

This source file includes following functions.
  1. hash
  2. rb_reserved_word


   1  /* C code produced by gperf version 2.7.2 */
   2  /* Command-line: gperf -p -j1 -i 1 -g -o -t -N rb_reserved_word -k'1,3,$' ./keywords  */
   3  struct kwtable {char *name; int id[2]; enum lex_state state;};
   4  
   5  #define TOTAL_KEYWORDS 40
   6  #define MIN_WORD_LENGTH 2
   7  #define MAX_WORD_LENGTH 8
   8  #define MIN_HASH_VALUE 6
   9  #define MAX_HASH_VALUE 55
  10  /* maximum key range = 50, duplicates = 0 */
  11  
  12  #ifdef __GNUC__
  13  __inline
  14  #else
  15  #ifdef __cplusplus
  16  inline
  17  #endif
  18  #endif
  19  static unsigned int
  20  hash (str, len)
  21       register const char *str;
  22       register unsigned int len;
  23  {
  24    static unsigned char asso_values[] =
  25      {
  26        56, 56, 56, 56, 56, 56, 56, 56, 56, 56,
  27        56, 56, 56, 56, 56, 56, 56, 56, 56, 56,
  28        56, 56, 56, 56, 56, 56, 56, 56, 56, 56,
  29        56, 56, 56, 56, 56, 56, 56, 56, 56, 56,
  30        56, 56, 56, 56, 56, 56, 56, 56, 56, 56,
  31        56, 56, 56, 56, 56, 56, 56, 56, 56, 56,
  32        56, 56, 56, 11, 56, 56, 36, 56,  1, 37,
  33        31,  1, 56, 56, 56, 56, 29, 56,  1, 56,
  34        56, 56, 56, 56, 56, 56, 56, 56, 56, 56,
  35        56, 56, 56, 56, 56,  1, 56, 32,  1,  2,
  36         1,  1,  4, 23, 56, 17, 56, 20,  9,  2,
  37         9, 26, 14, 56,  5,  1,  1, 16, 56, 21,
  38        20,  9, 56, 56, 56, 56, 56, 56, 56, 56,
  39        56, 56, 56, 56, 56, 56, 56, 56, 56, 56,
  40        56, 56, 56, 56, 56, 56, 56, 56, 56, 56,
  41        56, 56, 56, 56, 56, 56, 56, 56, 56, 56,
  42        56, 56, 56, 56, 56, 56, 56, 56, 56, 56,
  43        56, 56, 56, 56, 56, 56, 56, 56, 56, 56,
  44        56, 56, 56, 56, 56, 56, 56, 56, 56, 56,
  45        56, 56, 56, 56, 56, 56, 56, 56, 56, 56,
  46        56, 56, 56, 56, 56, 56, 56, 56, 56, 56,
  47        56, 56, 56, 56, 56, 56, 56, 56, 56, 56,
  48        56, 56, 56, 56, 56, 56, 56, 56, 56, 56,
  49        56, 56, 56, 56, 56, 56, 56, 56, 56, 56,
  50        56, 56, 56, 56, 56, 56, 56, 56, 56, 56,
  51        56, 56, 56, 56, 56, 56
  52      };
  53    register int hval = len;
  54  
  55    switch (hval)
  56      {
  57        default:
  58        case 3:
  59          hval += asso_values[(unsigned char)str[2]];
  60        case 2:
  61        case 1:
  62          hval += asso_values[(unsigned char)str[0]];
  63          break;
  64      }
  65    return hval + asso_values[(unsigned char)str[len - 1]];
  66  }
  67  
  68  #ifdef __GNUC__
  69  __inline
  70  #endif
  71  struct kwtable *
  72  rb_reserved_word (str, len)
  73       register const char *str;
  74       register unsigned int len;
  75  {
  76    static struct kwtable wordlist[] =
  77      {
  78        {""}, {""}, {""}, {""}, {""}, {""},
  79        {"end", kEND, kEND, EXPR_END},
  80        {"else", kELSE, kELSE, EXPR_BEG},
  81        {"case", kCASE, kCASE, EXPR_BEG},
  82        {"ensure", kENSURE, kENSURE, EXPR_BEG},
  83        {"module", kMODULE, kMODULE, EXPR_BEG},
  84        {"elsif", kELSIF, kELSIF, EXPR_BEG},
  85        {"def", kDEF, kDEF, EXPR_FNAME},
  86        {"rescue", kRESCUE, kRESCUE_MOD, EXPR_MID},
  87        {"not", kNOT, kNOT, EXPR_BEG},
  88        {"then", kTHEN, kTHEN, EXPR_BEG},
  89        {"yield", kYIELD, kYIELD, EXPR_ARG},
  90        {"for", kFOR, kFOR, EXPR_BEG},
  91        {"self", kSELF, kSELF, EXPR_END},
  92        {"false", kFALSE, kFALSE, EXPR_END},
  93        {"retry", kRETRY, kRETRY, EXPR_END},
  94        {"return", kRETURN, kRETURN, EXPR_MID},
  95        {"true", kTRUE, kTRUE, EXPR_END},
  96        {"if", kIF, kIF_MOD, EXPR_BEG},
  97        {"defined?", kDEFINED, kDEFINED, EXPR_ARG},
  98        {"super", kSUPER, kSUPER, EXPR_ARG},
  99        {"undef", kUNDEF, kUNDEF, EXPR_FNAME},
 100        {"break", kBREAK, kBREAK, EXPR_MID},
 101        {"in", kIN, kIN, EXPR_BEG},
 102        {"do", kDO, kDO, EXPR_BEG},
 103        {"nil", kNIL, kNIL, EXPR_END},
 104        {"until", kUNTIL, kUNTIL_MOD, EXPR_BEG},
 105        {"unless", kUNLESS, kUNLESS_MOD, EXPR_BEG},
 106        {"or", kOR, kOR, EXPR_BEG},
 107        {"next", kNEXT, kNEXT, EXPR_MID},
 108        {"when", kWHEN, kWHEN, EXPR_BEG},
 109        {"redo", kREDO, kREDO, EXPR_END},
 110        {"and", kAND, kAND, EXPR_BEG},
 111        {"begin", kBEGIN, kBEGIN, EXPR_BEG},
 112        {"__LINE__", k__LINE__, k__LINE__, EXPR_END},
 113        {"class", kCLASS, kCLASS, EXPR_CLASS},
 114        {"__FILE__", k__FILE__, k__FILE__, EXPR_END},
 115        {"END", klEND, klEND, EXPR_END},
 116        {"BEGIN", klBEGIN, klBEGIN, EXPR_END},
 117        {"while", kWHILE, kWHILE_MOD, EXPR_BEG},
 118        {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""},
 119        {""},
 120        {"alias", kALIAS, kALIAS, EXPR_FNAME}
 121      };
 122  
 123    if (len <= MAX_WORD_LENGTH && len >= MIN_WORD_LENGTH)
 124      {
 125        register int key = hash (str, len);
 126  
 127        if (key <= MAX_HASH_VALUE && key >= 0)
 128          {
 129            register const char *s = wordlist[key].name;
 130  
 131            if (*str == *s && !strcmp (str + 1, s + 1))
 132              return &wordlist[key];
 133          }
 134      }
 135    return 0;
 136  }