Add VAR(expr)=expr parsing
This commit is contained in:
@@ -45,6 +45,7 @@ enum NodeType
|
|||||||
Option,
|
Option,
|
||||||
Swap,
|
Swap,
|
||||||
AssignRef,
|
AssignRef,
|
||||||
|
VarRef,
|
||||||
}
|
}
|
||||||
abstract class Node
|
abstract class Node
|
||||||
{
|
{
|
||||||
@@ -620,3 +621,13 @@ class Swap : Statement
|
|||||||
this.item2 = item2;
|
this.item2 = item2;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
class VarRef : Expression
|
||||||
|
{
|
||||||
|
Expression expression;
|
||||||
|
this(Expression expr, SourceLocation loc)
|
||||||
|
{
|
||||||
|
super.location = loc;
|
||||||
|
this.type = NodeType.VarRef;
|
||||||
|
this.expression = expression;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -1015,8 +1015,21 @@ class Parser
|
|||||||
case TokenType.Continue:
|
case TokenType.Continue:
|
||||||
node = new Continue(lex.location);
|
node = new Continue(lex.location);
|
||||||
break;
|
break;
|
||||||
case TokenType.Dim:
|
|
||||||
case TokenType.Var:
|
case TokenType.Var:
|
||||||
|
{
|
||||||
|
auto old = lex.save;
|
||||||
|
lex.popFront();
|
||||||
|
token = lex.front;
|
||||||
|
if (token.type == TokenType.LParen)
|
||||||
|
{
|
||||||
|
lex = old;
|
||||||
|
token = lex.front;
|
||||||
|
goto case TokenType.Iden;
|
||||||
|
}
|
||||||
|
node = var();
|
||||||
|
return node;
|
||||||
|
}
|
||||||
|
case TokenType.Dim:
|
||||||
lex.popFront();
|
lex.popFront();
|
||||||
node = var();
|
node = var();
|
||||||
return node;
|
return node;
|
||||||
@@ -1097,6 +1110,10 @@ class Parser
|
|||||||
{
|
{
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
if(expr.type == NodeType.VarRef)
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
if(expr.type == NodeType.BinaryOperator)
|
if(expr.type == NodeType.BinaryOperator)
|
||||||
{
|
{
|
||||||
auto op = cast(BinaryOperator)expr;
|
auto op = cast(BinaryOperator)expr;
|
||||||
@@ -1782,6 +1799,22 @@ class Parser
|
|||||||
node = new Constant(token.value, lex.location);
|
node = new Constant(token.value, lex.location);
|
||||||
break;
|
break;
|
||||||
case TokenType.Var:
|
case TokenType.Var:
|
||||||
|
if(!lex.empty())
|
||||||
|
lex.popFront();
|
||||||
|
if(lex.front().type == TokenType.LParen)
|
||||||
|
{
|
||||||
|
lex.popFront();
|
||||||
|
auto expr = expression;
|
||||||
|
node = new VarRef(expr, lex.location);
|
||||||
|
if(lex.front().type != TokenType.RParen)
|
||||||
|
syntaxError();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
syntaxError();
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
break;
|
||||||
case TokenType.Call:
|
case TokenType.Call:
|
||||||
case TokenType.Iden:
|
case TokenType.Iden:
|
||||||
if(!lex.empty())
|
if(!lex.empty())
|
||||||
|
|||||||
Reference in New Issue
Block a user