/** * if(<expr>) [{] <code> [}] [elseif(<expr>) { <code> }]+ [else { <code> }] * * @param $codeGenerator */ public function parse_if(CodeGenerator $codeGenerator) { // 'if' eaten $prec = new Precedence($this->scanner); $prec->run(); // If $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->addIf(new ExprGenerator($prec->getData(), $codeGenerator->getScope()), $bodyCode); //$codeGenerator->addVariables($prec->getUsedVariables()); // Elseif $token = $this->scanner->next(); while ($token['code'] == T_ELSEIF) { $prec = new Precedence($this->scanner); $prec->run(); $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->addVariables($prec->getUsedVariables()); $codeGenerator->addElseif(new ExprGenerator($prec->getData(), $codeGenerator->getScope()), $bodyCode); $token = $this->scanner->next(); } // else if ($token['code'] == T_ELSE) { $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->addVariables($prec->getUsedVariables()); $codeGenerator->addElse($bodyCode); } else { $this->scanner->back(); } }