00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028 #ifndef V8_TOKEN_H_
00029 #define V8_TOKEN_H_
00030
00031 namespace v8 { namespace internal {
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047 #define IGNORE_TOKEN(name, string, precedence)
00048
00049 #define TOKEN_LIST(T, K, F) \
00050 \
00051 T(EOS, "EOS", 0) \
00052 \
00053 \
00054 T(LPAREN, "(", 0) \
00055 T(RPAREN, ")", 0) \
00056 T(LBRACK, "[", 0) \
00057 T(RBRACK, "]", 0) \
00058 T(LBRACE, "{", 0) \
00059 T(RBRACE, "}", 0) \
00060 T(COLON, ":", 0) \
00061 T(SEMICOLON, ";", 0) \
00062 T(PERIOD, ".", 0) \
00063 T(CONDITIONAL, "?", 3) \
00064 T(INC, "++", 0) \
00065 T(DEC, "--", 0) \
00066 \
00067 \
00068 \
00069 \
00070 T(INIT_VAR, "=init_var", 2) \
00071 T(INIT_CONST, "=init_const", 2) \
00072 T(ASSIGN, "=", 2) \
00073 T(ASSIGN_BIT_OR, "|=", 2) \
00074 T(ASSIGN_BIT_XOR, "^=", 2) \
00075 T(ASSIGN_BIT_AND, "&=", 2) \
00076 T(ASSIGN_SHL, "<<=", 2) \
00077 T(ASSIGN_SAR, ">>=", 2) \
00078 T(ASSIGN_SHR, ">>>=", 2) \
00079 T(ASSIGN_ADD, "+=", 2) \
00080 T(ASSIGN_SUB, "-=", 2) \
00081 T(ASSIGN_MUL, "*=", 2) \
00082 T(ASSIGN_DIV, "/=", 2) \
00083 T(ASSIGN_MOD, "%=", 2) \
00084 \
00085 \
00086 \
00087 \
00088 T(COMMA, ",", 1) \
00089 T(OR, "||", 4) \
00090 T(AND, "&&", 5) \
00091 T(BIT_OR, "|", 6) \
00092 T(BIT_XOR, "^", 7) \
00093 T(BIT_AND, "&", 8) \
00094 T(SHL, "<<", 11) \
00095 T(SAR, ">>", 11) \
00096 T(SHR, ">>>", 11) \
00097 T(ADD, "+", 12) \
00098 T(SUB, "-", 12) \
00099 T(MUL, "*", 13) \
00100 T(DIV, "/", 13) \
00101 T(MOD, "%", 13) \
00102 \
00103 \
00104 \
00105 \
00106 T(EQ, "==", 9) \
00107 T(NE, "!=", 9) \
00108 T(EQ_STRICT, "===", 9) \
00109 T(NE_STRICT, "!==", 9) \
00110 T(LT, "<", 10) \
00111 T(GT, ">", 10) \
00112 T(LTE, "<=", 10) \
00113 T(GTE, ">=", 10) \
00114 K(INSTANCEOF, "instanceof", 10) \
00115 K(IN, "in", 10) \
00116 \
00117 \
00118 \
00119 \
00120 T(NOT, "!", 0) \
00121 T(BIT_NOT, "~", 0) \
00122 K(DELETE, "delete", 0) \
00123 K(TYPEOF, "typeof", 0) \
00124 K(VOID, "void", 0) \
00125 \
00126 \
00127 K(BREAK, "break", 0) \
00128 K(CASE, "case", 0) \
00129 K(CATCH, "catch", 0) \
00130 K(CONTINUE, "continue", 0) \
00131 K(DEBUGGER, "debugger", 0) \
00132 K(DEFAULT, "default", 0) \
00133 \
00134 K(DO, "do", 0) \
00135 K(ELSE, "else", 0) \
00136 K(FINALLY, "finally", 0) \
00137 K(FOR, "for", 0) \
00138 K(FUNCTION, "function", 0) \
00139 K(IF, "if", 0) \
00140 \
00141 \
00142 K(NEW, "new", 0) \
00143 K(RETURN, "return", 0) \
00144 K(SWITCH, "switch", 0) \
00145 K(THIS, "this", 0) \
00146 K(THROW, "throw", 0) \
00147 K(TRY, "try", 0) \
00148 \
00149 K(VAR, "var", 0) \
00150 \
00151 K(WHILE, "while", 0) \
00152 K(WITH, "with", 0) \
00153 \
00154 \
00155 F(ABSTRACT, "abstract", 0) \
00156 F(BOOLEAN, "boolean", 0) \
00157 F(BYTE, "byte", 0) \
00158 F(CHAR, "char", 0) \
00159 F(CLASS, "class", 0) \
00160 K(CONST, "const", 0) \
00161 F(DOUBLE, "double", 0) \
00162 F(ENUM, "enum", 0) \
00163 F(EXPORT, "export", 0) \
00164 F(EXTENDS, "extends", 0) \
00165 F(FINAL, "final", 0) \
00166 F(FLOAT, "float", 0) \
00167 F(GOTO, "goto", 0) \
00168 F(IMPLEMENTS, "implements", 0) \
00169 F(IMPORT, "import", 0) \
00170 F(INT, "int", 0) \
00171 F(INTERFACE, "interface", 0) \
00172 F(LONG, "long", 0) \
00173 K(NATIVE, "native", 0) \
00174 F(PACKAGE, "package", 0) \
00175 F(PRIVATE, "private", 0) \
00176 F(PROTECTED, "protected", 0) \
00177 F(PUBLIC, "public", 0) \
00178 F(SHORT, "short", 0) \
00179 F(STATIC, "static", 0) \
00180 F(SUPER, "super", 0) \
00181 F(SYNCHRONIZED, "synchronized", 0) \
00182 F(THROWS, "throws", 0) \
00183 F(TRANSIENT, "transient", 0) \
00184 F(VOLATILE, "volatile", 0) \
00185 \
00186 \
00187 K(NULL_LITERAL, "null", 0) \
00188 K(TRUE_LITERAL, "true", 0) \
00189 K(FALSE_LITERAL, "false", 0) \
00190 T(NUMBER, NULL, 0) \
00191 T(STRING, NULL, 0) \
00192 \
00193 \
00194 T(IDENTIFIER, NULL, 0) \
00195 \
00196 \
00197 T(ILLEGAL, "ILLEGAL", 0) \
00198 \
00199 \
00200 T(COMMENT, NULL, 0)
00201
00202
00203 class Token {
00204 public:
00205
00206 #define T(name, string, precedence) name,
00207 enum Value {
00208 TOKEN_LIST(T, T, IGNORE_TOKEN)
00209 NUM_TOKENS
00210 };
00211 #undef T
00212
00213 #ifdef DEBUG
00214
00215
00216 static const char* Name(Value tok) {
00217 ASSERT(0 <= tok && tok < NUM_TOKENS);
00218 return name_[tok];
00219 }
00220 #endif
00221
00222
00223 static bool IsAssignmentOp(Value tok) {
00224 return INIT_VAR <= tok && tok <= ASSIGN_MOD;
00225 }
00226
00227 static bool IsBinaryOp(Value op) {
00228 return COMMA <= op && op <= MOD;
00229 }
00230
00231 static bool IsCompareOp(Value op) {
00232 return EQ <= op && op <= IN;
00233 }
00234
00235 static bool IsBitOp(Value op) {
00236 return (BIT_OR <= op && op <= SHR) || op == BIT_NOT;
00237 }
00238
00239 static bool IsUnaryOp(Value op) {
00240 return (NOT <= op && op <= VOID) || op == ADD || op == SUB;
00241 }
00242
00243 static bool IsCountOp(Value op) {
00244 return op == INC || op == DEC;
00245 }
00246
00247
00248
00249
00250 static const char* String(Value tok) {
00251 ASSERT(0 <= tok && tok < NUM_TOKENS);
00252 return string_[tok];
00253 }
00254
00255
00256
00257 static int Precedence(Value tok) {
00258 ASSERT(0 <= tok && tok < NUM_TOKENS);
00259 return precedence_[tok];
00260 }
00261
00262
00263
00264
00265 static Value Lookup(const char* str);
00266
00267
00268
00269 static void Initialize();
00270
00271 private:
00272 #ifdef DEBUG
00273 static const char* name_[NUM_TOKENS];
00274 #endif
00275 static const char* string_[NUM_TOKENS];
00276 static int8_t precedence_[NUM_TOKENS];
00277 };
00278
00279 } }
00280
00281 #endif // V8_TOKEN_H_