public override void Compile(Emitter.Emitter emitter) { // check if there's an expression prefix and back it up if(Lvalue.ExpressionPrefix != null) { // save to tmp variable var tmpVarName = emitter.CurrentMethod.Scope.CreateNewName(); var tmpVar = Expr.Var(tmpVarName, Lvalue.ExpressionPrefix); tmpVar.Compile(emitter); Lvalue.ExpressionPrefix = new IdentifierGetNode(tmpVarName); } // prepare operator node BinaryOperatorNode opNode; switch(Lexem.Type) { case LexemType.AssignAdd: opNode = new OperatorAddNode(); break; case LexemType.AssignSubtract: opNode = new OperatorSubtractNode(); break; case LexemType.AssignMultiply: opNode = new OperatorMultiplyNode(); break; case LexemType.AssignDivide: opNode = new OperatorDivideNode(); break; case LexemType.AssignRemainder: opNode = new OperatorRemainderNode(); break; case LexemType.AssignPower: opNode = new OperatorPowerNode(); break; case LexemType.AssignShiftLeft: opNode = new OperatorBinaryShiftLeftNode(); break; case LexemType.AssignShiftRight: opNode = new OperatorBinaryShiftRightNode(); break; default: throw new NotImplementedException(); } opNode.Lexem = Lexem; opNode.Left = Lvalue; opNode.Right = Expression; // prepare assignment IdentifierNode saveNode; if (Lvalue is IdentifierGetNode) saveNode = Expr.IdentifierSet(Lvalue as IdentifierGetNode, opNode); else if (Lvalue is ArrayGetNode) saveNode = Expr.ArraySet(Lvalue as ArrayGetNode, opNode); else saveNode = Expr.MatrixSet(Lvalue as MatrixGetNode, opNode); saveNode.Lexem = Lexem; saveNode.Compile(emitter); }
/// <summary> /// block4 = block5, { sign5, block5 } ; /// </summary> /// <returns></returns> public SyntaxTreeNode ParseBlock4() { // block5 var node = ParseBlock5(); // { sign5, block5 } while (PeekLexem(LexemType.Power, LexemType.NewLine)) { var lexem = GetLexem(0, true); if (lexem.Type == LexemType.NewLine) return node; var newNode = new OperatorPowerNode(); newNode.Lexem = lexem; SkipLexem(); // block5 newNode.Left = node; newNode.Right = ParseBlock5(); node = newNode; } return node; }