1
0

OPTIONを実装

This commit is contained in:
otya128
2016-09-02 20:57:36 +09:00
parent 2f50fc5ba9
commit 1bfb655e74
4 changed files with 64 additions and 2 deletions

View File

@@ -165,6 +165,8 @@ class Function
class Compiler
{
bool isDirectMode;
bool isDefint;
bool isStrictMode;
ValueType getType(wstring name)
{
wchar s = name[name.length - 1];
@@ -177,8 +179,10 @@ class Compiler
case '%':
return ValueType.Integer;
default:
return ValueType.Double;//非DEFINT時
//return ValueType.Integer;//DEFINT時
if (!isDefint)
return ValueType.Double;//DEFINT時
else
return ValueType.Integer;//DEFINT時
}
}
Statements statements;
@@ -437,6 +441,10 @@ class Compiler
{
//local変数をあたる
//それでもだめならOPTION STRICTならエラー
if (isStrictMode)
{
throw new UndefinedVariable();
}
this.global[name] = VMVariable(global = ++globalIndex, getType(name));
}
return global;
@@ -1088,6 +1096,24 @@ class Compiler
case NodeType.RepeatUntil:
compileRepeat(cast(RepeatUntil)i, s);
break;
case NodeType.Option:
if(isDirectMode)
{
throw new CantUseFromDirectMode();
}
else
{
auto option = cast(Option)i;
if (option.argument == "STRICT")
{
isStrictMode = true;
}
else if (option.argument == "DEFINT")
{
isDefint = true;
}
}
break;
default:
stderr.writeln("Compile:NotImpl ", i.type);
}

View File

@@ -80,6 +80,14 @@ class OutOfDATA : SmileBasicError
super("Out of DATA");
}
}
class UndefinedVariable : SmileBasicError
{
this()
{
this.errnum = 15;
super("Undefined variable");
}
}
class DuplicateVariable : SmileBasicError
{
this()

View File

@@ -42,6 +42,7 @@ enum NodeType
On,
Input,
RepeatUntil,
Option,
}
abstract class Node
{
@@ -578,3 +579,14 @@ class RepeatUntil : Statement
this.statements = statements;
}
}
class Option : Statement
{
wstring argument;
this(wstring arg, SourceLocation loc)
{
super.location = loc;
this.type = NodeType.Option;
argument = arg;
}
}

View File

@@ -847,6 +847,22 @@ class Parser
return node;
}
}
if (name == "OPTION")
{
if (token.type != TokenType.Iden)
{
syntaxError();
return null;
}
auto arg = std.uni.toUpper(token.value.stringValue);
if (arg != "STRICT" && arg != "DEFINT" && arg != "TOOL")
{
syntaxError();
return null;
}
lex.popFront();
return new Option(arg, lex.location);
}
//命令呼び出し
auto func = new CallFunctionStatement(name, lex.location);
node = func;