1
0

予約語を扱えるようにした

This commit is contained in:
otya128
2015-06-04 19:31:47 +09:00
parent f9d52680f4
commit f453d86a79
2 changed files with 43 additions and 0 deletions

View File

@@ -7,6 +7,7 @@ import std.stdio;
class Lexical
{
TokenType[] table;
TokenType[wstring] reserved;
wstring code;
int index;
this(wstring input)
@@ -24,11 +25,23 @@ class Lexical
table['('] = TokenType.LParen;
table[')'] = TokenType.RParen;
table[','] = TokenType.Comma;
table[':'] = TokenType.Colon;
table[';'] = TokenType.Semicolon;
reserved["OR"] = TokenType.Or;
reserved["AND"] = TokenType.And;
reserved["XOR"] = TokenType.Xor;
reserved["NOT"] = TokenType.Not;
reserved["PRINT"] = TokenType.Print;
reserved.rehash();
}
bool empty()
{
return index >= code.length;
}
bool isSmileBasicSuffix(wchar c)
{
return c == '$' || c == '%' || c == '#';
}
Token token;
void popFront()
{
@@ -69,6 +82,19 @@ class Lexical
}
iden ~= c;
}
if(isSmileBasicSuffix(c))
{
iden ~= c;
i++;
}
else//変数が予約語であることはありえない
{
auto r = reserved.get(iden, TokenType.Unknown);
if(r != TokenType.Unknown)
{
token = Token(r);
}
}
token = Token(TokenType.Iden, Value(iden));
break;
}
@@ -156,6 +182,9 @@ class Parser
return 0;//TODO:エラーにすべきかは実装次第
}
}
/*
テスト用
*/
int calc()
{
lex.popFront();
@@ -209,6 +238,17 @@ class Parser
return - - -1;
}
}
Statements parseProgram()
{
auto statements = new Statements();
statement();
return statements;
}
//statement
Statement statement()
{
return null;
}
Expression expression()
{
Expression node = null;

View File

@@ -14,12 +14,15 @@ enum TokenType
Or,
And,
Xor,
Not,
Print,
If,
LParen,
RParen,
Iden,
Comma,
Colon,
Semicolon,
}
struct Token