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


C# Interpreter.Execute方法代码示例

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


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

示例1: calculateButton_Click

        private void calculateButton_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                ClearScreen();

                string formula = formulaTextBox.Text;

                TokenReader reader = new TokenReader(CultureInfo.InvariantCulture);
                List<Token> tokens = reader.Read(formula);

                ShowTokens(tokens);

                AstBuilder astBuilder = new AstBuilder();
                Operation operation = astBuilder.Build(tokens);

                ShowAbstractSyntaxTree(operation);

                Dictionary<string, double> variables = new Dictionary<string, double>();
                foreach (Variable variable in GetVariables(operation))
                {
                    double value = AskValueOfVariable(variable);
                    variables.Add(variable.Name, value);
                }

                IExecutor executor = new Interpreter();
                double result = executor.Execute(operation, variables);

                resultTextBox.Text = "" + result;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }
开发者ID:plurby,项目名称:Jace,代码行数:35,代码来源:MainWindow.xaml.cs

示例2: TestBasicInterpreterSubstraction

        public void TestBasicInterpreterSubstraction()
        {
            IExecutor executor = new Interpreter();
            double result = executor.Execute(new Substraction(
                DataType.Integer,
                new IntegerConstant(6),
                new IntegerConstant(9)));

            Assert.AreEqual(-3.0, result);
        }
开发者ID:mahizsas,项目名称:Jace,代码行数:10,代码来源:BasicInterpreterTests.cs

示例3: TestBasicInterpreter1

        public void TestBasicInterpreter1()
        {
            IExecutor executor = new Interpreter();
            // 6 + (2 * 4)
            double result = executor.Execute(
                new Addition(
                    DataType.Integer,
                    new IntegerConstant(6),
                    new Multiplication(DataType.Integer, new IntegerConstant(2), new IntegerConstant(4))));

            Assert.AreEqual(14.0, result);
        }
开发者ID:mahizsas,项目名称:Jace,代码行数:12,代码来源:BasicInterpreterTests.cs

示例4: Visualize

 public static TemplateVisualizer Visualize(this Template template, ErrorManager errorManager, CultureInfo culture, int lineWidth)
 {
     ErrorBuffer errors = new ErrorBuffer();
     template.impl.NativeGroup.Listener = errors;
     StringWriter @out = new StringWriter();
     ITemplateWriter wr = new AutoIndentWriter(@out);
     wr.LineWidth = lineWidth;
     Interpreter interp = new Interpreter(template.Group, culture, true);
     TemplateFrame frame = new TemplateFrame(template, null);
     interp.Execute(wr, frame); // Render and track events
     TemplateVisualizer visualizer = new TemplateVisualizer(errorManager, frame, @out.ToString(), interp, interp.GetExecutionTrace(), errors.Errors);
     visualizer.Show();
     return visualizer;
 }
开发者ID:mahanteshck,项目名称:antlrcs,代码行数:14,代码来源:TemplateExtensions.cs

示例5: TestBasicInterpreterWithVariables

        public void TestBasicInterpreterWithVariables()
        {
            Dictionary<string, double> variables = new Dictionary<string, double>();
            variables.Add("var1", 2);
            variables.Add("age", 4);

            IExecutor interpreter = new Interpreter();
            // var1 + 2 * (3 * age)
            double result = interpreter.Execute(
                new Addition(DataType.FloatingPoint,
                    new Variable("var1"),
                    new Multiplication(
                        DataType.FloatingPoint,
                        new IntegerConstant(2),
                        new Multiplication(
                            DataType.FloatingPoint,
                            new IntegerConstant(3),
                            new Variable("age")))), variables);

            Assert.AreEqual(26.0, result);
        }
开发者ID:mahizsas,项目名称:Jace,代码行数:21,代码来源:BasicInterpreterTests.cs

示例6: GetEvents

 public virtual List<InterpEvent> GetEvents(CultureInfo culture, ITemplateWriter writer)
 {
     Interpreter interp = new Interpreter(groupThatCreatedThisInstance, culture);
     interp.Execute(writer, this); // Render and track events
     return interp.GetEvents();
 }
开发者ID:mahanteshck,项目名称:antlrcs,代码行数:6,代码来源:DebugTemplate.cs

示例7: TestInput

        public void TestInput()
        {
            var inputOutput = A.Fake<IInputOutputProvider>();
            A.CallTo(() => inputOutput.Get()).ReturnsNextFromSequence(new string[] {"4", "3", "-1"});
            interpreter = new Interpreter(inputOutput);

            string program = ",>,>,<<";
            interpreter.Execute(program);

            Assert.AreEqual(4, interpreter.MemoryCells[0]);
            Assert.AreEqual(3, interpreter.MemoryCells[1]);
            Assert.AreEqual(-1, interpreter.MemoryCells[2]);
        }
开发者ID:marco-fiset,项目名称:migraine,代码行数:13,代码来源:BrainfuckInterpreterTests.cs

示例8: TestOutput

        public void TestOutput()
        {
            string output = "";
            var inputOutput = A.Fake<IInputOutputProvider>();
            A.CallTo(() => inputOutput.Write(A<String>.Ignored))
                .Invokes(call => output += call.Arguments[0]);

            interpreter = new Interpreter(inputOutput);

            string program = "++++.--.>+++++.";
            interpreter.Execute(program);

            Assert.AreEqual("425", output);
        }
开发者ID:marco-fiset,项目名称:migraine,代码行数:14,代码来源:BrainfuckInterpreterTests.cs


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