Exemple #1
0
 protected function walkFor(ForNode $for)
 {
     $ret = "for (\${$for->getVariableName()} = ";
     $ret .= $this->walk($for->getFrom()) . ", ";
     $toSym = $this->gensym();
     $ret .= "{$toSym} = " . $this->walk($for->getTo()) . ", ";
     $iterationsSym = $this->gensym();
     $ret .= "{$iterationsSym} = 0; ";
     $ret .= "\${$for->getVariableName()} <= {$toSym}; ";
     $ret .= "\${$for->getVariableName()} += " . ($for->getStep() === null ? "1" : $this->walk($for->getStep()));
     $ret .= ", ++{$iterationsSym}) {" . implode("", $this->walkEach((array) $for->getBody())) . "}";
     $ret .= "if ({$iterationsSym} < 1) {" . implode("", $this->walkEach((array) $for->getElseBody())) . "}";
     return $ret;
 }
 protected function walkFor(ForNode $for)
 {
     return new ForNode($for->getVariableName(), $for->getFrom(), $for->getTo(), $for->getStep(), $this->walkEach($for->getBody()), $this->walkEach($for->getElseBody()));
 }