diff --git a/SMILEBASIC/compiler.d b/SMILEBASIC/compiler.d index 5c61720..2cad417 100644 --- a/SMILEBASIC/compiler.d +++ b/SMILEBASIC/compiler.d @@ -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); } diff --git a/SMILEBASIC/error.d b/SMILEBASIC/error.d index 42730de..dd36186 100644 --- a/SMILEBASIC/error.d +++ b/SMILEBASIC/error.d @@ -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() diff --git a/SMILEBASIC/node.d b/SMILEBASIC/node.d index 4d49af4..9169a19 100644 --- a/SMILEBASIC/node.d +++ b/SMILEBASIC/node.d @@ -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; + } +} diff --git a/SMILEBASIC/parser.d b/SMILEBASIC/parser.d index 391ecac..402f25d 100644 --- a/SMILEBASIC/parser.d +++ b/SMILEBASIC/parser.d @@ -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;