src/main/java/org/roisoleil/litexp/Expression.java
/**
	 * Check that the expression has enough numbers and variables to fit the
	 * requirements of the operators and functions, also check for only 1 result
	 * stored at the end of the evaluation.
	 */
Check that the expression has enough numbers and variables to fit the
requirements of the operators and functions, also check for only 1 result
stored at the end of the evaluation.
Check that the expression has enough numbers and variables to fit the requirements of the operators and functions also check for only 1 result stored at the end of the evaluation .
private void validate(List<Token> rpn) {
		Stack<Integer> stack = new Stack<>();
		stack.push(0);
		for (final Token token : rpn) {
			switch (token.type) {
			case UNARY_OPERATOR:
				if (stack.peek() < 1) {
					throw new LitExpException("Missing parameter(s) for unary operator " + token);
				}
				break;
			case OPERATOR:
				if (stack.peek() < 2) {
					throw new LitExpException("Missing parameter(s) for operator " + token);
				}
				stack.set(stack.size() - 1, stack.peek() - 2 + 1);
				break;
			case FUNCTION:
				Function function = functions.get(token.surface.toUpperCase(Locale.ROOT));
				if (function == null) {
					throw new LitExpException("Unknown function '" + token + "' at position " + (token.end + 1));
				}
				int numberArguments = stack.pop();
				if (!function.isVariableArguments() && numberArguments != function.getNumberArguments()) {
					throw new LitExpException("Function " + token + " expected " + function.getNumberArguments()
							+ " parameters, got " + numberArguments);
				}
				if (stack.size() <= 0) {
					throw new LitExpException("Too many function calls, maximum scope exceeded");
				}
				stack.set(stack.size() - 1, stack.peek() + 1);
				break;
			case OPEN_BRACKET:
				stack.push(0);
				break;
			default:
				stack.set(stack.size() - 1, stack.peek() + 1);
			}
		}
		if (stack.size() > 1) {
			throw new LitExpException("Too many unhandled function parameter lists");
		} else if (stack.peek() > 1) {
			throw new LitExpException("Too many numbers or variables");
		} else if (stack.peek() < 1) {
			throw new LitExpException("Empty expression");
		}
	}
private void validate ( List < Token > rpn ) { Stack < Integer > stack = new Stack < > ( ) ; stack . push ( 0 ) ; for ( final Token token : rpn ) { switch ( token . type ) { case UNARY_OPERATOR : if ( stack . peek ( ) < 1 ) { throw new LitExpException ( "Missing parameter(s) for unary operator " + token ) ; } break ; case OPERATOR : if ( stack . peek ( ) < 2 ) { throw new LitExpException ( "Missing parameter(s) for operator " + token ) ; } stack . set ( stack . size ( ) - 1 , stack . peek ( ) - 2 + 1 ) ; break ; case FUNCTION : Function function = functions . get ( token . surface . toUpperCase ( Locale . ROOT ) ) ; if ( function == null ) { throw new LitExpException ( "Unknown function '" + token + "' at position " + ( token . end + 1 ) ) ; } int numberArguments = stack . pop ( ) ; if ( ! function . isVariableArguments ( ) && numberArguments != function . getNumberArguments ( ) ) { throw new LitExpException ( "Function " + token + " expected " + function . getNumberArguments ( ) + " parameters, got " + numberArguments ) ; } if ( stack . size ( ) <= 0 ) { throw new LitExpException ( "Too many function calls, maximum scope exceeded" ) ; } stack . set ( stack . size ( ) - 1 , stack . peek ( ) + 1 ) ; break ; case OPEN_BRACKET : stack . push ( 0 ) ; break ; default : stack . set ( stack . size ( ) - 1 , stack . peek ( ) + 1 ) ; } } if ( stack . size ( ) > 1 ) { throw new LitExpException ( "Too many unhandled function parameter lists" ) ; } else if ( stack . peek ( ) > 1 ) { throw new LitExpException ( "Too many numbers or variables" ) ; } else if ( stack . peek ( ) < 1 ) { throw new LitExpException ( "Empty expression" ) ; } }
Check that the expression has enough numbers and variables to fit the
 requirements of the operators and functions, also check for only 1 result
 stored at the end of the evaluation.
Check that the expression has enough numbers and variables to fit the requirements of the operators and functions also check for only 1 result stored at the end of the evaluation .
// pop the operator's 2 parameters and add the result
 // push the result of the function
