OPTIONを実装
This commit is contained in:
@@ -165,6 +165,8 @@ class Function
|
|||||||
class Compiler
|
class Compiler
|
||||||
{
|
{
|
||||||
bool isDirectMode;
|
bool isDirectMode;
|
||||||
|
bool isDefint;
|
||||||
|
bool isStrictMode;
|
||||||
ValueType getType(wstring name)
|
ValueType getType(wstring name)
|
||||||
{
|
{
|
||||||
wchar s = name[name.length - 1];
|
wchar s = name[name.length - 1];
|
||||||
@@ -177,8 +179,10 @@ class Compiler
|
|||||||
case '%':
|
case '%':
|
||||||
return ValueType.Integer;
|
return ValueType.Integer;
|
||||||
default:
|
default:
|
||||||
|
if (!isDefint)
|
||||||
return ValueType.Double;//非DEFINT時
|
return ValueType.Double;//非DEFINT時
|
||||||
//return ValueType.Integer;//DEFINT時
|
else
|
||||||
|
return ValueType.Integer;//DEFINT時
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Statements statements;
|
Statements statements;
|
||||||
@@ -437,6 +441,10 @@ class Compiler
|
|||||||
{
|
{
|
||||||
//local変数をあたる
|
//local変数をあたる
|
||||||
//それでもだめならOPTION STRICTならエラー
|
//それでもだめならOPTION STRICTならエラー
|
||||||
|
if (isStrictMode)
|
||||||
|
{
|
||||||
|
throw new UndefinedVariable();
|
||||||
|
}
|
||||||
this.global[name] = VMVariable(global = ++globalIndex, getType(name));
|
this.global[name] = VMVariable(global = ++globalIndex, getType(name));
|
||||||
}
|
}
|
||||||
return global;
|
return global;
|
||||||
@@ -1088,6 +1096,24 @@ class Compiler
|
|||||||
case NodeType.RepeatUntil:
|
case NodeType.RepeatUntil:
|
||||||
compileRepeat(cast(RepeatUntil)i, s);
|
compileRepeat(cast(RepeatUntil)i, s);
|
||||||
break;
|
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:
|
default:
|
||||||
stderr.writeln("Compile:NotImpl ", i.type);
|
stderr.writeln("Compile:NotImpl ", i.type);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -80,6 +80,14 @@ class OutOfDATA : SmileBasicError
|
|||||||
super("Out of DATA");
|
super("Out of DATA");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
class UndefinedVariable : SmileBasicError
|
||||||
|
{
|
||||||
|
this()
|
||||||
|
{
|
||||||
|
this.errnum = 15;
|
||||||
|
super("Undefined variable");
|
||||||
|
}
|
||||||
|
}
|
||||||
class DuplicateVariable : SmileBasicError
|
class DuplicateVariable : SmileBasicError
|
||||||
{
|
{
|
||||||
this()
|
this()
|
||||||
|
|||||||
@@ -42,6 +42,7 @@ enum NodeType
|
|||||||
On,
|
On,
|
||||||
Input,
|
Input,
|
||||||
RepeatUntil,
|
RepeatUntil,
|
||||||
|
Option,
|
||||||
}
|
}
|
||||||
abstract class Node
|
abstract class Node
|
||||||
{
|
{
|
||||||
@@ -578,3 +579,14 @@ class RepeatUntil : Statement
|
|||||||
this.statements = statements;
|
this.statements = statements;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class Option : Statement
|
||||||
|
{
|
||||||
|
wstring argument;
|
||||||
|
this(wstring arg, SourceLocation loc)
|
||||||
|
{
|
||||||
|
super.location = loc;
|
||||||
|
this.type = NodeType.Option;
|
||||||
|
argument = arg;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -847,6 +847,22 @@ class Parser
|
|||||||
return node;
|
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);
|
auto func = new CallFunctionStatement(name, lex.location);
|
||||||
node = func;
|
node = func;
|
||||||
|
|||||||
Reference in New Issue
Block a user