From de5db9282c0a943acfe6480c7ee461fe9560d54b Mon Sep 17 00:00:00 2001 From: otya128 Date: Thu, 4 Jun 2015 20:51:03 +0900 Subject: [PATCH] =?UTF-8?q?=E3=83=91=E3=83=BC=E3=82=B5=E3=83=BC=E3=81=AE?= =?UTF-8?q?=E3=83=90=E3=82=B0=E4=BF=AE=E6=AD=A3,Comipler=E3=82=92=E5=AE=9A?= =?UTF-8?q?=E7=BE=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- SMILEBASIC/SMILEBASIC.visualdproj | 1 + SMILEBASIC/VM.d | 2 +- SMILEBASIC/compiler.d | 25 +++++++++++++++++++++++++ SMILEBASIC/parser.d | 9 +++++++-- 4 files changed, 34 insertions(+), 3 deletions(-) create mode 100644 SMILEBASIC/compiler.d diff --git a/SMILEBASIC/SMILEBASIC.visualdproj b/SMILEBASIC/SMILEBASIC.visualdproj index 8dffa98..a36e6c6 100644 --- a/SMILEBASIC/SMILEBASIC.visualdproj +++ b/SMILEBASIC/SMILEBASIC.visualdproj @@ -205,6 +205,7 @@ *.obj;*.cmd;*.build;*.json;*.dep + diff --git a/SMILEBASIC/VM.d b/SMILEBASIC/VM.d index d462f59..3107dee 100644 --- a/SMILEBASIC/VM.d +++ b/SMILEBASIC/VM.d @@ -1,4 +1,4 @@ -module otya.smilebasic.VM; +module otya.smilebasic.vm; class VM { } diff --git a/SMILEBASIC/compiler.d b/SMILEBASIC/compiler.d new file mode 100644 index 0000000..0051ac0 --- /dev/null +++ b/SMILEBASIC/compiler.d @@ -0,0 +1,25 @@ +module otya.smilebasic.compiler; +import otya.smilebasic.node; +import otya.smilebasic.vm; +import std.stdio; +class Compiler +{ + Statements statements; + this(Statements statements) + { + this.statements = statements; + } + + void compile() + { + Code[] code = new Code[0]; + foreach(Statement i ; statements.statements) + { + switch(i.type) + { + default: + stderr.writeln("Compile:NotImpl ", i.type); + } + } + } +} diff --git a/SMILEBASIC/parser.d b/SMILEBASIC/parser.d index 487211e..ab15f0e 100644 --- a/SMILEBASIC/parser.d +++ b/SMILEBASIC/parser.d @@ -2,6 +2,7 @@ module otya.smilebasic.parser; import otya.smilebasic.token; import otya.smilebasic.type; import otya.smilebasic.node; +import otya.smilebasic.compiler; import std.ascii; import std.stdio; class Lexical @@ -97,6 +98,7 @@ class Lexical if(r != TokenType.Unknown) { token = Token(r); + break; } } token = Token(TokenType.Iden, Value(iden)); @@ -260,6 +262,8 @@ class Parser } void compile() { + auto compiler = new Compiler(parseProgram()); + compiler.compile(); } Statements parseProgram() { @@ -278,7 +282,7 @@ class Parser } void syntaxError() { - stderr.writeln("Syntax error", lex.getLine()); + stderr.writeln("Syntax error (", lex.getLine(), ')'); } //statement Statement statement() @@ -322,13 +326,14 @@ class Parser print.addArgument(exp); lex.popFront(); token = lex.front(); + if(lex.empty()) break; if(token.type != TokenType.Colon && token.type != TokenType.NewLine && token.type != TokenType.Semicolon && token.type != TokenType.Comma) { syntaxError(); } } + return print; } - break; case TokenType.Colon: case TokenType.NewLine: break;