001package csheets.core.formula.lang;
002
003import csheets.core.*;
004import csheets.core.formula.*;
005
006/**
007 * A function that implements a loop statement where the first condition was the
008 * stop argument and the next arguments are the execution statements
009 * 
010 * @author Andre
011 * 
012 */
013public class Whiledo implements Function {
014
015        /**
016         * Create a new instance of function while do
017         */
018        public Whiledo() {
019        }
020
021        /** Parameters: condition, execution statements */
022        public static final FunctionParameter[] parameters = new FunctionParameter[] { new FunctionParameter(
023                        Value.Type.UNDEFINED, "Iterations", false,
024                        "The iterators of expression.") };
025
026        @Override
027        public String getIdentifier() {
028                return "WHILEDO";
029        }
030
031        @Override
032        public Value applyTo(Expression[] args) throws IllegalValueTypeException {
033                // arg[0] = conditionals
034                // arg[>0] = iterations
035                return args[args.length - 1].evaluate();
036        }
037
038        @Override
039        public FunctionParameter[] getParameters() {
040                return parameters;
041        }
042
043        @Override
044        public boolean isVarArg() {
045                return true;
046        }
047
048}