diff -r af5d8e985502 -r 765ab1b672a3 jitcraft/Parser.cpp --- a/jitcraft/Parser.cpp Sun Jul 01 14:52:57 2012 -0700 +++ b/jitcraft/Parser.cpp Sun Jul 01 16:36:39 2012 -0700 @@ -356,9 +356,27 @@ } Expression * +Parser::assignment() +{ + Expression *left = equals(); + while (left) { + TokenKind token = scanner_.peek(); + if (token != TOK_ASSIGN && (token < TOK_ASSIGN_ADD || token > TOK_ASSIGN_SHL)) + break; + scanner_.scan(); + Expression *expr = equals(); + if (!expr) + return NULL; + + left = new (pool_) Assignment(token, left, expr); + } + return left; +} + +Expression * Parser::expression() { - return equals(); + return assignment(); } Statement * @@ -411,12 +429,17 @@ if (!expect(TOK_LPAREN)) return NULL; - VariableDeclaration *decl = NULL; + Statement *decl = NULL; if (!match(TOK_SEMICOLON)) { - if (!enterScope(Scope::BLOCK)) - return NULL; - if ((decl = variableDeclaration()) == NULL) - return NULL; + if (scanner_.peek() == TOK_NEW) { + if (!enterScope(Scope::BLOCK)) + return NULL; + if ((decl = variableDeclaration()) == NULL) + return NULL; + } else { + if ((decl = expressionStatement()) == NULL) + return NULL; + } if (!expect(TOK_SEMICOLON)) return NULL; } @@ -442,7 +465,7 @@ return NULL; Scope *blockScope = NULL; - if (decl) { + if (decl && decl->isVariableDeclaration()) { blockScope = scope_->unlinkIfEmpty(); scope_ = scope_->enclosing(); } @@ -511,18 +534,10 @@ Statement * Parser::expressionStatement() { - Expression *left = primary(); + Expression *left = assignment(); if (!left) return NULL; - if (match(TOK_ASSIGN)) { - Expression *expr = expression(); - if (!expr) - return NULL; - - left = new (pool_) Assignment(left, expr); - } - return new (pool_) ExpressionStatement(left); } @@ -908,8 +923,8 @@ prefix(); fprintf(fp_, "[ ForStatement\n"); indent(); - if (node->declaration()) - node->declaration()->accept(this); + if (node->initialization()) + node->initialization()->accept(this); if (node->condition()) node->condition()->accept(this); if (node->update())