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


C# Interpreter类代码示例

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


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

示例1: EvaluateNode

 public override void EvaluateNode(Interpreter.EvaluationContext context, AstMode mode, DateTime time)
 {
     foreach (var rule in TradingRules)
     {
         rule.EvaluateNode(context, AstMode.None, time);
     }
 }
开发者ID:wayne-yeung,项目名称:FxStrategyAnalyzer,代码行数:7,代码来源:TradingStrategyAstNode.cs

示例2: New_Of_Base_Type

        public void New_Of_Base_Type()
        {
            var target = new Interpreter();

            Assert.AreEqual(new DateTime(2015, 1, 24), target.Eval("new DateTime(2015, 1, 24)"));
            Assert.AreEqual(new string('a', 10), target.Eval("new string('a', 10)"));
        }
开发者ID:kornarakis,项目名称:DynamicExpresso,代码行数:7,代码来源:ConstructorTest.cs

示例3: Can_use_overloaded_operators_on_class

        public void Can_use_overloaded_operators_on_class()
        {
            var target = new Interpreter();

            var x = new ClassWithOverloadedBinaryOperators(3);
            target.SetVariable("x", x);

            string y = "5";
            Assert.IsFalse(x == y);
            Assert.IsFalse(target.Eval<bool>("x == y", new Parameter("y", y)));

            y = "3";
            Assert.IsTrue(x == y);
            Assert.IsTrue(target.Eval<bool>("x == y", new Parameter("y", y)));

            Assert.IsFalse(target.Eval<bool>("x == \"4\""));
            Assert.IsTrue(target.Eval<bool>("x == \"3\""));

            Assert.IsTrue(!x == "-3");
            Assert.IsTrue(target.Eval<bool>("!x == \"-3\""));

            var z = new ClassWithOverloadedBinaryOperators(10);
            Assert.IsTrue((x + z) == "13");
            Assert.IsTrue(target.Eval<bool>("(x + z) == \"13\"", new Parameter("z", z)));
        }
开发者ID:jony1982,项目名称:DynamicExpresso,代码行数:25,代码来源:OperatorsTest.cs

示例4: Math_Class

        public void Math_Class()
        {
            var target = new Interpreter();

            Assert.AreEqual(Math.Pow(3, 4), target.Eval("Math.Pow(3, 4)"));
            Assert.AreEqual(Math.Sin(30.234), target.Eval("Math.Sin(30.234)"));
        }
开发者ID:johniak,项目名称:DynamicExpresso,代码行数:7,代码来源:StaticTest.cs

示例5: additionalChecks

        /// <summary>
        /// Perform additional checks based on the parameter types
        /// </summary>
        /// <param name="root">The element on which the errors should be reported</param>
        /// <param name="context">The evaluation context</param>
        /// <param name="actualParameters">The parameters applied to this function call</param>
        public override void additionalChecks(ModelElement root, Interpreter.InterpretationContext context, Dictionary<string, Interpreter.Expression> actualParameters)
        {
            CheckFunctionalParameter(root, context, actualParameters[First.Name], 1);
            CheckFunctionalParameter(root, context, actualParameters[Second.Name], 1);

            Function function1 = actualParameters[First.Name].GetExpressionType() as Function;
            Function function2 = actualParameters[Second.Name].GetExpressionType() as Function;

            if (function1 != null && function2 != null)
            {
                if (function1.FormalParameters.Count == 1 && function2.FormalParameters.Count == 1)
                {
                    Parameter p1 = (Parameter)function1.FormalParameters[0];
                    Parameter p2 = (Parameter)function2.FormalParameters[0];

                    if (p1.Type != p2.Type && p1.Type != EFSSystem.DoubleType && p2.Type != EFSSystem.DoubleType)
                    {
                        root.AddError("The formal parameters for the functions provided as parameter are not the same");
                    }
                }

                if (function1.ReturnType != function2.ReturnType && function1.ReturnType != EFSSystem.DoubleType && function2.ReturnType != EFSSystem.DoubleType)
                {
                    root.AddError("The return values for the functions provided as parameter are not the same");
                }
            }
        }
开发者ID:Assmann-Siemens,项目名称:ERTMSFormalSpecs,代码行数:33,代码来源:Max.cs

示例6: Execute

        public override ReturnCode Execute(
            Interpreter interpreter,
            IClientData clientData,
            ArgumentList arguments,
            ref Result result
            )
        {
            if ((arguments == null) || (arguments.Count < 2))
            {
                result = Utility.WrongNumberOfArguments(
                    this, 1, arguments, "command");

                return ReturnCode.Error;
            }

            try
            {
                var processor = new CommandLineProcessor();
                var o = processor.Pharse(arguments.Select(argument => (string) argument).Skip(1).ToArray());
                if (!(o is string) && o is IEnumerable)
                    result = new StringList(o);
                else
                {
                    result = o == null ? "" : new Variant(o).ToString();
                }
            }
            catch (Exception exception)
            {
                Log.Error("Script error ", exception);
                result = "Error on command execution " + exception.Message;
            }
            return ReturnCode.Ok;
        }
开发者ID:CadeLaRen,项目名称:digiCamControl,代码行数:33,代码来源:DccCommand.cs

示例7: Transition

 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="rule"></param>
 /// <param name="preCondition">The precondition which setup the initial state</param>
 /// <param name="initialState">The initial stae of this transition</param>
 /// <param name="update">The statement which set up the target state</param>
 /// <param name="targetState">The target state of this transition</param>
 public Transition(PreCondition preCondition, State initialState, Interpreter.Statement.VariableUpdateStatement update, State targetState)
 {
     PreCondition = preCondition;
     InitialState = initialState;
     Update = update;
     TargetState = targetState;
 }
