Exemplo n.º 1
0
        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);
        }
Exemplo n.º 2
0
        /// <summary>
        /// block5 = block6, { sign6, block6 } ;
        /// </summary>
        /// <returns></returns>
        public SyntaxTreeNode ParseBlock5()
        {
            // block6
              var node = ParseBlock6();

              // { sign6, block6 }
              while (PeekLexem(LexemTypeGroup.Binary))
              {
            var lexem = GetLexem(0, true);
            if (lexem.Type == LexemType.NewLine) return node;

            SkipLexem();
            BinaryOperatorNode newNode = null;
            switch (lexem.Type)
            {
              case LexemType.BinaryAnd: newNode = new OperatorBinaryAndNode(); break;
              case LexemType.BinaryOr: newNode = new OperatorBinaryOrNode(); break;
              case LexemType.BinaryXor: newNode = new OperatorBinaryXorNode(); break;
              case LexemType.BinaryShiftLeft: newNode = new OperatorBinaryShiftLeftNode(); break;
              case LexemType.BinaryShiftRight: newNode = new OperatorBinaryShiftRightNode(); break;
            }

            // block6
            newNode.Left = node;
            newNode.Right = ParseBlock6();
            newNode.Lexem = lexem;

            node = newNode;
              }

              return node;
        }