本文整理汇总了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);
}
}
示例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)"));
}
示例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)));
}
示例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)"));
}
示例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");
}
}
}
示例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;
}
示例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;
}
示例8: Alphabetic_Literals
public void Alphabetic_Literals()
{
var target = new Interpreter();
Assert.AreEqual("ciao", target.Eval("\"ciao\""));
Assert.AreEqual('c', target.Eval("'c'"));
}
示例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()");
}
示例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;
}
示例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;
}
示例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);
}
}
示例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));
}
示例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);
}
}
示例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;
}