本文整理汇总了C#中Parser.Evaluate方法的典型用法代码示例。如果您正苦于以下问题:C# Parser.Evaluate方法的具体用法?C# Parser.Evaluate怎么用?C# Parser.Evaluate使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Parser
的用法示例。
在下文中一共展示了Parser.Evaluate方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Test
void Test(String query, Int32 number)
{
var parser = new Parser();
var value = parser.Evaluate(query);
var plot = (PlotValue)value;
Assert.AreEqual(number, plot.Count);
}
示例2: TestValue
protected void TestValue(String query, SetValue result)
{
var parser = new Parser();
parser.LoadPlugin(typeof(SetsPlugin).Assembly);
parser.UseScripting = true;
var value = parser.Evaluate(query);
Assert.AreEqual(result, value);
}
示例3: Test
protected void Test(String query, Double result, Double prec = 0.0)
{
var parser = new Parser();
parser.LoadPlugin(typeof(UnitValue).Assembly);
var value = parser.Evaluate(query);
var real = ((ScalarValue)value).Re;
Assert.AreEqual(result, real, prec);
}
示例4: TestNoException
protected void TestNoException(String query)
{
Assert.DoesNotThrow(() =>
{
var parser = new Parser();
parser.LoadPlugin(typeof(SetsPlugin).Assembly);
parser.UseScripting = true;
var value = parser.Evaluate(query);
});
}
示例5: Test
void Test(String query, String name, Double val, Double result, Double prec = 0.0)
{
var parser = new Parser();
var argument = new Dictionary<String, Value>
{
{ name, new ScalarValue(val) }
};
var value = parser.Evaluate(query, argument);
var real = ((ScalarValue)value).Re;
Assert.AreEqual(result, real, prec);
}
示例6: Main
public static void Main()
{
string expr;
//Parser p=new Parser();
Console.WriteLine("Для выхода введите \"q\".");
StreamReader streamReader = new StreamReader("test.txt");
string str = "";
Parser p = new Parser();
double d = 0.0;
while (!streamReader.EndOfStream)
{
str = streamReader.ReadLine();
d=p.Evaluate(str);
}
//double st = p.Evaluate(str);
Console.WriteLine("Результат:" + d);
expr = Console.ReadLine();
while (expr != "q")
{
double st = p.Evaluate(expr);
Console.WriteLine("Результат:" + st);
expr = Console.ReadLine();
}
//Console.ReadLine();
//expr = "a=2+2";
//p.Evaluate(expr);
//expr = "b=5";
//p.Evaluate(expr);
//expr = "a+b";
//double st=p.Evaluate(expr);
//Console.WriteLine("Результат:" + st);
//expr = Console.ReadLine();
}
示例7: EvalExp5
void EvalExp5(out double result)
{
double partialResult, ex;
int t;
EvalExp6(out result);
if (token == "&")
{
GetToken();
EvalExp5(out partialResult);
ex = result;
if (partialResult == 0.0)
{
result = 0.0;
return;
}
//t = (int)partialResult;
for (t = (int)partialResult; t > 0; t--)
{
Parser oo = new Parser();
oo.vars = this.vars;
string[] str = exp.Split('&');
result=oo.Evaluate(str[0]);
this.vars = oo.vars;
}
}
}
示例8: solveResult
private object solveResult(string Expression)
{
if (Expression.StartsWith("@"))
{
return TagManager.Instance.ResolveSymbol(Expression, TagGroup);
}
object ret = false;
string _expression = Expression;
//Verifica se é matemática
Parser p = new Parser();
if (p.Evaluate(_expression))
{
ret = p.Result;
}
else
{
#region Tratamento de Parenteses
while (_expression.Contains("("))
{
_expression = _expression.Replace(_expression.Substring(_expression.LastIndexOf('('), (_expression.IndexOf(')', _expression.LastIndexOf('(') + 1) + 1) - _expression.LastIndexOf('(')), solveResult(_expression.Substring(_expression.LastIndexOf('(') + 1, (_expression.IndexOf(')', _expression.LastIndexOf('(') + 1) - 1) - _expression.LastIndexOf('('))).ToString());
}
#endregion
// Atualizando o array de string
string[] expressionSplited = split(_expression.ToCharArray());
// Procura pela tag do primeiro termo da expressão
bool parcialRet = false;
for (int i = 0; i <= System.Math.Floor((Convert.ToDouble(expressionSplited.Length) / Convert.ToDouble(4))); i++)
{
switch (expressionSplited[((i * 4) + 1)])
{
case "!=":
parcialRet = Convert.ToDouble(expressionSplited[i*4]) != Convert.ToDouble(expressionSplited[((i * 4) + 2)]);
break;
case "=":
parcialRet = Convert.ToDouble(expressionSplited[i*4]) == Convert.ToDouble(expressionSplited[((i * 4) + 2)]);
break;
case "<=":
parcialRet = Convert.ToDouble(expressionSplited[i*4]) <= Convert.ToDouble(expressionSplited[((i * 4) + 2)]);
break;
case ">=":
parcialRet = Convert.ToDouble(expressionSplited[i*4]) >= Convert.ToDouble(expressionSplited[((i * 4) + 2)]);
break;
case "<":
parcialRet = Convert.ToDouble(expressionSplited[i*4]) < Convert.ToDouble(expressionSplited[((i * 4) + 2)]);
break;
case ">":
parcialRet = Convert.ToDouble(expressionSplited[i*4]) > Convert.ToDouble(expressionSplited[((i * 4) + 2)]);
break;
}
if (i == 0)
{
ret = parcialRet;
}
else
{
ret = expressionSplited[((i * 4) - 1)] == "|" ? Convert.ToBoolean(ret) || parcialRet : Convert.ToBoolean(ret) && parcialRet;
}
}
}
return ret;
}