本文整理汇总了C#中Parser.Compile方法的典型用法代码示例。如果您正苦于以下问题:C# Parser.Compile方法的具体用法?C# Parser.Compile怎么用?C# Parser.Compile使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Parser
的用法示例。
在下文中一共展示了Parser.Compile方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Iterative
public static string Iterative(string sfx, string sfdx, double a, double b, out int count)
{
Parser fx = new Parser(sfx);
fx.AddFunction<Algorithms>("log");
fx.Compile();
Parser fdx = new Parser(sfdx);
fdx.AddFunction<Algorithms>("log");
fdx.Compile();
double x0 = (a + b)/2;
if (x0 == 0)
{
x0 = (b + x0)/2;
}
fdx.Variables.Add("x", x0);
double lambda = -1 / fdx.Calculate();
count = 0;
fx.Variables.Add("x", x0);
double xn = x0 + lambda*fx.Calculate();
while ((xn - x0) > eps)
{
x0 = xn;
fx.Variables["x"] = xn;
xn = xn + lambda * fx.Calculate();
++count;
}
return xn.ToString();
}
示例2: TestModule
public void TestModule()
{
var parser = new Parser();
Stream input = GetStream(@"MODULE TEST;
END TEST.
");
parser.Compile(input);
}
示例3: Parse
public static double Parse(string input)
{
Parser OMG = new Parser(input);
OMG.AddFunction<Agent>("F");
OMG.Compile();
OMG.Variables.Add("x",2);
OMG.Variables.Add("y", 2);
OMG.Variables.Add("z", 2);
return OMG.Calculate();
}
示例4: TestProcedureWithParens
public void TestProcedureWithParens()
{
var parser = new Parser();
Stream input = GetStream(@"MODULE TEST;
PROCEDURE TestProc();
BEGIN
END TestProc;
END TEST.
");
parser.Compile(input);
}
示例5: TestModuleDeclaration
public void TestModuleDeclaration()
{
var parser = new Parser();
Stream input = GetStream(
@"MODULE TEST;
VAR W: Writer;
PROCEDURE TestProc;
BEGIN
END TestProc;
END TEST.
");
parser.Compile(input);
}
示例6: TestMethodCall
public void TestMethodCall()
{
var parser = new Parser();
Stream input = GetStream(
@"MODULE TEST;
PROCEDURE TestProc;
BEGIN
Write();
Write();
END TestProc;
END TEST.
");
parser.Compile(input);
}
示例7: Chord
public static string Chord(string sfx, string sfdx, double a, double b, out int count)
{
Parser fx = new Parser(sfx);
fx.AddFunction<Algorithms>("log");
fx.Compile();
Parser fdx = new Parser(sfdx);
fdx.AddFunction<Algorithms>("log");
fdx.Compile();
fx.Variables["x"] = a;
fdx.Variables["x"] = a;
double a_fpt = fx.Calculate()*fdx.Calculate();
fx.Variables["x"] = b;
fdx.Variables["x"] = b;
double b_fpt = fx.Calculate()*fdx.Calculate();
double fixedPoint = a_fpt > 0 ? a : b;
double xnm1 = (a + b) / 2;
fx.Variables["x"] = xnm1;
double fx_r = fx.Calculate();
fx.Variables["x"] = fixedPoint;
double fx0_r = fx.Calculate();
double xn = xnm1 - (xnm1 - fixedPoint)/(fx_r - fx0_r)*fx_r;
count = 0;
while ((xn - xnm1) > eps)
{
xnm1 = xn;
fx.Variables["x"] = xn;
fx_r = fx.Calculate();
xn = xn - (xn - fixedPoint) / (fx_r - fx0_r) * fx_r;
++count;
}
return xn.ToString();
}
示例8: textBox_LostFocus
private void textBox_LostFocus(object sender, RoutedEventArgs e)
{
string text = (sender as TextBox).Text;
int id = int.Parse((sender as TextBox).Name.Substring(1));
var p = new Parser(text);
try
{
p.Compile();
}
catch(Exception exception)
{
ErrorAllert(exception.Message);
return;
}
varForEq[id - 1].Clear();
varForEq[id - 1].AddRange(p.RequiredVariables);
var vars = varForEq[0];
for (int i = 1; i < varForEq.Count; i++)
{
vars = new List<string>(vars.Union(varForEq[i]));
}
SetVariables(vars);
}
示例9: Newton
public static string Newton(string sfx, string sfdx, string sfddx, double a, double b, out int count)
{
Parser fx = new Parser(sfx);
fx.AddFunction<Algorithms>("log");
fx.Compile();
Parser fdx = new Parser(sfdx);
fdx.AddFunction<Algorithms>("log");
fdx.Compile();
Parser fddx = new Parser(sfddx);
fddx.AddFunction<Algorithms>("log");
fdx.Compile();
fx.Variables["x"] = a;
fddx.Variables["x"] = a;
double a_fpt = fx.Calculate() * fddx.Calculate();
fx.Variables["x"] = b;
fddx.Variables["x"] = b;
fx.Compile();
double b_fpt = fx.Calculate() * fddx.Calculate();
double fixedPoint = a_fpt > 0 ? a : b;
fx.Variables["x"] = fixedPoint;
fdx.Variables["x"] = fixedPoint;
double xn = fixedPoint - fx.Calculate()/fdx.Calculate();
count = 0;
while ((xn - fixedPoint) > eps)
{
fixedPoint = xn;
fx.Variables["x"] = xn;
fdx.Variables["x"] = xn;
xn = fixedPoint - fx.Calculate() / fdx.Calculate();
++count;
}
return xn.ToString();
}