Пример #1
0
 public function parse_foreach(CodeGenerator $codeGenerator)
 {
     // 'foreach' eaten
     $this->check(T_LPARENTHESIS);
     $prec = new Precedence($this->scanner);
     $prec->addEndToken(T_AS);
     $prec->run();
     $source = new ExprGenerator($prec->getData(), $codeGenerator->getScope());
     $this->check(T_AS);
     $token = $this->scanner->next(TRUE);
     if ($token['code'] != T_VARIABLE) {
         throw new ParserError($token, T_VARIABLE);
     }
     $varName = $token['value'];
     $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->addForeach($source, $varName, $bodyCode);
 }