1
0

INC,DECのパース

This commit is contained in:
otya128
2015-07-12 12:47:15 +09:00
parent ccfb25751b
commit 8c140956cb
4 changed files with 57 additions and 3 deletions

View File

@@ -35,6 +35,7 @@ enum NodeType
ArrayAssign,
DefineFunction,
While,
Inc,
}
abstract class Node
{
@@ -420,3 +421,13 @@ class While : Statement
this.statements = statements;
}
}
class Inc : Statement
{
wstring name;
Expression expression;
this(wstring name, Expression expr)
{
this.name = name;
this.expression = expr;
}
}

View File

@@ -62,6 +62,8 @@ class Lexical
reserved["OUT"] = TokenType.Out;
reserved["WHILE"] = TokenType.While;
reserved["WEND"] = TokenType.WEnd;
reserved["INC"] = TokenType.Inc;
reserved["DEC"] = TokenType.Dec;
reserved.rehash();
line = 1;
}
@@ -756,6 +758,9 @@ class Parser
case TokenType.While:
node = whileStatement();
break;
case TokenType.Inc:
case TokenType.Dec:
return incStatement();
default:
syntaxError();
break;
@@ -763,6 +768,42 @@ class Parser
lex.popFront();
return node;
}
Inc incStatement()
{
auto token = lex.front();
bool dec = token.type == TokenType.Dec;
lex.popFront();
token = lex.front();
if(token.type != TokenType.Iden)
{
syntaxError();
return null;
}
wstring var = token.value.stringValue;
//TODO:Array
lex.popFront();
token = lex.front();
Expression expr;
if(token.type == TokenType.Comma)
{
lex.popFront();
expr = expression();
if(!expr)
{
syntaxError();
return null;
}
}
else
{
expr = new Constant(Value(1));
}
if(dec)
{
expr = new BinaryOperator(new Constant(Value(0)), TokenType.Minus, expr);
}
return new Inc(var, expr);
}
IndexExpressions indexExpressions()
{
IndexExpressions ie = new IndexExpressions();

View File

@@ -356,7 +356,7 @@ NEXT
DEF FACT(N)
IF N<=1 THEN RETURN 1
RETURN N*FACT(N-1)
END"*//*
END"*/
`CLS : CL=0 : Z=0
WHILE 1
INC Z : IF Z>200 THEN Z=0
@@ -365,7 +365,7 @@ WHILE 1
PRINT "★ 梅雨で雨が多い季節ですね ★"
NEXT
CL=(CL+1) MOD 16 : VSYNC 2
WEND`*/
WEND`/*
`CLS : CL=0
WHILE 1
FOR I=0 TO 15
@@ -373,7 +373,7 @@ FOR I=0 TO 15
PRINT "Ё プチコン3ゴウ Ж"
NEXT
CL=(CL+1) MOD 16 : VSYNC 1
WEND`
WEND`*/
/*
`CLS : CL=0
@LOOP

View File

@@ -56,6 +56,8 @@ enum TokenType
Out,
While,
WEnd,
Inc,
Dec,
}
struct Token