当前位置: 首页>>代码示例>>C#>>正文


C# Interpreter.Interpret方法代码示例

本文整理汇总了C#中Interpreter.Interpret方法的典型用法代码示例。如果您正苦于以下问题:C# Interpreter.Interpret方法的具体用法?C# Interpreter.Interpret怎么用?C# Interpreter.Interpret使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Interpreter的用法示例。


在下文中一共展示了Interpreter.Interpret方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: DoTable

 public static void DoTable(Tree<Cell> table, Interpreter activeFixture, bool inFlow)
 {
     var activeFlowFixture = activeFixture as FlowInterpreter;
     if (activeFlowFixture != null) activeFlowFixture.DoSetUp(table);
     activeFixture.Interpret(table);
     if (activeFlowFixture != null && !inFlow) activeFlowFixture.DoTearDown(table);
 }
开发者ID:narkedboy,项目名称:fitsharp,代码行数:7,代码来源:ExecuteStoryTest.cs

示例2: InterpretHelloWorldProgram

        public static void InterpretHelloWorldProgram()
        {
            var lines = new string[] {
                ">                v",
                ">v\"Hello world!\"0<",
                ",:",
                "^_25*,@" };

            var builder = new StringBuilder();

            using (var writer = new StringWriter(builder, CultureInfo.CurrentCulture))
            {
                using (var reader = new StringReader(string.Empty))
                {
                    using (var interpreter = new Interpreter(lines, reader, writer))
                    {
                        interpreter.Interpret();
                    }
                }
            }

            var result = builder.ToString();

            Assert.Equal("Hello world!" + new string('\n', 1), result);
        }
开发者ID:JasonBock,项目名称:IronBefunge,代码行数:25,代码来源:InterpreterTests.cs

示例3: InterpretPrintBeholdIronBefungeProgram

        public static void InterpretPrintBeholdIronBefungeProgram()
        {
            var lines = new string[] {
                "\"!egnufeBnorI ,dloheB\">:#,[email protected]" };

            var builder = new StringBuilder();

            using (var writer = new StringWriter(builder, CultureInfo.CurrentCulture))
            {
                using (var reader = new StringReader(string.Empty))
                {
                    using (var interpreter = new Interpreter(lines, reader, writer))
                    {
                        interpreter.Interpret();
                    }
                }
            }

            var result = builder.ToString();

            Assert.Equal("Behold, IronBefunge!", result);
        }
开发者ID:JasonBock,项目名称:IronBefunge,代码行数:22,代码来源:InterpreterTests.cs

示例4: Execute

        /// <summary>
        /// Executes the code contained inside the TBlock.
        /// </summary>
        /// <param name="interpreter">The interpreter that the method is being called from.</param>
        /// <param name="exitFromFunction">
        /// A value that will be set to whether 'exit()' was called during the block execution.
        /// </param>
        /// <param name="breakUsed">Whethe the 'break' keyword was used in the block.</param>
        /// <param name="beforeElse">Whether to execute the code before the 'else', if any.</param>
        /// <returns>A TType value of the result of the last executed statement in the block.</returns>
        public TType Execute(Interpreter interpreter, out bool exitFromFunction, out bool breakUsed,
            bool beforeElse = true)
        {
            exitFromFunction = breakUsed = false;
            if (!beforeElse && (elseLocation < 0)) return new TException(interpreter, "No else statement found");

            int start, end;
            // Decide which section of code should be executed
            if (elseAllowed)
            {
                if (beforeElse)
                {
                    start = 0;
                    end = (elseLocation > 0 ? elseLocation : statements.Count) - 1;
                }
                else
                {
                    start = elseLocation + 1;
                    end = statements.Count - 1;
                }
            }
            else
            {
                start = 0;
                end = statements.Count - 1;
            }

            int stackLevel = interpreter.Stack.Level;
            // Keep track of the previous block (if any). Used when there are blocks within blocks
            TBlock previousCurrentBlock = interpreter.CurrentBlock;
            interpreter.CurrentBlock = this;

            TType returnValue = null, previousReturnValue = null;
            for (currentLine = start; currentLine <= end; ++currentLine)
            {
                previousReturnValue = returnValue;
                returnValue = interpreter.Interpret(statements[currentLine], true);

                if (interpreter.Stack.Level < stackLevel) // if 'exit()' was called
                {
                    exitFromFunction = true;
                    break;
                }

                // Need to check for TBreak so that it can be used to break from a loop (if any)
                if (returnValue is TException) break;
                if (returnValue is TBreak)
                {
                    returnValue = previousReturnValue ?? TNil.Instance;
                    breakUsed = true;
                    break;
                }
            }

            // Now that the block has finished executing its code, restore control to the outer block
            interpreter.CurrentBlock = previousCurrentBlock;

            return returnValue ?? TNil.Instance;
        }
