From 972b075b0fa5679f4ec945dbc7f8029ae07110f6 Mon Sep 17 00:00:00 2001 From: otya128 Date: Thu, 8 Dec 2016 21:38:22 +0900 Subject: [PATCH] Fix assign --- SMILEBASIC/compiler.d | 9 +++++++++ SMILEBASIC/node.d | 13 +++++++++++++ SMILEBASIC/parser.d | 42 +++++++++++++++++++++++++++--------------- 3 files changed, 49 insertions(+), 15 deletions(-) diff --git a/SMILEBASIC/compiler.d b/SMILEBASIC/compiler.d index 38fcb38..3527b6a 100644 --- a/SMILEBASIC/compiler.d +++ b/SMILEBASIC/compiler.d @@ -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) diff --git a/SMILEBASIC/node.d b/SMILEBASIC/node.d index 8616488..2548a41 100644 --- a/SMILEBASIC/node.d +++ b/SMILEBASIC/node.d @@ -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; diff --git a/SMILEBASIC/parser.d b/SMILEBASIC/parser.d index 0daf9c7..d8bdbf4 100644 --- a/SMILEBASIC/parser.d +++ b/SMILEBASIC/parser.d @@ -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);