Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(33)

Side by Side Diff: src/lexer/lexer.re

Issue 26972004: Experimental push model parser: Keyword fixes. (Closed) Base URL: https://v8.googlecode.com/svn/branches/experimental/parser
Patch Set: Created 7 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 #include <fcntl.h> 1 #include <fcntl.h>
2 #include <stdio.h> 2 #include <stdio.h>
3 #include <stddef.h> 3 #include <stddef.h>
4 #include <stdlib.h> 4 #include <stdlib.h>
5 #include <string.h> 5 #include <string.h>
6 6
7 // TODO: 7 // TODO:
8 // - SpiderMonkey compatibility hack: " --> something" is treated 8 // - SpiderMonkey compatibility hack: " --> something" is treated
9 // as a single line comment. 9 // as a single line comment.
10 // - An identifier cannot start immediately after a number. 10 // - An identifier cannot start immediately after a number.
(...skipping 29 matching lines...) Expand all
40 #define O_BINARY 0 40 #define O_BINARY 0
41 #endif 41 #endif
42 42
43 #endif // defined(WIN32) 43 #endif // defined(WIN32)
44 44
45 #include "lexer.h" 45 #include "lexer.h"
46 46
47 using namespace v8::internal; 47 using namespace v8::internal;
48 48
49 #define PUSH_TOKEN(T) { send(T); SKIP(); } 49 #define PUSH_TOKEN(T) { send(T); SKIP(); }
50 #define PUSH_TOKEN_LOOKAHEAD(T) { --cursor_; send(T); SKIP(); }
50 #define PUSH_LINE_TERMINATOR() { SKIP(); } 51 #define PUSH_LINE_TERMINATOR() { SKIP(); }
51 #define TERMINATE_ILLEGAL() { return 1; } 52 #define TERMINATE_ILLEGAL() { return 1; }
52 53
53 class PushScanner { 54 class PushScanner {
54 55
55 public: 56 public:
56 PushScanner(ExperimentalScanner* sink): 57 PushScanner(ExperimentalScanner* sink):
57 eof_(false), 58 eof_(false),
58 state_(-1), 59 state_(-1),
59 condition_(kConditionNormal), 60 condition_(kConditionNormal),
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
164 re2c:yych:conversion = 0; 165 re2c:yych:conversion = 0;
165 re2c:condenumprefix = kCondition; 166 re2c:condenumprefix = kCondition;
166 re2c:define:YYCONDTYPE = Condition; 167 re2c:define:YYCONDTYPE = Condition;
167 168
168 eof = "\000"; 169 eof = "\000";
169 any = [\000-\377]; 170 any = [\000-\377];
170 whitespace_char = [ \t\v\f\r]; 171 whitespace_char = [ \t\v\f\r];
171 whitespace = whitespace_char+; 172 whitespace = whitespace_char+;
172 identifier_start_ = [$_\\a-zA-Z]; 173 identifier_start_ = [$_\\a-zA-Z];
173 identifier_char = [$_\\a-zA-Z0-9]; 174 identifier_char = [$_\\a-zA-Z0-9];
175 not_identifier_char = any\identifier_char;
174 line_terminator = [\n\r]+; 176 line_terminator = [\n\r]+;
175 digit = [0-9]; 177 digit = [0-9];
176 hex_digit = [0-9a-fA-F]; 178 hex_digit = [0-9a-fA-F];
177 maybe_exponent = ('e' [-+]? digit+)?; 179 maybe_exponent = ('e' [-+]? digit+)?;
178 180
179 <Normal> "break" { PUSH_TOKEN(Token::BREAK); } 181 <Normal> "break" not_identifier_char { PUSH_TOKEN_LOOKAHEAD(Token::BREA K); }
180 <Normal> "case" { PUSH_TOKEN(Token::CASE); } 182 <Normal> "case" not_identifier_char { PUSH_TOKEN_LOOKAHEAD(Token::CASE ); }
181 <Normal> "catch" { PUSH_TOKEN(Token::CATCH); } 183 <Normal> "catch" not_identifier_char { PUSH_TOKEN_LOOKAHEAD(Token::CATC H); }
182 <Normal> "class" { PUSH_TOKEN(Token::FUTURE_RESERVED_WORD); } 184 <Normal> "class" not_identifier_char { PUSH_TOKEN_LOOKAHEAD(Token::FUTU RE_RESERVED_WORD); }
183 <Normal> "const" { PUSH_TOKEN(Token::CONST); } 185 <Normal> "const" not_identifier_char { PUSH_TOKEN_LOOKAHEAD(Token::CONS T); }
184 <Normal> "continue" { PUSH_TOKEN(Token::CONTINUE); } 186 <Normal> "continue" not_identifier_char { PUSH_TOKEN_LOOKAHEAD(Token::CONT INUE); }
185 <Normal> "debugger" { PUSH_TOKEN(Token::DEBUGGER); } 187 <Normal> "debugger" not_identifier_char { PUSH_TOKEN_LOOKAHEAD(Token::DEBU GGER); }
186 <Normal> "default" { PUSH_TOKEN(Token::DEFAULT); } 188 <Normal> "default" not_identifier_char { PUSH_TOKEN_LOOKAHEAD(Token::DEFA ULT); }
187 <Normal> "delete" { PUSH_TOKEN(Token::DELETE); } 189 <Normal> "delete" not_identifier_char { PUSH_TOKEN_LOOKAHEAD(Token::DELE TE); }
188 <Normal> "do" { PUSH_TOKEN(Token::DO); } 190 <Normal> "do" not_identifier_char { PUSH_TOKEN_LOOKAHEAD(Token::DO); }
189 <Normal> "else" { PUSH_TOKEN(Token::ELSE); } 191 <Normal> "else" not_identifier_char { PUSH_TOKEN_LOOKAHEAD(Token::ELSE ); }
190 <Normal> "enum" { PUSH_TOKEN(Token::FUTURE_RESERVED_WORD); } 192 <Normal> "enum" not_identifier_char { PUSH_TOKEN_LOOKAHEAD(Token::FUTU RE_RESERVED_WORD); }
191 <Normal> "export" { PUSH_TOKEN(Token::FUTURE_RESERVED_WORD); } 193 <Normal> "export" not_identifier_char { PUSH_TOKEN_LOOKAHEAD(Token::FUTU RE_RESERVED_WORD); }
192 <Normal> "extends" { PUSH_TOKEN(Token::FUTURE_RESERVED_WORD); } 194 <Normal> "extends" not_identifier_char { PUSH_TOKEN_LOOKAHEAD(Token::FUTU RE_RESERVED_WORD); }
193 <Normal> "false" { PUSH_TOKEN(Token::FALSE_LITERAL); } 195 <Normal> "false" not_identifier_char { PUSH_TOKEN_LOOKAHEAD(Token::FALS E_LITERAL); }
194 <Normal> "finally" { PUSH_TOKEN(Token::FINALLY); } 196 <Normal> "finally" not_identifier_char { PUSH_TOKEN_LOOKAHEAD(Token::FINA LLY); }
195 <Normal> "for" { PUSH_TOKEN(Token::FOR); } 197 <Normal> "for" not_identifier_char { PUSH_TOKEN_LOOKAHEAD(Token::FOR) ; }
196 <Normal> "function" { PUSH_TOKEN(Token::FUNCTION); } 198 <Normal> "function" not_identifier_char { PUSH_TOKEN_LOOKAHEAD(Token::FUNC TION); }
197 <Normal> "if" { PUSH_TOKEN(Token::IF); } 199 <Normal> "if" not_identifier_char { PUSH_TOKEN_LOOKAHEAD(Token::IF); }
198 <Normal> "implements" { PUSH_TOKEN(Token::FUTURE_STRICT_RESERVED_WORD); } 200 <Normal> "implements" not_identifier_char { PUSH_TOKEN_LOOKAHEAD(Token::FUTU RE_STRICT_RESERVED_WORD); }
199 <Normal> "import" { PUSH_TOKEN(Token::FUTURE_RESERVED_WORD); } 201 <Normal> "import" not_identifier_char { PUSH_TOKEN_LOOKAHEAD(Token::FUTU RE_RESERVED_WORD); }
200 <Normal> "in" { PUSH_TOKEN(Token::IN); } 202 <Normal> "in" not_identifier_char { PUSH_TOKEN_LOOKAHEAD(Token::IN); }
201 <Normal> "instanceof" { PUSH_TOKEN(Token::INSTANCEOF); } 203 <Normal> "instanceof" not_identifier_char { PUSH_TOKEN_LOOKAHEAD(Token::INST ANCEOF); }
202 <Normal> "interface" { PUSH_TOKEN(Token::FUTURE_STRICT_RESERVED_WORD); } 204 <Normal> "interface" not_identifier_char { PUSH_TOKEN_LOOKAHEAD(Token::FUTU RE_STRICT_RESERVED_WORD); }
203 <Normal> "let" { PUSH_TOKEN(Token::FUTURE_STRICT_RESERVED_WORD); } 205 <Normal> "let" not_identifier_char { PUSH_TOKEN_LOOKAHEAD(Token::FUTU RE_STRICT_RESERVED_WORD); }
204 <Normal> "new" { PUSH_TOKEN(Token::NEW); } 206 <Normal> "new" not_identifier_char { PUSH_TOKEN_LOOKAHEAD(Token::NEW) ; }
205 <Normal> "null" { PUSH_TOKEN(Token::NULL_LITERAL); } 207 <Normal> "null" not_identifier_char { PUSH_TOKEN_LOOKAHEAD(Token::NULL _LITERAL); }
206 <Normal> "package" { PUSH_TOKEN(Token::FUTURE_STRICT_RESERVED_WORD); } 208 <Normal> "package" not_identifier_char { PUSH_TOKEN_LOOKAHEAD(Token::FUTU RE_STRICT_RESERVED_WORD); }
207 <Normal> "private" { PUSH_TOKEN(Token::FUTURE_STRICT_RESERVED_WORD); } 209 <Normal> "private" not_identifier_char { PUSH_TOKEN_LOOKAHEAD(Token::FUTU RE_STRICT_RESERVED_WORD); }
208 <Normal> "protected" { PUSH_TOKEN(Token::FUTURE_STRICT_RESERVED_WORD); } 210 <Normal> "protected" not_identifier_char { PUSH_TOKEN_LOOKAHEAD(Token::FUTU RE_STRICT_RESERVED_WORD); }
209 <Normal> "public" { PUSH_TOKEN(Token::FUTURE_STRICT_RESERVED_WORD); } 211 <Normal> "public" not_identifier_char { PUSH_TOKEN_LOOKAHEAD(Token::FUTU RE_STRICT_RESERVED_WORD); }
210 <Normal> "return" { PUSH_TOKEN(Token::RETURN); } 212 <Normal> "return" not_identifier_char { PUSH_TOKEN_LOOKAHEAD(Token::RETU RN); }
211 <Normal> "static" { PUSH_TOKEN(Token::FUTURE_STRICT_RESERVED_WORD); } 213 <Normal> "static" not_identifier_char { PUSH_TOKEN_LOOKAHEAD(Token::FUTU RE_STRICT_RESERVED_WORD); }
212 <Normal> "super" { PUSH_TOKEN(Token::FUTURE_RESERVED_WORD); } 214 <Normal> "super" not_identifier_char { PUSH_TOKEN_LOOKAHEAD(Token::FUTU RE_RESERVED_WORD); }
213 <Normal> "switch" { PUSH_TOKEN(Token::SWITCH); } 215 <Normal> "switch" not_identifier_char { PUSH_TOKEN_LOOKAHEAD(Token::SWIT CH); }
214 <Normal> "this" { PUSH_TOKEN(Token::THIS); } 216 <Normal> "this" not_identifier_char { PUSH_TOKEN_LOOKAHEAD(Token::THIS ); }
215 <Normal> "throw" { PUSH_TOKEN(Token::THROW); } 217 <Normal> "throw" not_identifier_char { PUSH_TOKEN_LOOKAHEAD(Token::THRO W); }
216 <Normal> "true" { PUSH_TOKEN(Token::TRUE_LITERAL); } 218 <Normal> "true" not_identifier_char { PUSH_TOKEN_LOOKAHEAD(Token::TRUE _LITERAL); }
217 <Normal> "try" { PUSH_TOKEN(Token::TRY); } 219 <Normal> "try" not_identifier_char { PUSH_TOKEN_LOOKAHEAD(Token::TRY) ; }
218 <Normal> "typeof" { PUSH_TOKEN(Token::TYPEOF); } 220 <Normal> "typeof" not_identifier_char { PUSH_TOKEN_LOOKAHEAD(Token::TYPE OF); }
219 <Normal> "var" { PUSH_TOKEN(Token::VAR); } 221 <Normal> "var" not_identifier_char { PUSH_TOKEN_LOOKAHEAD(Token::VAR) ; }
220 <Normal> "void" { PUSH_TOKEN(Token::VOID); } 222 <Normal> "void" not_identifier_char { PUSH_TOKEN_LOOKAHEAD(Token::VOID ); }
221 <Normal> "while" { PUSH_TOKEN(Token::WHILE); } 223 <Normal> "while" not_identifier_char { PUSH_TOKEN_LOOKAHEAD(Token::WHIL E); }
222 <Normal> "with" { PUSH_TOKEN(Token::WITH); } 224 <Normal> "with" not_identifier_char { PUSH_TOKEN_LOOKAHEAD(Token::WITH ); }
223 <Normal> "yield" { PUSH_TOKEN(Token::YIELD); } 225 <Normal> "yield" not_identifier_char { PUSH_TOKEN_LOOKAHEAD(Token::YIEL D); }
224 226
225 <Normal> "|=" { PUSH_TOKEN(Token::ASSIGN_BIT_OR); } 227 <Normal> "|=" { PUSH_TOKEN(Token::ASSIGN_BIT_OR); }
226 <Normal> "^=" { PUSH_TOKEN(Token::ASSIGN_BIT_XOR); } 228 <Normal> "^=" { PUSH_TOKEN(Token::ASSIGN_BIT_XOR); }
227 <Normal> "&=" { PUSH_TOKEN(Token::ASSIGN_BIT_AND); } 229 <Normal> "&=" { PUSH_TOKEN(Token::ASSIGN_BIT_AND); }
228 <Normal> "+=" { PUSH_TOKEN(Token::ASSIGN_ADD); } 230 <Normal> "+=" { PUSH_TOKEN(Token::ASSIGN_ADD); }
229 <Normal> "-=" { PUSH_TOKEN(Token::ASSIGN_SUB); } 231 <Normal> "-=" { PUSH_TOKEN(Token::ASSIGN_SUB); }
230 <Normal> "*=" { PUSH_TOKEN(Token::ASSIGN_MUL); } 232 <Normal> "*=" { PUSH_TOKEN(Token::ASSIGN_MUL); }
231 <Normal> "/=" { PUSH_TOKEN(Token::ASSIGN_DIV); } 233 <Normal> "/=" { PUSH_TOKEN(Token::ASSIGN_DIV); }
232 <Normal> "%=" { PUSH_TOKEN(Token::ASSIGN_MOD); } 234 <Normal> "%=" { PUSH_TOKEN(Token::ASSIGN_MOD); }
233 235
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
296 298
297 <DoubleQuoteString> "\\\"" { goto yy0; } 299 <DoubleQuoteString> "\\\"" { goto yy0; }
298 <DoubleQuoteString> '"' { PUSH_TOKEN(Token::STRING);} 300 <DoubleQuoteString> '"' { PUSH_TOKEN(Token::STRING);}
299 <DoubleQuoteString> any { goto yy0; } 301 <DoubleQuoteString> any { goto yy0; }
300 302
301 <SingleQuoteString> "\\'" { goto yy0; } 303 <SingleQuoteString> "\\'" { goto yy0; }
302 <SingleQuoteString> "'" { PUSH_TOKEN(Token::STRING);} 304 <SingleQuoteString> "'" { PUSH_TOKEN(Token::STRING);}
303 <SingleQuoteString> any { goto yy0; } 305 <SingleQuoteString> any { goto yy0; }
304 306
305 <Identifier> identifier_char+ { goto yy0; } 307 <Identifier> identifier_char+ { goto yy0; }
306 <Identifier> any { cursor_--; PUSH_TOKEN(Token::IDENTIFIER); } 308 <Identifier> any { PUSH_TOKEN_LOOKAHEAD(Token::IDENTIFIER); }
307 309
308 <SingleLineComment> line_terminator { PUSH_LINE_TERMINATOR();} 310 <SingleLineComment> line_terminator { PUSH_LINE_TERMINATOR();}
309 <SingleLineComment> eof { PUSH_LINE_TERMINATOR();} 311 <SingleLineComment> eof { PUSH_LINE_TERMINATOR();}
310 <SingleLineComment> any { goto yy0; } 312 <SingleLineComment> any { goto yy0; }
311 313
312 <MultiLineComment> [*][//] { PUSH_LINE_TERMINATOR();} 314 <MultiLineComment> [*][//] { PUSH_LINE_TERMINATOR();}
313 <MultiLineComment> eof { TERMINATE_ILLEGAL(); } 315 <MultiLineComment> eof { TERMINATE_ILLEGAL(); }
314 <MultiLineComment> any { goto yy0; } 316 <MultiLineComment> any { goto yy0; }
315 317
316 <HtmlComment> eof { TERMINATE_ILLEGAL(); } 318 <HtmlComment> eof { TERMINATE_ILLEGAL(); }
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
411 } 413 }
412 414
413 415
414 void ExperimentalScanner::Record(Token::Value token, int beg, int end) { 416 void ExperimentalScanner::Record(Token::Value token, int beg, int end) {
415 if (token == Token::EOS) end--; 417 if (token == Token::EOS) end--;
416 token_[fetched_] = token; 418 token_[fetched_] = token;
417 beg_[fetched_] = beg; 419 beg_[fetched_] = beg;
418 end_[fetched_] = end; 420 end_[fetched_] = end;
419 fetched_++; 421 fetched_++;
420 } 422 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698