开发者ID:Assmann-Siemens,项目名称:ERTMSFormalSpecs,代码行数:15,代码来源:Transition.cs

示例8: Alphabetic_Literals

        public void Alphabetic_Literals()
        {
            var target = new Interpreter();

            Assert.AreEqual("ciao", target.Eval("\"ciao\""));
            Assert.AreEqual('c', target.Eval("'c'"));
        }
开发者ID:nishannnb,项目名称:DynamicExpresso,代码行数:7,代码来源:LiteralsTest.cs

示例9: SystemExceptions_are_preserved_using_method_invocation

        public void SystemExceptions_are_preserved_using_method_invocation()
        {
            var target = new Interpreter();
            target.SetVariable("a", new MyTestService());

            target.Eval("a.ThrowException()");
        }
开发者ID:jony1982,项目名称:DynamicExpresso,代码行数:7,代码来源:ExceptionTest.cs

示例10: CapsInfer

 private static bool CapsInfer(Interpreter interpreter, Source source, Stringe tagname, TagArg[] args)
 {
     // TODO: Make capsinfer properly infer "first" capitalization given multiple sentences. Currently, it mistakes it for "word" mode.
     var words = Regex.Matches(args[0].GetString(), @"\w+").OfType<Match>().Select(m => m.Value).ToArray();
     int wCount = words.Length;
     int uCount = 0;
     int fwCount = 0;
     bool firstCharIsUpper = false;
     for (int i = 0; i < wCount; i++)
     {
         if (words[i].All(Char.IsUpper))
         {
             uCount++;
         }
         if (Char.IsUpper(words[i][0]))
         {
             fwCount++;
             if (i == 0) firstCharIsUpper = true;
         }
     }
     if (uCount == wCount)
     {
         interpreter.CurrentState.Output.SetCaps(Capitalization.Upper);
     }
     else if (wCount > 1 && fwCount == wCount)
     {
         interpreter.CurrentState.Output.SetCaps(Capitalization.Word);
     }
     else if (firstCharIsUpper)
     {
         interpreter.CurrentState.Output.SetCaps(Capitalization.First);
     }
     return false;
 }
开发者ID:zhangfann,项目名称:Processus,代码行数:34,代码来源:Interpreter.TagFuncs.cs

示例11: SpiderView

        public SpiderView(SpiderHost host)
        {
            this.Host = host;
            this.Scripting = new Scripting.LuaInterpreter(this);
            this.Preprocessor = new Preprocessor.LuaMako(this);
            this.Scripting.RegisterFunction("refresh", GetType().GetMethod("refresh"), this);

            this.timer = new Timer();
            InitializeComponent();
            this.tabBar = new TabBar(this);
            this.deck = new Panel();
            tabBar.Dock = DockStyle.Top;
            tabBar.Height = 23;
            this.Controls.Add(deck);
            this.Controls.Add(tabBar);
            deck.Dock = DockStyle.Fill;
            this.tabBar.Dock = DockStyle.Top;
            Block = Stylesheet.Blocks["Body"];
            this.BackColor = Block.BackColor;
            this.ForeColor = Block.ForeColor;
            this.tabBar.TabChange += tabBar_TabChange;
            this.timer.Tick += timer_Tick;
            this.timer.Interval = 1000;
            this.Click += SpiderView_Click;
        }
开发者ID:krikelin,项目名称:BungaSpotify-2009,代码行数:25,代码来源:SpiderView.cs

示例12: 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

示例13: Evaluate

        public override double Evaluate(Parser parser, Interpreter ii)
        {
            if (_token.Identifier == MathTokenType.Swap)
            {
                var left = _left as NameExpression;
                var right = _right as NameExpression;
                if (left == null) throw new ManhoodException(parser.Source, _token, "Left side of swap operation was not a variable.");
                if (right == null) throw new ManhoodException(parser.Source, _token, "Right side of swap operation was not a variable.");
                double temp = left.Evaluate(parser, ii);
                double b = right.Evaluate(parser, ii);
                ii.Engine.Variables.SetVar(left.Name, b);
                ii.Engine.Variables.SetVar(right.Name, temp);
                return b;
            }
            Func<Parser, Interpreter, NameExpression, Expression, double> assignFunc;
            if (AssignOperations.TryGetValue(_token.Identifier, out assignFunc))
            {
                var left = _left as NameExpression;
                if (left == null) throw new ManhoodException(parser.Source, _token, "Left side of assignment was not a variable.");
                return assignFunc(parser, ii, left, _right);
            }

            Func<double, double, double> func;
            if (!Operations.TryGetValue(_token.Identifier, out func))
            {
                throw new ManhoodException(parser.Source, _token, "Invalid binary operation '" + _token + "'.");
            }
            return func(_left.Evaluate(parser, ii), _right.Evaluate(parser, ii));
        }
开发者ID:dandrews,项目名称:Manhood,代码行数:29,代码来源:BinaryOperatorExpression.cs

示例14: EvaluateNode

 public override void EvaluateNode(Interpreter.EvaluationContext context, AstMode mode, DateTime time)
 {
     if (ExecuteFrequency.CanExecute(context.StartDate, time))
     {
         Statements.EvaluateNode(context, AstMode.None, time);
     }
 }
开发者ID:wayne-yeung,项目名称:FxStrategyAnalyzer,代码行数:7,代码来源:TradingRuleAstNode.cs

示例15: Execute

 public override object Execute(Interpreter interpreter)
 {
     Console.WriteLine ("Mono Debugger (C) 2003-2007 Novell, Inc.\n" +
                "Written by Martin Baulig ([email protected])\n" +
                "        and Chris Toshok ([email protected])\n");
     return null;
 }
开发者ID:baulig,项目名称:debugger,代码行数:7,代码来源:Command.cs


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