Example #1
0
 /**
  * Parse for loop
  *
  * for(<expr>;<expr>;<expr>) { ... }
  *
  * @param CodeGenerator $codeGenerator
  * @throws EndOfFileException
  * @throws ParserError
  * @throws PrecedenceException
  */
 public function parse_for(CodeGenerator $codeGenerator)
 {
     // 'for' eaten
     $this->check(T_LPARENTHESIS);
     $prec = new Precedence($this->scanner);
     $prec->run();
     //$codeGenerator->addVariables($prec->getUsedVariables());
     $initExpr = new ExprGenerator($prec->getData(), $codeGenerator->getScope());
     $prec = new Precedence($this->scanner);
     $prec->run();
     //$codeGenerator->addVariables($prec->getUsedVariables());
     $ifExpr = new ExprGenerator($prec->getData(), $codeGenerator->getScope());
     $prec = new Precedence($this->scanner);
     $prec->addEndToken(T_RPARENTHESIS);
     $prec->run();
     //$codeGenerator->addVariables($prec->getUsedVariables());
     $iterExpr = new ExprGenerator($prec->getData(), $codeGenerator->getScope());
     $this->check(T_RPARENTHESIS);
     $token = $this->scanner->next();
     $bodyCode = new CodeGenerator($codeGenerator->getIndent() + 1, $codeGenerator->getScope());
     if ($token['code'] == T_LCURLY_PARENTHESIS) {
         $this->parse_body($bodyCode);
         $this->check(T_RCURLY_PARENTHESIS);
     } else {
         $this->scanner->back();
         $this->parser_command($bodyCode);
     }
     $codeGenerator->addFor($initExpr, $ifExpr, $iterExpr, $bodyCode);
 }