本文整理汇总了C#中Expression.GetRest方法的典型用法代码示例。如果您正苦于以下问题:C# Expression.GetRest方法的具体用法?C# Expression.GetRest怎么用?C# Expression.GetRest使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Expression
的用法示例。
在下文中一共展示了Expression.GetRest方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: AddDefinition
private void AddDefinition(Frame environment, List<string> paramNames, Dictionary<string, Procedure> bindings, Expression definition)
{
if (definition != null)
{
string name = definition.GetFirst().ToString();
paramNames.Add(name);
if (definition.GetRest().Count == 0)
{
throw new Exception("Let: expression missing for " + name);
}
//TODO clean up the constructor and property
Frame valueEnv = new Frame(new Dictionary<string, Procedure>(0), environment, null, new Identity(environment, null), false, "let-value");
object value = valueEnv.Evaluate(definition.GetRest()[0],true);
if (value is Procedure)
{
bindings.Add(name, (Procedure)value);
}
else
{
bindings.Add(name, new Identity(environment, value));
}
}
}
示例2: Evaluate
public object Evaluate(Frame environment, Expression expression)
{
if (expression.GetRest().Count < 2)
{
throw new Exception("Invalid let definition");
}
Expression definitionList = expression.GetRest()[0];
List<string> paramNames = new List<string>(definitionList.GetRest().Count + 1);
Dictionary<string, Procedure> bindings = new Dictionary<string, Procedure>(paramNames.Capacity);
Expression firstDefinition = definitionList.GetFirst();
AddDefinition(environment, paramNames, bindings, firstDefinition);
foreach (Expression definition in definitionList.GetRest())
{
AddDefinition(environment, paramNames, bindings, definition);
}
List<Expression> body = new List<Expression>(expression.GetRest().Count - 1);
for (int i = 1; i < expression.GetRest().Count; i++)
{
body.Add(expression.GetRest()[i]);
}
Lambda block = new Lambda(environment, paramNames, body);
Frame child = new Frame(bindings, environment, environment, block,true,null);
return child.Evaluate(block.Body);
}
示例3: Evaluate
public object Evaluate(Frame environment, Expression expression)
{
List<Expression> operands = expression.GetRest();
if (operands.Count < 2)
{
throw new Exception("Invalid number of If arguments");
}
Frame evalFrame = new Frame(new Dictionary<string, Procedure>(), environment, environment, null, true, null);
object result = evalFrame.Evaluate(operands[0]);
bool resultValue = false;
if (!bool.TryParse(result.ToString(), out resultValue))
{
throw new Exception("If clause not a predicate.");
}
if (resultValue)
{
return evalFrame.Evaluate(operands[1],true);
}
else
{
if (operands.Count > 2)
{
return evalFrame.Evaluate(operands[2], true);
}
else
{
return string.Empty;
}
}
}
示例4: Evaluate
public object Evaluate(Frame environment, Expression expression)
{
List<Expression> operands = expression.GetRest();
if (operands.Count < 1)
{
throw new Exception("Invalid number of cond arguments");
}
Frame evalFrame = new Frame(new Dictionary<string, Procedure>(0), environment,environment, null, true, null);
foreach (Expression expr in operands)
{
if (expr.GetFirst().ToString() == "else")
{
return evalFrame.Evaluate(expr.GetRest()[0], true);
}
object result = evalFrame.Evaluate(expr.GetFirst());
bool resultValue = false;
if (!bool.TryParse(result.ToString(), out resultValue))
{
throw new Exception("Cond clause not a predicate.");
}
if (resultValue)
{
object exprResult = string.Empty;
for (int i = 0; i < expr.GetRest().Count;i++ )
{
exprResult = evalFrame.Evaluate(expr.GetRest()[i]);
}
return exprResult;
}
}
return string.Empty;
}
示例5: Evaluate
public object Evaluate(Frame environment, Expression expression)
{
List<Expression> operands = expression.GetRest();
if (operands.Count == 0)
{
throw new Exception("or: invalid number of arguments.");
}
Frame evalFrame = new Frame(new Dictionary<string, Procedure>(), environment,environment, null, true, null);
for (int i = 0; i < operands.Count; i++)
{
object result = null;
if (i == operands.Count - 1)
{
result = evalFrame.Evaluate(operands[i], true);
}
else
{
result = evalFrame.Evaluate(operands[i]);
}
bool resultValue = false;
if (!bool.TryParse(result.ToString(), out resultValue))
{
throw new Exception("or: clause not a predicate.");
}
if (resultValue)
{
return true;
}
}
return false;
}
示例6: Evaluate
public object Evaluate(Frame environment, Expression expression)
{
if (expression.GetRest().Count < 2)
{
throw new Exception("Invalid lambda definition");
}
Expression paramList = expression.GetRest()[0];
List<String> parameters = new List<string>(paramList.GetRest().Count + 1);
parameters.Add(paramList.GetFirst().ToString());
foreach (Expression param in paramList.GetRest())
{
parameters.Add(param.ToString());
}
List<Expression> body = new List<Expression>();
for (int i = 1; i < expression.GetRest().Count; i++)
{
body.Add(expression.GetRest()[i]);
}
return new Lambda(environment, parameters, body);
}
示例7: Evaluate
public object Evaluate(Frame environment, Expression expression)
{
List<Expression> operands = expression.GetRest();
if (operands.Count < 2)
{
throw new Exception("Invalid define arguments");
}
bool isFunctionDeclaration = false;
if (operands[0] is Combination)
{
isFunctionDeclaration = true;
}
String name = operands[0].GetFirst().ToString();
List<string> parameters = new List<string>();
foreach (Expression expr in operands[0].GetRest())
{
parameters.Add(expr.ToString());
}
List<Expression> body = new List<Expression>(operands.Count - 1);
if (!isFunctionDeclaration)
{
var definitionValue = environment.Evaluate(operands[1]);
if (definitionValue is Lambda)
{
environment.AddBinding(name, (Lambda)definitionValue);
}
else
{
environment.AddBinding(name, new Identity(environment,definitionValue));
}
return name;
}
for (int i = 1; i < operands.Count; i++)
{
body.Add(operands[i]);
}
environment.AddBinding(name, new Lambda(environment,parameters, body));
return name;
}