本文整理汇总了C#中Interpreter.ParseGroup方法的典型用法代码示例。如果您正苦于以下问题:C# Interpreter.ParseGroup方法的具体用法?C# Interpreter.ParseGroup怎么用?C# Interpreter.ParseGroup使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Interpreter
的用法示例。
在下文中一共展示了Interpreter.ParseGroup方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Parse
/// <summary>
/// Attempts to convert an object into a TType.
/// </summary>
/// <param name="interpreter">The interpreter that the method is being called from.</param>
/// <param name="obj">The object that is to be converted into a TType derivative.</param>
/// <returns>An object of base class TType. If the operation was unsuccessful, null is returned.</returns>
public static TType Parse(Interpreter interpreter, object obj)
{
if (obj is string)
{
string str = ((string)obj).Trim();
if (str == "") return TNil.Instance;
// Attempt to convert to a keyword first
if ((str == "yes") || (str == "no")) return new TBoolean(str);
if (str == "nil") return TNil.Instance;
if (str == "break") return TBreak.Instance;
{
long result;
if (long.TryParse(str, out result)) return new TInteger(result);
}
{
double result;
if (double.TryParse(str, out result)) return new TReal(result);
}
{ // If first and last characters of string are '"', then return a TString
if ((str.First() == STRING_CHARACTER) && (str.Last() == STRING_CHARACTER))
return new TString(str.Substring(1, str.Length - 2));
}
{ // Attempt to find a function or variable with the name
TType result = TFunction.GetFunction(str);
if (result == null)
{
result = interpreter.Stack.FindVariable(str);
if (result == null)
return new TException(interpreter,
"Variable or function with identifier '" + str + "' not found");
}
return result;
}
}
else if (obj is TType) return (TType)obj;
else if (obj is Interpreter.Group) return interpreter.ParseGroup(obj as Interpreter.Group);
return null;
}