當前位置: 首頁>>代碼示例>>C#>>正文


C# BinaryOperator.SetLeftOperand方法代碼示例

本文整理匯總了C#中BinaryOperator.SetLeftOperand方法的典型用法代碼示例。如果您正苦於以下問題:C# BinaryOperator.SetLeftOperand方法的具體用法?C# BinaryOperator.SetLeftOperand怎麽用?C# BinaryOperator.SetLeftOperand使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在BinaryOperator的用法示例。


在下文中一共展示了BinaryOperator.SetLeftOperand方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: ConvertUnaryOperand

            public static UnaryConvertResult ConvertUnaryOperand(Expression operand, Token op)
            {
                UnaryConvertResult res = new UnaryConvertResult();
                Symbols.Type t = operand.GetType();
                switch (op.type)
                {
                    case Token.Type.OP_INC:
                    case Token.Type.OP_DEC:
                        Token.Type tt = op.type == Token.Type.OP_DEC ?
                            Token.Type.OP_SUB_ASSIGN : Token.Type.OP_PLUS_ASSIGN;

                        BinaryOperator bop = new BinaryOperator(new Token(tt));
                        bop.SetLeftOperand(operand);
                        bop.SetRightOperand(new Const("1", new Symbols.INT()));
                        res.type = bop.GetType();
                        break;

                    case Token.Type.OP_BIT_AND:
                        if (!(operand.IsLvalue() || operand.GetType() is Symbols.Func))
                        {
                            throw new Symbols.Exception(operand, NOT_LVALUE_OR_FUNC);
                        }
                        res.type = new Symbols.POINTER(operand.GetType());
                        break;

                    case Token.Type.OP_STAR:
                        res.lvalue = true;
                        if (!(t is Symbols.POINTER || t is Symbols.Func))
                        {
                            throw new Symbols.Exception(operand, NOT_POINTER);
                        }

                        if (t is Symbols.Func)
                        {
                            res.type = t;
                        }
                        else
                        {
                            res.type = ((Symbols.RefType)t).GetRefType();
                        }
                        break;

                    case Token.Type.OP_PLUS:
                    case Token.Type.OP_SUB:
                        if (!t.IsArifmetic())
                        {
                            throw new Symbols.Exception(operand, NOT_ARITHMETICAL);
                        }
                        res.type = t;
                        break;

                    case Token.Type.OP_TILDE:
                        if (!t.IsInteger())
                        {
                            throw new Symbols.Exception(operand, NOT_INTEGER);
                        }
                        res.type = t;
                        break;

                    case Token.Type.OP_NOT:
                        if (!(t.IsArifmetic() || t is Symbols.Func || t is Symbols.POINTER))
                        {
                            throw new Symbols.Exception(operand, string.Format(NO_OPERATOR, op.GetStrVal()));
                        }
                        res.type = new Symbols.INT();
                        break;

                    case Token.Type.KW_SIZEOF:
                        res.type = new Symbols.INT();
                        break;

                    case Token.Type.OP_DOT:
                    default:
                        throw new System.NotImplementedException();
                }

                res.operand = operand;
                return res;
            }
開發者ID:khomyakov42,項目名稱:Compiler,代碼行數:79,代碼來源:Symantic.cs

