ref: 228cbca9bef303fa5123346d7e3bd32d74e37eef
parent: 4eb3349511ca6bc22c90765f4e96e974ef3bb019
author: Tor Andersson <tor@ccxvii.net>
date: Fri Jan 10 06:23:45 EST 2014
Reorder statement cases to align with spec text.
--- a/js-parse.c
+++ b/js-parse.c
@@ -557,10 +557,51 @@
return block(J);
}
+ if (accept(J, TK_VAR)) {
+ a = vardeclist(J, 0);
+ semicolon(J);
+ return STM1(VAR, a);
+ }
+
+ /* empty statement */
if (accept(J, ';')) {
return STM0(NOP);
}
+ if (accept(J, TK_IF)) {
+ expect(J, '(');
+ a = expression(J, 0);
+ expect(J, ')');
+ b = statement(J);
+ if (accept(J, TK_ELSE))
+ c = statement(J);
+ else
+ c = NULL;
+ return STM3(IF, a, b, c);
+ }
+
+ if (accept(J, TK_DO)) {
+ a = statement(J);
+ expect(J, TK_WHILE);
+ expect(J, '(');
+ b = expression(J, 0);
+ expect(J, ')');
+ semicolon(J);
+ return STM2(DO, a, b);
+ }
+
+ if (accept(J, TK_WHILE)) {
+ expect(J, '(');
+ a = expression(J, 0);
+ expect(J, ')');
+ b = statement(J);
+ return STM2(WHILE, a, b);
+ }
+
+ if (accept(J, TK_FOR)) {
+ return forstatement(J);
+ }
+
if (accept(J, TK_CONTINUE)) {
a = identifieropt(J);
semicolon(J);
@@ -590,6 +631,16 @@
return STM2(WITH, a, b);
}
+ if (accept(J, TK_SWITCH)) {
+ expect(J, '(');
+ a = expression(J, 0);
+ expect(J, ')');
+ expect(J, '{');
+ b = caselist(J);
+ expect(J, '}');
+ return STM2(SWITCH, a, b);
+ }
+
if (accept(J, TK_THROW)) {
a = expression(J, 0);
semicolon(J);
@@ -618,58 +669,7 @@
return STM0(DEBUGGER);
}
- if (accept(J, TK_IF)) {
- expect(J, '(');
- a = expression(J, 0);
- expect(J, ')');
- b = statement(J);
- if (accept(J, TK_ELSE))
- c = statement(J);
- else
- c = NULL;
- return STM3(IF, a, b, c);
- }
-
- if (accept(J, TK_DO)) {
- a = statement(J);
- expect(J, TK_WHILE);
- expect(J, '(');
- b = expression(J, 0);
- expect(J, ')');
- semicolon(J);
- return STM2(DO, a, b);
- }
-
- if (accept(J, TK_WHILE)) {
- expect(J, '(');
- a = expression(J, 0);
- expect(J, ')');
- b = statement(J);
- return STM2(WHILE, a, b);
- }
-
- if (accept(J, TK_VAR)) {
- a = vardeclist(J, 0);
- semicolon(J);
- return STM1(VAR, a);
- }
-
- if (accept(J, TK_FOR)) {
- return forstatement(J);
- }
-
- if (accept(J, TK_SWITCH)) {
- expect(J, '(');
- a = expression(J, 0);
- expect(J, ')');
- expect(J, '{');
- b = caselist(J);
- expect(J, '}');
- return STM2(SWITCH, a, b);
- }
-
- /* LabelledStatement : Identifier ':' Statement */
- /* ExpressionStatement : Expression ';' */
+ /* labelled statement or expression statement */
if (J->lookahead == TK_IDENTIFIER) {
a = expression(J, 0);
if (a->type == AST_IDENTIFIER && accept(J, ':')) {
@@ -680,8 +680,8 @@
return a;
}
- /* ExpressionStatement : [lookahead not 'function' or '{'] Expression ';' */
- if (J->lookahead != TK_FUNCTION && J->lookahead != '{') {
+ /* expression statement */
+ if (J->lookahead != TK_FUNCTION) {
a = expression(J, 0);
semicolon(J);
return a;