本文整理汇总了C#中Evaluator.Interpret方法的典型用法代码示例。如果您正苦于以下问题:C# Evaluator.Interpret方法的具体用法?C# Evaluator.Interpret怎么用?C# Evaluator.Interpret使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Evaluator
的用法示例。
在下文中一共展示了Evaluator.Interpret方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Main
static void Main(string[] args)
{
string command = "";
do
{
Console.Write(Prompt);
command = Console.ReadLine();
if (string.IsNullOrWhiteSpace(command))
{
continue;
}
command = command.Trim();
if (command.StartsWith("/"))
{
if (processSpecialCommand(command)) break;
continue;
}
try
{
sb.Append(command).Append("\n");
string text = sb.ToString();
_evaluator = new Evaluator(text);
Console.Write("->\n" + _evaluator.Interpret() + "\n");
}
catch (Exception e)
{
Console.Write("!> " + e.Message + "\n");
sb.Clear();
}
} while (command != ExitCommand);
}
示例2: Main
static void Main(string[] args)
{
String expression = "w x z - +";
Evaluator sentence = new Evaluator(expression);
Dictionary<String, IExpression> variables = new Dictionary<String, IExpression>();
variables.Add("w", new Number(5));
variables.Add("x", new Number(10));
variables.Add("z", new Number(42));
int result = sentence.Interpret(variables);
Console.WriteLine(result);
}
示例3: processSpecialCommand
private static bool processSpecialCommand(string command)
{
if (command == ExitCommand)
{
return true;
}
if (command.StartsWith(FileCommand))
{
string[] fileExport = command.Split(' ');
if (fileExport.Length != 2)
{
Console.WriteLine("!> Usage /file filename.cs");
}
string fileName = fileExport[1];
using (StreamWriter streamWriter = new StreamWriter(fileName))
{
_evaluator = new Evaluator(sb.ToString());
streamWriter.Write(_evaluator.Interpret());
}
}
if (command == ClipboardCommand)
{
_evaluator = new Evaluator(sb.ToString());
var text =_evaluator.Interpret();
Clipboard.SetText(text);
}
if (command == ClearCommand)
{
sb.Clear();
}
if (command == HelpCommand)
{
printHelp();
}
return false;
}