void ProgramCompiler::Formatter::visit(Iteration &iter)
{
formatted += "for(";
- iter.init_statement->visit(*this);
- formatted += ' ';
- iter.condition->visit(*this);
- formatted += "; ";
- iter.loop_expression->visit(*this);
- formatted += ")\n";
+ if(iter.init_statement)
+ iter.init_statement->visit(*this);
+ else
+ formatted += ';';
+ if(iter.condition)
+ {
+ formatted += ' ';
+ iter.condition->visit(*this);
+ }
+ formatted += ';';
+ if(iter.loop_expression)
+ {
+ formatted += ' ';
+ iter.loop_expression->visit(*this);
+ }
+ formatted += ')';
iter.body.visit(*this);
}
loop->init_statement = parse_statement();
else
{
- RefPtr<ExpressionStatement> expr = new ExpressionStatement;
- expr->expression = parse_expression();
+ if(token!=";")
+ {
+ RefPtr<ExpressionStatement> expr = new ExpressionStatement;
+ expr->expression = parse_expression();
+ loop->init_statement = expr;
+ }
expect(";");
- loop->init_statement = expr;
}
- loop->condition = parse_expression();
+ if(peek_token()!=";")
+ loop->condition = parse_expression();
expect(";");
- loop->loop_expression = parse_expression();
+ if(peek_token()!=")")
+ loop->loop_expression = parse_expression();
expect(")");
parse_block(loop->body, false);
void TraversingVisitor::visit(Iteration &iter)
{
- iter.init_statement->visit(*this);
+ if(iter.init_statement)
+ iter.init_statement->visit(*this);
if(iter.condition)
iter.condition->visit(*this);
if(iter.loop_expression)