开发者ID:supermaximo93,项目名称:Toast-Prototype-Interpreter,代码行数:69,代码来源:TBlock.cs

示例5: Call

        /// <summary>
        /// Calls the TFunction with the specified arguments.
        /// </summary>
        /// <param name="interpreter">The interpreter that the method is being called from.</param>
        /// <param name="value">
        /// The argument to pass to the function. When passing multiple arguments, use a TArgumentList.
        /// </param>
        /// <returns></returns>
        public TType Call(Interpreter interpreter, TType value)
        {
            // If value is already a TArgumentList, then simply copy the reference, otherwise create a new
            // TArgumentList and add the value to it. This TArgument list is to be passed to the function.
            TArgumentList argList = value as TArgumentList;
            if (argList == null)
            {
                argList = new TArgumentList();
                argList.Add(value);
            }

            // If the function takes a fixed number of arguments...
            if (ArgNames != null)
            {
                // Occupy the argument list with the default arguments. If there is no default argument in a place
                // where an argument should have been given, return a TException.
                if (argList.Count < ArgNames.Length)
                {
                    for (int i = argList.Count; i < DefaultArgs.Length; ++i)
                    {
                        if (DefaultArgs[i] == null) break;
                        else argList.Add(DefaultArgs[i]);
                    }
                }

                if (argList.Count != ArgNames.Length)
                {
                    return new TException(interpreter, "Incorrect number of arguments for function '" + Name + "'",
                        argList.Count.ToString() + " out of " + ArgNames.Length.ToString() + " given");
                }
            }

            interpreter.Stack.Push();
            // Keep a track of the new stack level so that if a function calls 'exit()', which pops from the stack,
            // this will be able to be detected and the function call can be terminated properly
            int stackLevel = interpreter.Stack.Level;

            // Put the arguments on the current stack 'frame'
            if (ArgNames == null)
            {
                for (int i = 0; i < argList.Count; ++i)
                    interpreter.Stack.AddVariable(new TVariable("arg" + i.ToString(), argList[i]));
            }
            else
            {
                for (int i = 0; i < argList.Count; ++i)
                    interpreter.Stack.AddVariable(new TVariable(ArgNames[i], argList[i]));
            }

            TType returnValue = null;
            bool dontPop = false; // Set to true if the stack is popped during the call, i.e. if 'exit()' is called

            // Call the function
            if (HardCodedFunction != null) returnValue = HardCodedFunction.Invoke(interpreter, argList);
            else if (Block != null)
            {
                bool breakUsed;
                returnValue = Block.Execute(interpreter, out dontPop, out breakUsed);
            }
            else if (CustomFunction != "")
            {
                returnValue = interpreter.Interpret(CustomFunction, true);
                if (interpreter.Stack.Level < stackLevel) dontPop = true;
            }

            // If returnValue is a TVariable, then return the value of the TVariable (e.g. we want to return 5, as
            // opposed to the variable X which contains 5)
            TVariable variable = returnValue as TVariable;
            if (variable != null) returnValue = variable.Value;

            if (!dontPop) interpreter.Stack.Pop();

            return returnValue ?? TNil.Instance;
        }
开发者ID:supermaximo93,项目名称:Toast-Prototype-Interpreter,代码行数:82,代码来源:TFunction.cs


注:本文中的Interpreter.Interpret方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。