本文整理汇总了C#中Interpreter类的典型用法代码示例。如果您正苦于以下问题:C# Interpreter类的具体用法?C# Interpreter怎么用?C# Interpreter使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Interpreter类属于命名空间,在下文中一共展示了Interpreter类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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
示例16: CanInterpretTwoSentences
public void CanInterpretTwoSentences()
{
Interpreter interpreter = new Interpreter();
var commands = interpreter.Parse("PRESS A,\"B\",C\r\nPRESS A,B").ToList();
Assert.AreEqual(2, commands.Count);
Assert.AreEqual(2, commands[1].Parameters.Count);
}
开发者ID:NicolasDorier,项目名称:GestSpace,代码行数:7,代码来源:UnitTest1.cs
示例17: Instantiate
public static void Instantiate(Assembly a, Interpreter interp)
{
Hashtable table = interp.VarTable;
try {
CodeChunk chunk = (CodeChunk)a.CreateInstance("CsiChunk");
chunk.Go(table);
// vs 0.8 we display the type and value of expressions. The variable $_ is
// always set, which is useful if you want to save the result of the last
// calculation.
if (interp.returnsValue && DumpingValue) {
object val = table["_"];
Type type = val.GetType();
string stype = type.ToString();
if (stype.StartsWith("System.")) // to simplify things a little bit...
stype = stype.Substring(7);
stype = "("+stype+")";
if (val is string) {
Print(stype,"'"+val+"'");
} else
if (val is IEnumerable) {
Print(stype);
Dumpl((IEnumerable)val);
} else
Print(stype,val);
}
} catch(Exception ex) {
Print(ex.GetType() + " was thrown: " + ex.Message);
}
}
开发者ID:stevedonovan,项目名称:cs-repl,代码行数:29,代码来源:interpreter.cs
示例18: Numeric_Operators_Priority
public void Numeric_Operators_Priority()
{
var target = new Interpreter();
Assert.AreEqual(8 / 2 + 2, target.Eval("8 / 2 + 2"));
Assert.AreEqual(8 + 2 / 2, target.Eval("8 + 2 / 2"));
}
开发者ID:CooperLiu,项目名称:DynamicExpresso,代码行数:7,代码来源:OperatorsTest.cs
示例19: 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
示例20: CheckFunctionalParameter
/// <summary>
/// Ensures that the parameter provided corresponds to a function double->double
/// </summary>
/// <param name="root">Element on which the errors shall be attached</param>
/// <param name="context">The context used to evaluate the expression</param>
/// <param name="expression">The expression which references the function</param>
/// <param name="count">the expected number of parameters</param>
protected virtual void CheckFunctionalParameter(ModelElement root, Interpreter.InterpretationContext context, Interpreter.Expression expression, int count)
{
Types.Type type = expression.GetExpressionType();
Function function = type as Function;
if (function != null)
{
if (function.FormalParameters.Count == count)
{
foreach (Parameter parameter in function.FormalParameters)
{
if (!parameter.Type.IsDouble())
{
root.AddError(expression.ToString() + " does not takes a double for parameter " + parameter.Name);
}
}
}
else
{
root.AddError(expression.ToString() + " does not take " + count + "parameter(s) as input");
}
if (!function.ReturnType.IsDouble())
{
root.AddError(expression.ToString() + " does not return a double");
}
}
else
{
if (!type.IsDouble())
{
root.AddError(expression.ToString() + " type is not double");
}
}
}
开发者ID:Assmann-Siemens,项目名称:ERTMSFormalSpecs,代码行数:42,代码来源:PredefinedFunction.cs
注:本文中的Interpreter类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论