示例2: ConvertBinaryOperands

            public static BinaryConvertResult ConvertBinaryOperands(Expression lop, Expression rop, Token op)
            {
                Symbols.Type lt = lop.GetType(), rt = rop.GetType();
                BinaryConvertResult res = new BinaryConvertResult();
                res.op = op;
                Pair<Expression, Expression> uacon = null;
                switch (op.type)
                {
                    case Token.Type.OP_STAR:
                    case Token.Type.OP_DIV:
                        if (!lt.IsArifmetic())
                        {
                            throw new Symbols.Exception(lop, NOT_ARITHMETICAL);
                        }
                        if (!rt.IsArifmetic())
                        {
                            throw new Symbols.Exception(rop, NOT_ARITHMETICAL);
                        }

                        if (op.type == Token.Type.OP_MOD)
                        {
                            if (!lt.IsArifmetic())
                            {
                                lop = new Cast(lop, new Symbols.INT());
                            }
                            if (!rt.IsArifmetic())
                            {
                                rop = new Cast(rop, new Symbols.INT());
                            }
                            res.type = rop.GetType();
                            break;
                        }
                        uacon = UsualArithmeticConversions(lop, rop);
                        lop = uacon.first;
                        rop = uacon.last;
                        res.type = lop.GetType();
                        break;

                    case Token.Type.OP_MOD:
                        if (!lt.IsInteger())
                        {
                            throw new Symbols.Exception(lop, NOT_INTEGER);
                        }
                        if (!rt.IsInteger())
                        {
                            throw new Symbols.Exception(rop, NOT_INTEGER);
                        }

                        if (op.type == Token.Type.OP_MOD)
                        {
                            if (!(lt is Symbols.INT))
                            {
                                lop = new Cast(lop, new Symbols.INT());
                            }
                            if (!(rt is Symbols.INT))
                            {
                                rop = new Cast(rop, new Symbols.INT());
                            }
                            res.type = rop.GetType();
                            break;
                        }
                        uacon = UsualArithmeticConversions(lop, rop);
                        lop = uacon.first;
                        rop = uacon.last;
                        res.type = lop.GetType();
                        break;

                    case Token.Type.OP_PLUS:
                    case Token.Type.OP_SUB:
                        if (rt is Symbols.POINTER || lt is Symbols.POINTER)
                        {
                            if (rt is Symbols.POINTER && lt is Symbols.POINTER)
                            {
                                if (op.type == Token.Type.OP_PLUS)
                                {
                                    throw new Symbols.Exception(lop, NOT_ARITHMETICAL);
                                }
                                res.type = rt;
                                break;
                            }

                            BinaryOperator binop = new BinaryOperator(new Token(Token.Type.OP_STAR));
                            int size = 0;
                            if (rt is Symbols.POINTER)
                            {
                                lop = lt is Symbols.INT ? lop : new Cast(lop, new Symbols.INT());
                                binop.SetLeftOperand(lop);
                                size = ((Symbols.POINTER)rt).GetRefType().GetSizeType();
                                binop.SetRightOperand(new Const(size.ToString(), new Symbols.INT()));
                                lop = binop;
                                res.type = rt;
                            }
                            else
                            {
                                rop = rt is Symbols.INT ? rop : new Cast(rop, new Symbols.INT());
                                binop.SetLeftOperand(rop);
                                size = ((Symbols.POINTER)lt).GetRefType().GetSizeType();
                                binop.SetRightOperand(new Const(size.ToString(), new Symbols.INT()));
                                rop = binop;
                                res.type = lt;
//.........這裏部分代碼省略.........
開發者ID:khomyakov42,項目名稱:Compiler,代碼行數:101,代碼來源:Symantic.cs

示例3: Modified

            public override Expression Modified()
            {
                Expression res = null;
                switch (this.op.type)
                {
                    case Token.Type.LBRACKET:
                        BinaryOperator bop = new BinaryOperator(new Token(Token.Type.OP_PLUS));

                        if (this.expr is Refference && ((Refference)this.expr).op.type == Token.Type.LBRACKET)
                        {
                            UnaryOperator u = new UnaryOperator(new Token(Token.Type.OP_BIT_AND));
                            this.expr.SetType(((Symbols.RefType)this.expr.GetType()).GetRefType());
                            u.SetOperand(this.expr);
                            bop.SetRightOperand(u);
                        }
                        else
                        {
                            bop.SetRightOperand(this.expr);
                        }

                        bop.SetLeftOperand(this.refference);
                        res = new UnaryOperator(new Token(Token.Type.OP_STAR));
                        ((UnaryOperator)res).SetOperand(bop);
                        break;
                    case Token.Type.OP_REF:
                        UnaryOperator rop = new UnaryOperator(new Token(Token.Type.OP_STAR));
                        rop.SetOperand(this.expr);
                        res = new Refference(new Token(Token.Type.OP_DOT));
                        ((Refference)res).SetExpression(rop);
                        ((Refference)res).SetRefference(this.refference);
                        break;
                }
                return res == null ? this : res.Modified();
            }
開發者ID:khomyakov42,項目名稱:Compiler,代碼行數:34,代碼來源:SyntaxObjects.cs


注:本文中的BinaryOperator.SetLeftOperand方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。