Main Page | Class List | Directories | File List | Class Members | File Members

keywhash.c

Go to the documentation of this file.
00001 /* Perfect hash generated by command line:
00002  * ./a.out
00003  */
00004 #ifndef SLCONST
00005 #define SLCONST const
00006 #endif
00007 #define MIN_HASH_VALUE  2
00008 #define MAX_HASH_VALUE  151
00009 #define MIN_KEYWORD_LEN 2
00010 #define MAX_KEYWORD_LEN 11
00011 
00012 static SLCONST unsigned char Keyword_Hash_Table [256] =
00013 {
00014   152, 152, 152, 152, 152, 152, 152, 152, 152, 152, 152, 152, 152, 152, 152, 152, 
00015   152, 152, 152, 152, 152, 152, 152, 152, 152, 152, 152, 152, 152, 152, 152, 152, 
00016   152,  15, 152, 152, 152, 152, 152, 152, 152, 152, 152, 152, 152, 152, 152, 152, 
00017    10,  15,  25,  30,  35, 152, 152, 152, 152, 152, 152, 152, 152, 152, 152, 152, 
00018   152, 152,   0,   0, 152,   0, 152, 152, 152,   5, 152,   0,   0, 152, 152,   0, 
00019   152, 152,   0,   0,   0,   0, 152, 152,   0, 152, 152, 152, 152, 152, 152,   5, 
00020   152,   5,   5,  20,  15,   0,   0,   0,  55,  25, 152,   0,  30,  10,  15,   0, 
00021    15, 152,   0,   0,   0,  50,   0,   0,   5,  20, 152, 152, 152, 152, 152, 152, 
00022   152, 152, 152, 152, 152, 152, 152, 152, 152, 152, 152, 152, 152, 152, 152, 152, 
00023   152, 152, 152, 152, 152, 152, 152, 152, 152, 152, 152, 152, 152, 152, 152, 152, 
00024   152, 152, 152, 152, 152, 152, 152, 152, 152, 152, 152, 152, 152, 152, 152, 152, 
00025   152, 152, 152, 152, 152, 152, 152, 152, 152, 152, 152, 152, 152, 152, 152, 152, 
00026   152, 152, 152, 152, 152, 152, 152, 152, 152, 152, 152, 152, 152, 152, 152, 152, 
00027   152, 152, 152, 152, 152, 152, 152, 152, 152, 152, 152, 152, 152, 152, 152, 152, 
00028   152, 152, 152, 152, 152, 152, 152, 152, 152, 152, 152, 152, 152, 152, 152, 152, 
00029   152, 152, 152, 152, 152, 152, 152, 152, 152, 152, 152, 152, 152, 152, 152, 152
00030 };
00031 
00032 static unsigned char keyword_hash (char *s, unsigned int len)
00033 {
00034    unsigned int sum;
00035 
00036    sum = len;
00037    while (len)
00038      {
00039         len--;
00040         sum += (unsigned int) Keyword_Hash_Table [(unsigned char)s[len]];
00041      }
00042    return sum;
00043 }
00044 
00045 typedef SLCONST struct
00046 {
00047    char *name;
00048    unsigned int type;
00049 }
00050 Keyword_Table_Type;
00051 
00052 static Keyword_Table_Type Keyword_Table [/* 150 */] =
00053 {
00054    {"or",       OR_TOKEN},
00055    {"for",      FOR_TOKEN},
00056    {NULL,0},
00057    {NULL,0},
00058    {NULL,0},
00059    {"forever",  FOREVER_TOKEN},
00060    {"xor",      BXOR_TOKEN},
00061    {"_for",     _FOR_TOKEN},
00062    {NULL,0},
00063    {NULL,0},
00064    {NULL,0},
00065    {NULL,0},
00066    {NULL,0},
00067    {"break",    BREAK_TOKEN},
00068    {"ERROR_BLOCK",      ERRBLK_TOKEN},
00069    {"do",       DO_TOKEN},
00070    {"not",      NOT_TOKEN},
00071    {NULL,0},
00072    {"EXIT_BLOCK",       EXITBLK_TOKEN},
00073    {NULL,0},
00074    {NULL,0},
00075    {"try",      TRY_TOKEN},
00076    {NULL,0},
00077    {NULL,0},
00078    {"USER_BLOCK0",      USRBLK0_TOKEN},
00079    {"if",       IF_TOKEN},
00080    {"mod",      MOD_TOKEN},
00081    {"case",     CASE_TOKEN},
00082    {NULL,0},
00083    {"USER_BLOCK1",      USRBLK1_TOKEN},
00084    {NULL,0},
00085    {"pop",      POP_TOKEN},
00086    {"else",     ELSE_TOKEN},
00087    {NULL,0},
00088    {"orelse",   ORELSE_TOKEN},
00089    {NULL,0},
00090    {"and",      AND_TOKEN},
00091    {NULL,0},
00092    {"__tmp",    TMP_TOKEN},
00093    {"USER_BLOCK2",      USRBLK2_TOKEN},
00094    {NULL,0},
00095    {"!if",      IFNOT_TOKEN},
00096    {NULL,0},
00097    {NULL,0},
00098    {"USER_BLOCK3",      USRBLK3_TOKEN},
00099    {NULL,0},
00100    {NULL,0},
00101    {"loop",     LOOP_TOKEN},
00102    {NULL,0},
00103    {"USER_BLOCK4",      USRBLK4_TOKEN},
00104    {"private",  PRIVATE_TOKEN},
00105    {NULL,0},
00106    {NULL,0},
00107    {NULL,0},
00108    {"static",   STATIC_TOKEN},
00109    {"typedef",  TYPEDEF_TOKEN},
00110    {"shr",      SHR_TOKEN},
00111    {NULL,0},
00112    {"throw",    THROW_TOKEN},
00113    {"define",   DEFINE_TOKEN},
00114    {NULL,0},
00115    {NULL,0},
00116    {NULL,0},
00117    {NULL,0},
00118    {NULL,0},
00119    {NULL,0},
00120    {NULL,0},
00121    {NULL,0},
00122    {NULL,0},
00123    {"return",   RETURN_TOKEN},
00124    {"andelse",  ANDELSE_TOKEN},
00125    {NULL,0},
00126    {NULL,0},
00127    {NULL,0},
00128    {"struct",   STRUCT_TOKEN},
00129    {NULL,0},
00130    {"variable", VARIABLE_TOKEN},
00131    {NULL,0},
00132    {NULL,0},
00133    {NULL,0},
00134    {NULL,0},
00135    {NULL,0},
00136    {"exch",     EXCH_TOKEN},
00137    {NULL,0},
00138    {NULL,0},
00139    {"foreach",  FOREACH_TOKEN},
00140    {"shl",      SHL_TOKEN},
00141    {NULL,0},
00142    {NULL,0},
00143    {NULL,0},
00144    {NULL,0},
00145    {NULL,0},
00146    {NULL,0},
00147    {"using",    USING_TOKEN},
00148    {NULL,0},
00149    {NULL,0},
00150    {NULL,0},
00151    {NULL,0},
00152    {NULL,0},
00153    {NULL,0},
00154    {NULL,0},
00155    {NULL,0},
00156    {NULL,0},
00157    {"catch",    CATCH_TOKEN},
00158    {"switch",   SWITCH_TOKEN},
00159    {NULL,0},
00160    {NULL,0},
00161    {NULL,0},
00162    {NULL,0},
00163    {NULL,0},
00164    {NULL,0},
00165    {NULL,0},
00166    {NULL,0},
00167    {"while",    WHILE_TOKEN},
00168    {NULL,0},
00169    {NULL,0},
00170    {NULL,0},
00171    {NULL,0},
00172    {NULL,0},
00173    {NULL,0},
00174    {NULL,0},
00175    {NULL,0},
00176    {NULL,0},
00177    {NULL,0},
00178    {NULL,0},
00179    {NULL,0},
00180    {NULL,0},
00181    {NULL,0},
00182    {NULL,0},
00183    {NULL,0},
00184    {"finally",  FINALLY_TOKEN},
00185    {"continue", CONT_TOKEN},
00186    {NULL,0},
00187    {NULL,0},
00188    {NULL,0},
00189    {NULL,0},
00190    {"do_while", DOWHILE_TOKEN},
00191    {NULL,0},
00192    {NULL,0},
00193    {NULL,0},
00194    {NULL,0},
00195    {NULL,0},
00196    {NULL,0},
00197    {NULL,0},
00198    {NULL,0},
00199    {NULL,0},
00200    {NULL,0},
00201    {NULL,0},
00202    {NULL,0},
00203    {"public",   PUBLIC_TOKEN},
00204 };
00205 
00206 static Keyword_Table_Type *is_keyword (char *str, unsigned int len)
00207 {
00208    unsigned int hash;
00209    char *name;
00210    Keyword_Table_Type *kw;
00211 
00212    if ((len < MIN_KEYWORD_LEN)
00213        || (len > MAX_KEYWORD_LEN))
00214      return NULL;
00215 
00216    hash = keyword_hash (str, len);
00217    if ((hash > MAX_HASH_VALUE) || (hash < MIN_HASH_VALUE))
00218      return NULL;
00219 
00220    kw = &Keyword_Table[hash - MIN_HASH_VALUE];
00221    if ((NULL != (name = kw->name))
00222        && (*str == *name)
00223        && (0 == strcmp (str, name)))
00224      return kw;
00225    return NULL;
00226 }

© sourcejam.com 2005-2008