Fix assign
This commit is contained in:
@@ -928,6 +928,15 @@ class Compiler
|
||||
genCodePopVar(assign.name, s);
|
||||
}
|
||||
break;
|
||||
case NodeType.AssignRef:
|
||||
{
|
||||
auto assign = cast(AssignRef)i;
|
||||
//right->left
|
||||
compileExpression(assign.expression, s);
|
||||
compilePushReference(assign.left, s);
|
||||
genCode(new PopRererence());
|
||||
}
|
||||
break;
|
||||
case NodeType.Label:
|
||||
{
|
||||
if (this.isDirectMode)
|
||||
|
||||
@@ -44,6 +44,7 @@ enum NodeType
|
||||
RepeatUntil,
|
||||
Option,
|
||||
Swap,
|
||||
AssignRef,
|
||||
}
|
||||
abstract class Node
|
||||
{
|
||||
@@ -221,6 +222,18 @@ class Assign : Statement
|
||||
this.expression = expr;
|
||||
}
|
||||
}
|
||||
class AssignRef : Statement
|
||||
{
|
||||
Expression left;
|
||||
Expression expression;
|
||||
this(Expression left, Expression expr, SourceLocation loc)
|
||||
{
|
||||
super.location = loc;
|
||||
this.type = NodeType.AssignRef;
|
||||
this.left = left;
|
||||
this.expression = expr;
|
||||
}
|
||||
}
|
||||
class Label : Statement
|
||||
{
|
||||
wstring label;
|
||||
|
||||
@@ -849,21 +849,6 @@ class Parser
|
||||
case TokenType.Iden:
|
||||
{
|
||||
wstring name = token.value.stringValue;
|
||||
lex.popFront();
|
||||
if (token.type != TokenType.Call)
|
||||
{
|
||||
token = lex.front();
|
||||
if(token.type == TokenType.Assign)
|
||||
{
|
||||
node = assign(name);
|
||||
return node;
|
||||
}
|
||||
if(token.type == TokenType.LBracket)//配列代入
|
||||
{
|
||||
node = arrayAssign(name);
|
||||
return node;
|
||||
}
|
||||
}
|
||||
if (name == "OPTION")
|
||||
{
|
||||
if (token.type != TokenType.Iden)
|
||||
@@ -880,6 +865,19 @@ class Parser
|
||||
lex.popFront();
|
||||
return new Option(arg, lex.location);
|
||||
}
|
||||
if (token.type != TokenType.Call)
|
||||
{
|
||||
auto expr = expression;
|
||||
if (expr.type == NodeType.Variable)
|
||||
{
|
||||
auto variable = cast(Variable)expr;
|
||||
node = assign(variable.name);
|
||||
return node;
|
||||
}
|
||||
node = assign(expr);
|
||||
return node;
|
||||
}
|
||||
lex.popFront();
|
||||
//命令呼び出し
|
||||
auto func = new CallFunctionStatement(name, lex.location);
|
||||
node = func;
|
||||
@@ -1561,6 +1559,20 @@ class Parser
|
||||
auto a = new Assign(name, expr, lex.location);
|
||||
return a;
|
||||
}
|
||||
AssignRef assign(Expression left)
|
||||
{
|
||||
lex.popFront();
|
||||
auto token = lex.front();//=の次
|
||||
Expression expr = expression();
|
||||
if(expr is null) return null;
|
||||
if (!isLValue(left))
|
||||
{
|
||||
syntaxError();
|
||||
return null;
|
||||
}
|
||||
auto a = new AssignRef(left, expr, lex.location);
|
||||
return a;
|
||||
}
|
||||
Print print()
|
||||
{
|
||||
auto print = new Print(lex.location);
|
||||
|
||||
Reference in New Issue
Block a user