本文整理匯總了PHP中Program::getStatement方法的典型用法代碼示例。如果您正苦於以下問題:PHP Program::getStatement方法的具體用法?PHP Program::getStatement怎麽用?PHP Program::getStatement使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Program
的用法示例。
在下文中一共展示了Program::getStatement方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: writeProgram
/**
* Write a program to a file
*
* @param Program $prog
* @param string $filename
*/
public static function writeProgram(Program $prog, $filename)
{
if ($handle = fopen($filename, 'w')) {
for ($k = 0; $k < $prog->getStatementCount(); $k++) {
fprintf($handle, "%s\n", $prog->getStatement($k)->dumpWamCode());
}
$handle = fclose($handle);
}
return $handle;
}
示例2: addClause
public function addClause($label, Program $code)
{
$line = $this->getLastClauseOf($label);
if ($line >= 0) {
// there already exists such a label: add via try_me_else
$s = $this->getStatement($line);
$index = strpos($s->getLabel(), '~');
try {
//int i;
if ($index > 0) {
$i = 1 + substr($s->getLabel(), $index + 1);
} else {
$i = 2;
}
// update the just-compiled program
$newLabel = $label . "~" . $i;
$code->getStatement(0)->setLabel($newLabel);
// update the previous clause: trust_me -> try_me_else
$s->setFunction("try_me_else");
$s->setArgAt($newLabel, 0);
$s->arg1 = $newLabel;
$s->setJump(count($this->statements));
// update labels and program itself
$this->addProgram($code);
} catch (\Exception $e) {
// TODO maybe do something ?
}
} else {
// first label of that kind: just add to code and update jumpings
$this->addProgram($code);
$this->updateLabels();
}
}