本文整理汇总了C#中Evaluator.EvalInfix方法的典型用法代码示例。如果您正苦于以下问题:C# Evaluator.EvalInfix方法的具体用法?C# Evaluator.EvalInfix怎么用?C# Evaluator.EvalInfix使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Evaluator
的用法示例。
在下文中一共展示了Evaluator.EvalInfix方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Main
static void Main(string[] args)
{
//string expr = "pr/2+(-3*2)^2 * sqrt(2+2) * max(sqrt(2), sqrt(4))";
string expr = "(1 + 2.5) * 3";
Dictionary<string, double> vars = new Dictionary<string, double>();
vars.Add("pr", -1);
Evaluator<double> eval = new Evaluator<double>(expr, new SimpleMath());
try
{
Console.WriteLine("Sample math expression: " + expr);
Console.WriteLine("In postfix format: " + eval.Expression);
Console.WriteLine("Result: " + eval.Eval(vars));
}
catch (ParsingException e)
{
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine(e.Message);
Console.ForegroundColor = ConsoleColor.Gray;
}
Console.WriteLine("----------------------------------------");
Evaluator<bool> evalLogic = new Evaluator<bool>(new SimpleLogic());
string exprLogic = "(F | (!T > T)) = ((F & T) > (F > T))";
try
{
Console.WriteLine("Sample logical expression: " + exprLogic);
Console.WriteLine("Result: " + evalLogic.EvalInfix(exprLogic));
}
catch (ParsingException e)
{
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine(e.Message);
Console.ForegroundColor = ConsoleColor.Gray;
}
Console.WriteLine("----------------------------------------");
//string exprLogic2 = "(p > (q > r)) > ((s > t) > (u > v))";
//string exprLogic2 = "(p -> (not q -> r)) <-> ((r -> !q) -> (p -> r))";
string exprLogic2 = "(((a|b)>(c=d))&(f^g))=h";
try
{
Console.WriteLine("Truth table of: " + exprLogic2);
Console.WriteLine();
TruthTables.PrintTable(exprLogic2);
}
catch (ParsingException e)
{
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine(e.Message);
Console.ForegroundColor = ConsoleColor.Gray;
}
Console.WriteLine("\nPress any key to continue...");
Console.ReadKey();
}