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

Unified Diff: src/lexer/lexer.re

Issue 27177002: Experimental push model parser: Numbers. (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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/lexer/lexer.re
diff --git a/src/lexer/lexer.re b/src/lexer/lexer.re
index 0082f0afb052df2536697127c19f76885dcd4a40..370de928ae7e3dc92aa924eac4674741a3a4a020 100644
--- a/src/lexer/lexer.re
+++ b/src/lexer/lexer.re
@@ -4,6 +4,15 @@
#include <stdlib.h>
#include <string.h>
+
+/*
+TODO:
+- SpiderMonkey compatibility hack: " --> something" is treated as a single line comment.
+- An identifier cannot start immediately after a number.
+
+*/
+
+
/*!types:re2c */
#if defined(WIN32)
@@ -39,7 +48,6 @@
printf("\n"); \
SKIP(); }
#define PUSH_NUMBER() { \
- --cursor; \
printf("got number\n"); \
size_t tokenSize = cursor-start; \
fwrite(start, tokenSize, 1, stdout); \
@@ -289,9 +297,44 @@ public:
whitespace = whitespace_char+;
identifier_start = [$_\\a-zA-z];
identifier_char = [$_\\a-zA-z0-9];
- number_start = [0-9];
- number_char = [0-9\.e];
line_terminator = [\n\r]+;
+ digit = [0-9];
+ hex_digit = [0-9a-fA-F];
+ maybe_exponent = ('e' [-+]? digit+)?;
+
+ <Normal> "|=" { PUSH_TOKEN(ASSIGN_BIT_OR); }
+ <Normal> "^=" { PUSH_TOKEN(ASSIGN_BIT_XOR); }
+ <Normal> "&=" { PUSH_TOKEN(ASSIGN_BIT_AND); }
+ <Normal> "+=" { PUSH_TOKEN(ASSIGN_ADD); }
+ <Normal> "-=" { PUSH_TOKEN(ASSIGN_SUB); }
+ <Normal> "*=" { PUSH_TOKEN(ASSIGN_MUL); }
+ <Normal> "/=" { PUSH_TOKEN(ASSIGN_DIV); }
+ <Normal> "%=" { PUSH_TOKEN(ASSIGN_MOD); }
+
+ <Normal> "===" { PUSH_TOKEN(EQ_STRICT); }
+ <Normal> "==" { PUSH_TOKEN(EQ); }
+ <Normal> "=" { PUSH_TOKEN(ASSIGN); }
+ <Normal> "!==" { PUSH_TOKEN(NE_STRICT); }
+ <Normal> "!=" { PUSH_TOKEN(NE); }
+ <Normal> "!" { PUSH_TOKEN(NOT); }
+
+ <Normal> "//" :=> SingleLineComment
+ <Normal> "/*" :=> MultiLineComment
+ <Normal> "<!--" :=> HtmlComment
+
+ <Normal> ">>>=" { PUSH_TOKEN(ASSIGN_SHR); }
+ <Normal> "<<=" { PUSH_TOKEN(ASSIGN_SHL); }
+ <Normal> ">>=" { PUSH_TOKEN(ASSIGN_SAR); }
+ <Normal> "<=" { PUSH_TOKEN(LTE); }
+ <Normal> ">=" { PUSH_TOKEN(GTE); }
+ <Normal> "<<" { PUSH_TOKEN(SHL); }
+ <Normal> ">>" { PUSH_TOKEN(SAR); }
+ <Normal> "<" { PUSH_TOKEN(LT); }
+ <Normal> ">" { PUSH_TOKEN(GT); }
+
+ <Normal> '0x' hex_digit+ { PUSH_NUMBER(); }
+ <Normal> "." digit+ maybe_exponent { PUSH_NUMBER(); }
+ <Normal> digit+ ("." digit+)? maybe_exponent { PUSH_NUMBER(); }
<Normal> "(" { PUSH_TOKEN(LPAREN); }
<Normal> ")" { PUSH_TOKEN(RPAREN); }
@@ -306,58 +349,27 @@ public:
<Normal> "++" { PUSH_TOKEN(INC); }
<Normal> "--" { PUSH_TOKEN(DEC); }
- <Normal> "|=" { PUSH_TOKEN(ASSIGN_BIT_OR); }
- <Normal> "^=" { PUSH_TOKEN(ASSIGN_BIT_XOR); }
- <Normal> "&=" { PUSH_TOKEN(ASSIGN_BIT_AND); }
- <Normal> "<<=" { PUSH_TOKEN(ASSIGN_SHL); }
- <Normal> ">>=" { PUSH_TOKEN(ASSIGN_SAR); }
- <Normal> ">>>=" { PUSH_TOKEN(ASSIGN_SHR); }
- <Normal> "+=" { PUSH_TOKEN(ASSIGN_ADD); }
- <Normal> "-=" { PUSH_TOKEN(ASSIGN_SUB); }
- <Normal> "*=" { PUSH_TOKEN(ASSIGN_MUL); }
- <Normal> "/=" { PUSH_TOKEN(ASSIGN_DIV); }
- <Normal> "%=" { PUSH_TOKEN(ASSIGN_MOD); }
-
- <Normal> "," { PUSH_TOKEN(COMMA); }
<Normal> "||" { PUSH_TOKEN(OR); }
<Normal> "&&" { PUSH_TOKEN(AND); }
+
<Normal> "|" { PUSH_TOKEN(BIT_OR); }
<Normal> "^" { PUSH_TOKEN(BIT_XOR); }
<Normal> "&" { PUSH_TOKEN(BIT_AND); }
- <Normal> "<<" { PUSH_TOKEN(SHL); }
- <Normal> ">>" { PUSH_TOKEN(SAR); }
<Normal> "+" { PUSH_TOKEN(ADD); }
<Normal> "-" { PUSH_TOKEN(SUB); }
<Normal> "*" { PUSH_TOKEN(MUL); }
<Normal> "/" { PUSH_TOKEN(DIV); }
<Normal> "%" { PUSH_TOKEN(MOD); }
-
- <Normal> "===" { PUSH_TOKEN(EQ_STRICT); }
- <Normal> "==" { PUSH_TOKEN(EQ); }
- <Normal> "!==" { PUSH_TOKEN(NE_STRICT); }
- <Normal> "!=" { PUSH_TOKEN(NE); }
- <Normal> "<=" { PUSH_TOKEN(LTE); }
- <Normal> ">=" { PUSH_TOKEN(GTE); }
- <Normal> "<" { PUSH_TOKEN(LT); }
- <Normal> ">" { PUSH_TOKEN(GT); }
-
- <Normal> "=" { PUSH_TOKEN(ASSIGN); }
-
- <Normal> "!" { PUSH_TOKEN(NOT); }
<Normal> "~" { PUSH_TOKEN(BIT_NOT); }
+ <Normal> "," { PUSH_TOKEN(COMMA); }
<Normal> line_terminator+ { PUSH_LINE_TERMINATOR(); }
- <Normal> whitespace { SKIP();}
-
- <Normal> "//" :=> SingleLineComment
- <Normal> "/*" :=> MultiLineComment
- <Normal> "<!--" :=> HtmlComment
+ <Normal> whitespace { SKIP(); }
<Normal> ["] :=> DoubleQuoteString
<Normal> ['] :=> SingleQuoteString
<Normal> identifier_start :=> Identifier
- <Normal> number_start :=> Number
<Normal> eof { PUSH_EOS(); return 1; }
<Normal> any { TERMINATE_ILLEGAL(); }
@@ -384,10 +396,6 @@ public:
<HtmlComment> eof { TERMINATE_ILLEGAL(); }
<HtmlComment> "-->" { PUSH_LINE_TERMINATOR();}
<HtmlComment> any { goto yy0; }
-
- <Number> number_char+ { goto yy0; }
- <Number> any { PUSH_NUMBER(); }
-
*/
fill:
« 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