1
0
This commit is contained in:
otya128
2015-06-03 19:51:42 +09:00
parent fb28e1236d
commit 6673ca3fc2
7 changed files with 449 additions and 0 deletions

99
SMILEBASIC/parser.d Normal file
View File

@@ -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)
{
}
}