public virtual Statement visit(ForInStatement statement) { writeIndent(); write("for ("); statement.variable.visitExpression(this); write(" in "); statement.expression.visitExpression(this); write(")"); statement.statement.visitStatement(this); return(statement); }
public virtual Statement visit(ForInStatement statement) { write("for in (line = " + statement.getLineNumber() + ")"); return(statement); }
private Statement parseForStatement() { Expression declaration = null; Expression initial = null; Expression condition = null; Expression increment = null; Expression variable = null; Expression expression = null; Statement statement = null; // 'for' statements can be one of the follow four productions: // // for ( ExpressionNoIn_opt; Expression_opt ; Expression_opt ) Statement // for ( var VariableDeclarationListNoIn; Expression_opt ; Expression_opt ) Statement // for ( LeftHandSideExpression in Expression ) Statement // for ( var VariableDeclarationNoIn in Expression ) Statement readToken(Token.KEYWORD_FOR); readToken(Token.OPERATOR_OPENPAREN); int state = 0; while (statement == null) { switch (state) { case 0: // initial state if (nextToken == Token.KEYWORD_VAR) { state = 1; } else if (nextToken != Token.OPERATOR_SEMICOLON) { state = 2; } else { state = 5; } break; case 1: // 'for' '(' 'var' readToken(Token.KEYWORD_VAR); declaration = parseVariableDeclaration(false); if (nextToken == Token.KEYWORD_IN) { variable = declaration; state = 3; } else { state = 4; } break; case 2: // 'for' '(' Expression initial = parseExpression(false); if (nextToken == Token.KEYWORD_IN) { variable = initial; state = 3; } else { state = 5; } break; case 3: // 'for' '(' ... 'in' readToken(Token.KEYWORD_IN); expression = parseExpression(true); readToken(Token.OPERATOR_CLOSEPAREN); // 'for' '(' ... 'in' ... ')' Statement statement = new ForInStatement(variable, expression, parseStatement()); break; case 4: // 'for' '(' 'var' VariableDeclarationList ArrayList declarationVector = new ArrayList(); declarationVector.Add(declaration); while (nextToken == Token.OPERATOR_COMMA) { readToken(Token.OPERATOR_COMMA); declarationVector.Add(parseVariableDeclaration(false)); } initial = new VariableExpression(CompilerUtil.vectorToDeclarationArray(declarationVector)); // fall through goto case 5; case 5: // 'for' '(' ... ';' readToken(Token.OPERATOR_SEMICOLON); // 'for' '(' ... ';' ... if (nextToken != Token.OPERATOR_SEMICOLON) { condition = parseExpression(true); } // 'for' '(' ... ';' ... ';' readToken(Token.OPERATOR_SEMICOLON); // 'for' '(' ... ';' ... ';' ... if (nextToken != Token.OPERATOR_CLOSEPAREN) { increment = parseExpression(true); } // 'for' '(' ... ';' ... ';' ... ')' readToken(Token.OPERATOR_CLOSEPAREN); // 'for' '(' ... ';' ... ';' ... ')' Statement statement = new ForStatement(initial, condition, increment, parseStatement()); break; } } return statement; }