当前位置: 首页>>代码示例>>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;未经允许,请勿转载。