From 6673ca3fc2745502cdb4731c889bf885451a938b Mon Sep 17 00:00:00 2001 From: otya128 Date: Wed, 3 Jun 2015 19:51:42 +0900 Subject: [PATCH] init --- SMILEBASIC.sln | 22 +++ SMILEBASIC/SMILEBASIC.visualdproj | 217 ++++++++++++++++++++++++++++++ SMILEBASIC/main.d | 6 + SMILEBASIC/node.d | 38 ++++++ SMILEBASIC/parser.d | 99 ++++++++++++++ SMILEBASIC/token.d | 30 +++++ SMILEBASIC/type.d | 37 +++++ 7 files changed, 449 insertions(+) create mode 100644 SMILEBASIC.sln create mode 100644 SMILEBASIC/SMILEBASIC.visualdproj create mode 100644 SMILEBASIC/main.d create mode 100644 SMILEBASIC/node.d create mode 100644 SMILEBASIC/parser.d create mode 100644 SMILEBASIC/token.d create mode 100644 SMILEBASIC/type.d diff --git a/SMILEBASIC.sln b/SMILEBASIC.sln new file mode 100644 index 0000000..745c885 --- /dev/null +++ b/SMILEBASIC.sln @@ -0,0 +1,22 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio 2013 +VisualStudioVersion = 12.0.31101.0 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{002A2DE9-8BB6-484D-9802-7E4AD4084715}") = "SMILEBASIC", "SMILEBASIC\SMILEBASIC.visualdproj", "{02748C89-9CEB-48FE-B711-36F7A9951ED8}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Win32 = Debug|Win32 + Release|Win32 = Release|Win32 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {02748C89-9CEB-48FE-B711-36F7A9951ED8}.Debug|Win32.ActiveCfg = Debug|Win32 + {02748C89-9CEB-48FE-B711-36F7A9951ED8}.Debug|Win32.Build.0 = Debug|Win32 + {02748C89-9CEB-48FE-B711-36F7A9951ED8}.Release|Win32.ActiveCfg = Release|Win32 + {02748C89-9CEB-48FE-B711-36F7A9951ED8}.Release|Win32.Build.0 = Release|Win32 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff --git a/SMILEBASIC/SMILEBASIC.visualdproj b/SMILEBASIC/SMILEBASIC.visualdproj new file mode 100644 index 0000000..177f927 --- /dev/null +++ b/SMILEBASIC/SMILEBASIC.visualdproj @@ -0,0 +1,217 @@ + + {02748C89-9CEB-48FE-B711-36F7A9951ED8} + + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 1 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 2.043 + 0 + 0 + 0 + 0 + 0 + $(CC) -c + 1 + $(DMDInstallDir)windows\bin\dmd.exe + + + $(ConfigurationName) + $(OutDir) + + + 0 + + + + + 0 + + + 1 + $(IntDir)\$(TargetName).json + 0 + + 0 + + 0 + 0 + 0 + + + + 0 + + 1 + $(VisualDInstallDir)cv2pdb\cv2pdb.exe + 0 + 0 + 0 + + + + + + + + $(OutDir)\$(ProjectName).exe + 1 + 2 + 0 + + + + *.obj;*.cmd;*.build;*.json;*.dep + + + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 1 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 2.043 + 0 + 0 + 0 + 0 + 0 + $(CC) -c + 1 + $(DMDInstallDir)windows\bin\dmd.exe + + + $(ConfigurationName) + $(OutDir) + + + 0 + + + + + 0 + + + 1 + $(IntDir)\$(TargetName).json + 0 + + 0 + + 0 + 0 + 0 + + + + 0 + + 0 + $(VisualDInstallDir)cv2pdb\cv2pdb.exe + 0 + 0 + 0 + + + + + + + + $(OutDir)\$(ProjectName).exe + 1 + 1 + 0 + + + + *.obj;*.cmd;*.build;*.json;*.dep + + + + + + + + + + + + diff --git a/SMILEBASIC/main.d b/SMILEBASIC/main.d new file mode 100644 index 0000000..5c41e9f --- /dev/null +++ b/SMILEBASIC/main.d @@ -0,0 +1,6 @@ +import std.stdio; +int main(string[] argv) +{ + writeln("Hello D-World!"); + return 0; +} diff --git a/SMILEBASIC/node.d b/SMILEBASIC/node.d new file mode 100644 index 0000000..c12e8e5 --- /dev/null +++ b/SMILEBASIC/node.d @@ -0,0 +1,38 @@ +module otya.smilebasic.node; +import otya.smilebasic.type; +import otya.smilebasic.token; +enum NodeType +{ + Node = 0b1, + Expression, + Constant, + BinaryOperator, +} +abstract class Node +{ + NodeType type; +} +abstract class Expression : Node +{ +} +class Constant : Expression +{ + Value value; + this(Value v) + { + this.value = v; + } +} +class BinaryOperator : Expression +{ + Expression item1; + TokenType operator; + Expression item2; + this(Expression i1, TokenType o, Expression i2) + { + this.type = NodeType.BinaryOperator; + this.item1 = i1; + this.operator = o; + this.item2 = i2; + } +} diff --git a/SMILEBASIC/parser.d b/SMILEBASIC/parser.d new file mode 100644 index 0000000..0cfbc60 --- /dev/null +++ b/SMILEBASIC/parser.d @@ -0,0 +1,99 @@ +module otya.smilebasic.parser; +import otya.smilebasic.token; +import otya.smilebasic.type; +import otya.smilebasic.node; +import std.ascii; +class Lexical +{ + wstring code; + int index; + this(wstring input) + { + this.code = input; + } + bool empty() + { + return index >= code.length; + } + Token token; + void popFront() + { + int i = index; + for(;i < code.length;i++) + { + wchar c = code[i]; + if(c == ' ') continue; + if(c.isDigit()) + { + int num; + for(;i < code.length;i++) + { + c = code[i]; + if(!c.isDigit()) + { + break; + } + num = num * 10 + (c - '0'); + } + token = Token(TokenType.Integer, Value(num)); + break; + } + //error + + break; + } + index = i; + } + Token front() + { + return token; + } +} +unittest +{ + auto lex = new Lexical("1"); + +} +class Parser +{ + wstring code; + Lexical lex; + this(wstring input) + { + this.code = input; + lex = new Lexical(input); + } + int getOPRank(TokenType type) + { + switch(type) + { +// return 8;//&&,|| + case TokenType.And: + case TokenType.Or: + case TokenType.Xor: + return 7;//AND,OR,XOR + +// return 6;//==,!=,<,<=,>,>= + +// return 5;//<<,>> + case TokenType.Plus: + case TokenType.Minus: + return 4;//+,-(bin) + case TokenType.Mul: + case TokenType.Div: +// return 3;//*,/,DIV,MOD +// return 2;//-,NOT,! +// return 1;//() + default: + return 0;//TODO:エラーにすべきかは実装次第 + } + } + void expression(Expression node) + { + term(8, node); + } + void term(int order, Expression node) + { + + } +} diff --git a/SMILEBASIC/token.d b/SMILEBASIC/token.d new file mode 100644 index 0000000..532e3d3 --- /dev/null +++ b/SMILEBASIC/token.d @@ -0,0 +1,30 @@ +module otya.smilebasic.token; +import otya.smilebasic.type; +enum TokenType +{ + Unknown, + Integer, + Double, + String, + Plus, + Minus, + Mul, + Div, + Mod, + Or, + And, + Xor, + Print, + If, +} + +struct Token +{ + TokenType type; + Value value; + this(TokenType t, Value v) + { + type = t; + value = v; + } +} diff --git a/SMILEBASIC/type.d b/SMILEBASIC/type.d new file mode 100644 index 0000000..a28e768 --- /dev/null +++ b/SMILEBASIC/type.d @@ -0,0 +1,37 @@ +module otya.smilebasic.type; +enum ValueType : byte +{ + Integer, + Double, + String, + Array, + IntegerArray, + DoubleArray, + StringArray, +} +struct Value +{ + ValueType type; + union + { + int integerValue; + double doubleValue; + wstring stringValue; + int[] intArray; + } + this(int value) + { + this.type = ValueType.Integer; + integerValue = value; + } + this(double value) + { + this.type = ValueType.Double; + doubleValue = value; + } + this(wstring value) + { + this.type = ValueType.String; + stringValue = value; + } +}