clex_sym.h
上传用户:hbdengju
上传日期:2007-01-06
资源大小:11k
文件大小:5k
源码类别:

编译器/解释器

开发平台:

C/C++

  1. /* clex_sym.h:
  2. // This file defines both an enum {} type named "symbol", and
  3. //  a variable sym_str[] with string representations of the
  4. //  symbols.  It is intended to maintain an exact
  5. //  correspondence between array entries and symbol values.
  6. */
  7. /*
  8.     This file is #include'd twice: once for the enum
  9.     (with CLEX_IMPLEMENTATION turned off) and once for
  10.     the array initialization (with it turned on).  The
  11.     lower-numbered symbols have uppercase name strings,
  12.     but the keyword symbol strings are stored separately.
  13.     If a keyword is to be added, add it first to the
  14.     standalone program kwhash.c and generate a new
  15.     perfect hash function for the new set.  Then add
  16.     it to both places below and modify the hash function
  17.     and table size in clex.c.
  18. */
  19. #ifndef CLEX_IMPLEMENTATION
  20. #define CLEX_S(sym) sym
  21. #define CLEX_S2(sym1,sym2) sym1
  22. enum Clex_sym
  23.     {
  24. #else /* CLEX_IMPLEMENTATION */
  25. #undef  CLEX_S
  26. #undef  CLEX_S2
  27. #define CLEX_S(sym) "sym"
  28. #define CLEX_S2(sym1,sym2) sym2
  29. static char* sym_str[] =
  30.     {
  31. #endif /* CLEX_IMPLEMENTATION */
  32.     CLEX_S(NONE_S = 0),    /* should never get this */
  33.     CLEX_S(ERROR_S),
  34.     CLEX_S(  ERROR_EOLN_S),
  35.     CLEX_S(  ERROR_EOF_S),
  36.     CLEX_S(  ERROR_UNKN_S),
  37. #ifndef CLEX_IMPLEMENTATION
  38.     CLEX_S(ERROR_MAX = ERROR_UNKN_S),
  39. #endif
  40.     CLEX_S(EOF_S),        
  41.     CLEX_S(EOLN_S),         // n
  42.     CLEX_S(BANG_S),         // !
  43.     CLEX_S(  NE_S),         // !=
  44.     CLEX_S(QUOTE_S),        // "
  45.     CLEX_S(POUND_S),        // #
  46.     CLEX_S(MOD_S),          // %
  47.     CLEX_S(  MODAS_S),      // %=
  48.     CLEX_S(AMPER_S),        // &
  49.     CLEX_S(  LAND_S),       // &&
  50.     CLEX_S(  ANDAS_S),      // &=
  51.     CLEX_S(APOS_S),         // '
  52.     CLEX_S(LPAR_S),         // (
  53.     CLEX_S(RPAR_S),         // )
  54.     CLEX_S(STAR_S),         // *
  55.     CLEX_S(  MULAS_S),      // *=
  56.     CLEX_S(PLUS_S),         // +
  57.     CLEX_S(  INCRE_S),      // ++
  58.     CLEX_S(  ADDAS_S),      // +=
  59.     CLEX_S(COMMA_S),        // ),
  60.     CLEX_S(MINUS_S),        // -
  61.     CLEX_S(  DECRE_S),      // --
  62.     CLEX_S(  SUBAS_S),      // -=
  63.     CLEX_S(  DEREF_S),      // ->
  64.     CLEX_S(DOT_S),          // .
  65.     CLEX_S(  ELLIP_S),      // ...
  66.     CLEX_S(SLASH_S),        // / 
  67.     CLEX_S(  DIVAS_S),      // /=
  68.     CLEX_S(COLON_S),        // :
  69.     CLEX_S(  SCOPE_S),      // ::
  70.     CLEX_S(SEMI_S),         // ;
  71.     CLEX_S(LT_S),           // <
  72.     CLEX_S(  LE_S),         // <=
  73.     CLEX_S(  SHL_S),        // <<
  74.     CLEX_S(  SHLAS_S),      // <<=
  75.     CLEX_S(AS_S),           // =
  76.     CLEX_S(  EQ_S),         // ==
  77.     CLEX_S(GT_S),           // >
  78.     CLEX_S(  GE_S),         // >=
  79.     CLEX_S(  SHR_S),        // >>
  80.     CLEX_S(  SHRAS_S),      // >>=
  81.     CLEX_S(QUEST_S),        // ?
  82.     CLEX_S(AT_S),           // @ (undefined)
  83.     CLEX_S(LBRACK_S),       // [
  84.     CLEX_S(BSLASH_S),       //  
  85.     CLEX_S(RBRACK_S),       // ]
  86.     CLEX_S(CARET_S),        // ^
  87.     CLEX_S(  XORAS_S),      // ^=
  88.     CLEX_S(GRAVE_S),        // ` (undefined)
  89.     CLEX_S(LBRACE_S),       // {
  90.     CLEX_S(VBAR_S),         // |
  91.     CLEX_S(  LOR_S),        // ||
  92.     CLEX_S(  ORAS_S),       // |=
  93.     CLEX_S(RBRACE_S),       // }
  94.     CLEX_S(TILDE_S),        // ~
  95.     CLEX_S(IDENT_S),        // a name, or string that could be a name
  96.     CLEX_S(NUM_S),          // a numeric string
  97.     CLEX_S(FLOATNUM_S)      // a recognizably floating-point num
  98. #ifndef CLEX_IMPLEMENTATION
  99.     , CLEX_S(KEYWORD_S),
  100. #else
  101.     };
  102.  static char *keywords[] =
  103.     {
  104. #endif
  105.     CLEX_S2(ASM_S = KEYWORD_S, "asm"),
  106.     CLEX_S2(AUTO_S,     "auto"),
  107.     CLEX_S2(BREAK_S,    "break"),
  108.     CLEX_S2(CASE_S,     "case"),
  109.     CLEX_S2(CHAR_S,     "char"),
  110.     CLEX_S2(CLASS_S,    "class"),
  111.     CLEX_S2(CONST_S,    "const"),
  112.     CLEX_S2(CONTINUE_S, "continue"),
  113.     CLEX_S2(DEFAULT_S,  "default"),
  114.     CLEX_S2(DELETE_S,   "delete"),
  115.     CLEX_S2(DO_S,       "do"),
  116.     CLEX_S2(DOUBLE_S,   "double"),
  117.     CLEX_S2(ELSE_S,     "else"),
  118.     CLEX_S2(ENUM_S,     "enum"),
  119.     CLEX_S2(EXTERN_S,   "extern"),
  120.     CLEX_S2(FLOAT_S,    "float"),
  121.     CLEX_S2(FOR_S,      "for"),
  122.     CLEX_S2(FRIEND_S,   "friend"),
  123.     CLEX_S2(GOTO_S,     "goto"),
  124.     CLEX_S2(IF_S,       "if"),
  125.     CLEX_S2(INLINE_S,   "inline"),
  126.     CLEX_S2(INT_S,      "int"),
  127.     CLEX_S2(LONG_S,     "long"),
  128.     CLEX_S2(NEW_S,      "new"),
  129.     CLEX_S2(OPERATOR_S, "operator"),
  130.     CLEX_S2(OVERLOAD_S, "overload"),
  131.     CLEX_S2(PRIVATE_S,  "private"),
  132.     CLEX_S2(PROTECTED_S,"protected"),
  133.     CLEX_S2(PUBLIC_S,   "public"),
  134.     CLEX_S2(REGISTER_S, "register"),
  135.     CLEX_S2(RETURN_S,   "return"),
  136.     CLEX_S2(SHORT_S,    "short"),
  137.     CLEX_S2(SIGNED_S,   "signed"),
  138.     CLEX_S2(SIZEOF_S,   "sizeof"),
  139.     CLEX_S2(STATIC_S,   "static"),
  140.     CLEX_S2(STRUCT_S,   "struct"),
  141.     CLEX_S2(SWITCH_S,   "switch"),
  142.     CLEX_S2(THIS_S,     "this"),
  143.     CLEX_S2(TYPEDEF_S,  "typedef"),
  144.     CLEX_S2(UNION_S,    "union"),
  145.     CLEX_S2(UNSIGNED_S, "unsigned"),
  146.     CLEX_S2(VIRTUAL_S,  "virtual"),
  147.     CLEX_S2(VOLATILE_S, "volatile"),
  148.     CLEX_S2(VOID_S,     "void"),
  149.     CLEX_S2(WHILE_S,    "while"),
  150.     CLEX_S2(END_OF_SYMBOLS_S, NULL)
  151.     };
  152. #ifndef CLEX_IMPLEMENTATION
  153. const CLEX_NUMKEYS = (END_OF_SYMBOLS_S - KEYWORD_S);
  154. #endif