本文整理汇总了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);
}
}
示例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);
}
示例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);
}
示例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;
}
示例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);
}
示例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();
}
示例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]);
}
示例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);
}