1
0

Fix assign

This commit is contained in:
otya128
2016-12-08 21:38:22 +09:00
parent cc05576862
commit 972b075b0f
3 changed files with 49 additions and 15 deletions

View File

@@ -928,6 +928,15 @@ class Compiler
genCodePopVar(assign.name, s); genCodePopVar(assign.name, s);
} }
break; 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: case NodeType.Label:
{ {
if (this.isDirectMode) if (this.isDirectMode)

View File

@@ -44,6 +44,7 @@ enum NodeType
RepeatUntil, RepeatUntil,
Option, Option,
Swap, Swap,
AssignRef,
} }
abstract class Node abstract class Node
{ {
@@ -221,6 +222,18 @@ class Assign : Statement
this.expression = expr; 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 class Label : Statement
{ {
wstring label; wstring label;

View File

@@ -849,21 +849,6 @@ class Parser
case TokenType.Iden: case TokenType.Iden:
{ {
wstring name = token.value.stringValue; 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 (name == "OPTION")
{ {
if (token.type != TokenType.Iden) if (token.type != TokenType.Iden)
@@ -880,6 +865,19 @@ class Parser
lex.popFront(); lex.popFront();
return new Option(arg, lex.location); 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); auto func = new CallFunctionStatement(name, lex.location);
node = func; node = func;
@@ -1561,6 +1559,20 @@ class Parser
auto a = new Assign(name, expr, lex.location); auto a = new Assign(name, expr, lex.location);
return a; 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() Print print()
{ {
auto print = new Print(lex.location); auto print = new Print(lex.location);