OLD | NEW |
1 // Copyright 2011 the V8 project authors. All rights reserved. | 1 // Copyright 2011 the V8 project authors. All rights reserved. |
2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
4 // met: | 4 // met: |
5 // | 5 // |
6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
(...skipping 23 matching lines...) Expand all Loading... |
34 namespace internal { | 34 namespace internal { |
35 | 35 |
36 // TOKEN_LIST takes a list of 3 macros M, all of which satisfy the | 36 // TOKEN_LIST takes a list of 3 macros M, all of which satisfy the |
37 // same signature M(name, string, precedence), where name is the | 37 // same signature M(name, string, precedence), where name is the |
38 // symbolic token name, string is the corresponding syntactic symbol | 38 // symbolic token name, string is the corresponding syntactic symbol |
39 // (or NULL, for literals), and precedence is the precedence (or 0). | 39 // (or NULL, for literals), and precedence is the precedence (or 0). |
40 // The parameters are invoked for token categories as follows: | 40 // The parameters are invoked for token categories as follows: |
41 // | 41 // |
42 // T: Non-keyword tokens | 42 // T: Non-keyword tokens |
43 // K: Keyword tokens | 43 // K: Keyword tokens |
44 // F: Future (reserved) keyword tokens | |
45 | 44 |
46 // IGNORE_TOKEN is a convenience macro that can be supplied as | 45 // IGNORE_TOKEN is a convenience macro that can be supplied as |
47 // an argument (at any position) for a TOKEN_LIST call. It does | 46 // an argument (at any position) for a TOKEN_LIST call. It does |
48 // nothing with tokens belonging to the respective category. | 47 // nothing with tokens belonging to the respective category. |
49 | 48 |
50 #define IGNORE_TOKEN(name, string, precedence) | 49 #define IGNORE_TOKEN(name, string, precedence) |
51 | 50 |
52 #define TOKEN_LIST(T, K, F) \ | 51 #define TOKEN_LIST(T, K) \ |
53 /* End of source indicator. */ \ | 52 /* End of source indicator. */ \ |
54 T(EOS, "EOS", 0) \ | 53 T(EOS, "EOS", 0) \ |
55 \ | 54 \ |
56 /* Punctuators (ECMA-262, section 7.7, page 15). */ \ | 55 /* Punctuators (ECMA-262, section 7.7, page 15). */ \ |
57 T(LPAREN, "(", 0) \ | 56 T(LPAREN, "(", 0) \ |
58 T(RPAREN, ")", 0) \ | 57 T(RPAREN, ")", 0) \ |
59 T(LBRACK, "[", 0) \ | 58 T(LBRACK, "[", 0) \ |
60 T(RBRACK, "]", 0) \ | 59 T(RBRACK, "]", 0) \ |
61 T(LBRACE, "{", 0) \ | 60 T(LBRACE, "{", 0) \ |
62 T(RBRACE, "}", 0) \ | 61 T(RBRACE, "}", 0) \ |
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
175 \ | 174 \ |
176 /* Scanner-internal use only. */ \ | 175 /* Scanner-internal use only. */ \ |
177 T(WHITESPACE, NULL, 0) | 176 T(WHITESPACE, NULL, 0) |
178 | 177 |
179 | 178 |
180 class Token { | 179 class Token { |
181 public: | 180 public: |
182 // All token values. | 181 // All token values. |
183 #define T(name, string, precedence) name, | 182 #define T(name, string, precedence) name, |
184 enum Value { | 183 enum Value { |
185 TOKEN_LIST(T, T, IGNORE_TOKEN) | 184 TOKEN_LIST(T, T) |
186 NUM_TOKENS | 185 NUM_TOKENS |
187 }; | 186 }; |
188 #undef T | 187 #undef T |
189 | 188 |
190 // Returns a string corresponding to the C++ token name | 189 // Returns a string corresponding to the C++ token name |
191 // (e.g. "LT" for the token LT). | 190 // (e.g. "LT" for the token LT). |
192 static const char* Name(Value tok) { | 191 static const char* Name(Value tok) { |
193 ASSERT(tok < NUM_TOKENS); // tok is unsigned | 192 ASSERT(tok < NUM_TOKENS); // tok is unsigned |
194 return name_[tok]; | 193 return name_[tok]; |
195 } | 194 } |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
279 private: | 278 private: |
280 static const char* const name_[NUM_TOKENS]; | 279 static const char* const name_[NUM_TOKENS]; |
281 static const char* const string_[NUM_TOKENS]; | 280 static const char* const string_[NUM_TOKENS]; |
282 static const int8_t precedence_[NUM_TOKENS]; | 281 static const int8_t precedence_[NUM_TOKENS]; |
283 static const char token_type[NUM_TOKENS]; | 282 static const char token_type[NUM_TOKENS]; |
284 }; | 283 }; |
285 | 284 |
286 } } // namespace v8::internal | 285 } } // namespace v8::internal |
287 | 286 |
288 #endif // V8_TOKEN_H_ | 287 #endif // V8_TOKEN_H_ |
OLD | NEW |