public string VisitUnaryLambdaFuncNode(IUnaryLambdaFuncASTNode unaryLambdaFunc) { StringBuilder lambdaStr = new StringBuilder(); lambdaStr.AppendFormat("({0} {1})", _constructOperationStr(unaryLambdaFunc.OpType), unaryLambdaFunc.Body.Accept(this)); return(lambdaStr.ToString()); }
public Object VisitUnaryLambdaFuncNode(IUnaryLambdaFuncASTNode unaryLambdaFunc) { if (unaryLambdaFunc == null) { throw new ArgumentNullException("unaryLambdaFunc", "The argument cannot equal to null"); } ParameterExpression x = Expression.Parameter(typeof(int), "x"); Expression lambdaBody = Expression.Empty(); Expression y = (Expression)_visitUnaryLambdaFuncHelper(unaryLambdaFunc.Body, x); lambdaBody = _createExpressionByOpType(unaryLambdaFunc.OpType, x, y); return(Expression.Lambda(lambdaBody.Reduce(), x).Compile()); }
protected Object _visitUnaryLambdaFuncHelper(IASTNode node, Expression parameter) { int[] valueArray = null; if (node.Type == E_NODE_TYPE.NT_VALUE) { valueArray = (node as IValueASTNode).Value; return(Expression.Constant(valueArray.Length >= 1 ? valueArray[0] : 0)); } IUnaryLambdaFuncASTNode funcNode = node as IUnaryLambdaFuncASTNode; if (funcNode == null) { throw new CRuntimeError("Invalid lambda's body"); } IASTNode lambdaBody = funcNode.Body; Expression value = null; if (lambdaBody.Type == E_NODE_TYPE.NT_VALUE) { valueArray = (lambdaBody as IValueASTNode).Value; value = Expression.Constant(valueArray.Length >= 1 ? valueArray[0] : 0); return(_createExpressionByOpType(funcNode.OpType, parameter, value)); } if (lambdaBody.Type != E_NODE_TYPE.NT_UNARY_LAMBDA_FUNC) { throw new CRuntimeError("Invalid lambda's body"); } value = (Expression)_visitUnaryLambdaFuncHelper(lambdaBody, parameter); return(_createExpressionByOpType(funcNode.OpType, parameter, value)); }