Esempio 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);
        }
Esempio n. 2
0
        /// <summary>
        /// block2 = block3, { sign3, block3 } ;
        /// </summary>
        /// <returns></returns>
        public SyntaxTreeNode ParseBlock2()
        {
            // ? [ "-" | "!" ]
              Lexem invertLexem = null;
              if(PeekLexem(LexemType.Subtract, LexemType.Not))
              {
            invertLexem = GetLexem();
            SkipLexem();
              }

              // block3
              var node = ParseBlock3();

              if(invertLexem != null)
              {
            if (invertLexem.Type == LexemType.Subtract)
              node = new OperatorInvertNode(node);
            else
              node = new OperatorNegateNode(node);

            node.Lexem = invertLexem;
              }

              // { sign3, block3 }
              while (PeekLexem(LexemTypeGroup.Sign3))
              {
            var lexem = GetLexem(0, true);
            if (lexem.Type == LexemType.NewLine) return node;

            SkipLexem();
            BinaryOperatorNode newNode;
            switch (lexem.Type)
            {
              case LexemType.Add: newNode = new OperatorAddNode(); break;
              case LexemType.Subtract: newNode = new OperatorSubtractNode(); break;
              default: throw new NotImplementedException();
            }

            // block3
            newNode.Left = node;
            newNode.Right = ParseBlock3();
            newNode.Lexem = lexem;

            node = newNode;
              }

              return node;
        }