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


C# BinaryExpression.ToStatement方法代碼示例

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


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

示例1: ExpressionFunc

        Statement ExpressionFunc()
        {
            var stack = new Stack<Expression>();
            var resultExp = GetResultIndexExpression();
            if (!(resultExp is IntegerLiteralExpression))
                throw new InvalidOperationException(string.Format("ResultExpression was expected to be an integer but was a {0} instead", resultExp.GetType()));
            var dst = ((IntegerLiteralExpression)resultExp).Value;
            while ((_opCode = ReadByte()) != 0xFF)
            {
                switch (_opCode & 0x1F)
                {
                    case 1:
					// var
                        stack.Push(GetVarOrDirectWord(OpCodeParameter.Param1));
                        break;

                    case 2:
					// add
                        {
                            var i = stack.Pop();
                            stack.Push(new BinaryExpression(i, Operator.Add, stack.Pop()));
                        }
                        break;

                    case 3:
					// sub
                        {
                            var i = stack.Pop();
                            stack.Push(new BinaryExpression(stack.Pop(), Operator.Subtract, i));
                        }
                        break;

                    case 4:
					// mul
                        {
                            var i = stack.Pop();
                            stack.Push(new BinaryExpression(i, Operator.Multiply, stack.Pop()));
                        }
                        break;

                    case 5:
					// div
                        {
                            var i = stack.Pop();
                            stack.Push(new BinaryExpression(stack.Pop(), Operator.Divide, i));
                        }
                        break;

                    case 6:
					// normal opcode
                        {
                            _opCode = ReadByte();
                            var statement = ExecuteOpCode();
                            var expStatement = statement as ExpressionStatement;
                            if (expStatement == null)
                                throw new InvalidOperationException("ExpressionStatement expected");
                            var binExp = expStatement.Expression as BinaryExpression;
                            if (binExp == null)
                                throw new InvalidOperationException("BinaryExpression expected");
                            if (!((binExp.Left is ElementAccess) && ((ElementAccess)binExp.Left).Target is SimpleName))
                                throw new InvalidOperationException("Variables[0] was expected expected");
                            stack.Push(binExp.Right);
                        }
                        break;

                    default:
                        throw new NotImplementedException();
                }
            }

            var exp = new BinaryExpression(GetResultIndex(dst), Operator.Assignment, stack.Pop());
            return exp.ToStatement();
        }
開發者ID:scemino,項目名稱:nscumm,代碼行數:73,代碼來源:ScriptParser3_Expression.cs


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