1
0

IFの構文解析

This commit is contained in:
otya128
2015-06-06 17:11:02 +09:00
parent 2eaab2ef55
commit 5cab924046
6 changed files with 160 additions and 10 deletions

View File

@@ -51,6 +51,8 @@ enum CodeType
Print,
PopG,
GotoS,
GotoFalse,
GotoTrue,
}
abstract class Code
{
@@ -194,6 +196,38 @@ class GotoS : Code
stderr.writeln("can't execute");
}
}
class GotoTrue : Code
{
int address;
this(int addr)
{
this.type = CodeType.GotoTrue;
address = addr;
}
override void execute(VM vm)
{
Value cond;
vm.pop(cond);
if(cond.boolValue)
vm.pc = address - 1;
}
}
class GotoFalse : Code
{
int address;
this(int addr)
{
this.type = CodeType.GotoFalse;
address = addr;
}
override void execute(VM vm)
{
Value cond;
vm.pop(cond);
if(!cond.boolValue)
vm.pc = address - 1;
}
}
class Gosub : Code
{