Fix parser error that made it ignore the last line
This commit is contained in:
parent
fda22052b8
commit
e2bb39006a
@ -20,6 +20,7 @@ class InstructionSet
|
|||||||
|
|
||||||
public function apply(Block $block): void
|
public function apply(Block $block): void
|
||||||
{
|
{
|
||||||
|
print("$block\n");
|
||||||
$words = $block->words;
|
$words = $block->words;
|
||||||
while ($word = array_shift($words)) {
|
while ($word = array_shift($words)) {
|
||||||
$method = "{$word}";
|
$method = "{$word}";
|
||||||
@ -32,7 +33,7 @@ class InstructionSet
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public function G22(Block $block): void
|
protected function G22(Block $block): void
|
||||||
{
|
{
|
||||||
$number = $block->valueOf('X');
|
$number = $block->valueOf('X');
|
||||||
$this->machine->SPMC->loadProgram($number);
|
$this->machine->SPMC->loadProgram($number);
|
||||||
|
@ -40,12 +40,10 @@ class Machine
|
|||||||
|
|
||||||
public function step(): void
|
public function step(): void
|
||||||
{
|
{
|
||||||
$block = $this->AMC->next();
|
if ($this->AMC === $this->SPMC && count($this->AMC) === 0) {
|
||||||
if (is_null($block) && $this->AMC === $this->SPMC) {
|
|
||||||
// SP ended, back to PP
|
|
||||||
$this->AMC = $this->PPMC;
|
$this->AMC = $this->PPMC;
|
||||||
$block = $this->AMC->next();
|
|
||||||
}
|
}
|
||||||
|
$block = $this->AMC->next();
|
||||||
$this->IS->apply($block);
|
$this->IS->apply($block);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -61,7 +61,7 @@ class ProgramParser
|
|||||||
}
|
}
|
||||||
$program = new Program($firstWord->value);
|
$program = new Program($firstWord->value);
|
||||||
$lineBuffer = null;
|
$lineBuffer = null;
|
||||||
foreach ($words as $word) {
|
while ($word = array_shift($words)) {
|
||||||
if ($word->register === 'N') {
|
if ($word->register === 'N') {
|
||||||
if (!is_null($lineBuffer)) {
|
if (!is_null($lineBuffer)) {
|
||||||
$program->addBlock($lineBuffer);
|
$program->addBlock($lineBuffer);
|
||||||
@ -71,6 +71,9 @@ class ProgramParser
|
|||||||
}
|
}
|
||||||
$lineBuffer->addWord($word);
|
$lineBuffer->addWord($word);
|
||||||
}
|
}
|
||||||
|
if (!is_null($lineBuffer)) {
|
||||||
|
$program->addBlock($lineBuffer);
|
||||||
|
}
|
||||||
|
|
||||||
return $program;
|
return $program;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user