本文整理汇总了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();
}
}