パーサーのバグ修正,Comiplerを定義
This commit is contained in:
@@ -205,6 +205,7 @@
|
|||||||
<filesToClean>*.obj;*.cmd;*.build;*.json;*.dep</filesToClean>
|
<filesToClean>*.obj;*.cmd;*.build;*.json;*.dep</filesToClean>
|
||||||
</Config>
|
</Config>
|
||||||
<Folder name="SMILEBASIC">
|
<Folder name="SMILEBASIC">
|
||||||
|
<File path="compiler.d" />
|
||||||
<File path="main.d" />
|
<File path="main.d" />
|
||||||
<File path="node.d" />
|
<File path="node.d" />
|
||||||
<File path="parser.d" />
|
<File path="parser.d" />
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
module otya.smilebasic.VM;
|
module otya.smilebasic.vm;
|
||||||
class VM
|
class VM
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|||||||
25
SMILEBASIC/compiler.d
Normal file
25
SMILEBASIC/compiler.d
Normal file
@@ -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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -2,6 +2,7 @@ module otya.smilebasic.parser;
|
|||||||
import otya.smilebasic.token;
|
import otya.smilebasic.token;
|
||||||
import otya.smilebasic.type;
|
import otya.smilebasic.type;
|
||||||
import otya.smilebasic.node;
|
import otya.smilebasic.node;
|
||||||
|
import otya.smilebasic.compiler;
|
||||||
import std.ascii;
|
import std.ascii;
|
||||||
import std.stdio;
|
import std.stdio;
|
||||||
class Lexical
|
class Lexical
|
||||||
@@ -97,6 +98,7 @@ class Lexical
|
|||||||
if(r != TokenType.Unknown)
|
if(r != TokenType.Unknown)
|
||||||
{
|
{
|
||||||
token = Token(r);
|
token = Token(r);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
token = Token(TokenType.Iden, Value(iden));
|
token = Token(TokenType.Iden, Value(iden));
|
||||||
@@ -260,6 +262,8 @@ class Parser
|
|||||||
}
|
}
|
||||||
void compile()
|
void compile()
|
||||||
{
|
{
|
||||||
|
auto compiler = new Compiler(parseProgram());
|
||||||
|
compiler.compile();
|
||||||
}
|
}
|
||||||
Statements parseProgram()
|
Statements parseProgram()
|
||||||
{
|
{
|
||||||
@@ -278,7 +282,7 @@ class Parser
|
|||||||
}
|
}
|
||||||
void syntaxError()
|
void syntaxError()
|
||||||
{
|
{
|
||||||
stderr.writeln("Syntax error", lex.getLine());
|
stderr.writeln("Syntax error (", lex.getLine(), ')');
|
||||||
}
|
}
|
||||||
//statement
|
//statement
|
||||||
Statement statement()
|
Statement statement()
|
||||||
@@ -322,13 +326,14 @@ class Parser
|
|||||||
print.addArgument(exp);
|
print.addArgument(exp);
|
||||||
lex.popFront();
|
lex.popFront();
|
||||||
token = lex.front();
|
token = lex.front();
|
||||||
|
if(lex.empty()) break;
|
||||||
if(token.type != TokenType.Colon && token.type != TokenType.NewLine && token.type != TokenType.Semicolon && token.type != TokenType.Comma)
|
if(token.type != TokenType.Colon && token.type != TokenType.NewLine && token.type != TokenType.Semicolon && token.type != TokenType.Comma)
|
||||||
{
|
{
|
||||||
syntaxError();
|
syntaxError();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return print;
|
||||||
}
|
}
|
||||||
break;
|
|
||||||
case TokenType.Colon:
|
case TokenType.Colon:
|
||||||
case TokenType.NewLine:
|
case TokenType.NewLine:
|
||||||
break;
|
break;
|
||||||
|
|||||||
Reference in New Issue
Block a user