public override CodeGenPayload Visit(FactorialToken token, CodeGenPayload state = default) { var factorialPExpr = Expression.Parameter(typeof(double)); var factorialExpr = Expression.Lambda(Expression.Invoke(Expression.Constant((Func <double, double>)Factorial), factorialPExpr), factorialPExpr); return(state?.Combine(new CodeGenPayload { Expression = Expression.Invoke(factorialExpr, Visit(token, state).Expression) })); }
protected T Visit(IToken token, T state = default) { return(token switch { AddToken addToken => Visit(addToken, state), SubtractToken subtractToken => Visit(subtractToken, state), MultiplyToken multiplyToken => Visit(multiplyToken, state), DivideToken divideToken => Visit(divideToken, state), NegateToken negateToken => Visit(negateToken, state), NumberToken numberToken => Visit(numberToken, state), FactorialToken factorialToken => Visit(factorialToken, state), PowerToken powerToken => Visit(powerToken, state), VariableToken variableToken => Visit(variableToken, state), AssignmentToken assignmentToken => Visit(assignmentToken, state), _ => throw new ArgumentOutOfRangeException(nameof(token)) });
public virtual T Visit(FactorialToken token, T state = default) { return(Visit(token.Item1, state ?? new T())); }