Пример #1
0
 public override object Evaluate(Frame environment)
 {
     isDecimal = false;
     if (environment == null)
     {
         throw new ArgumentNullException("Environment can not be null.");
     }
     List<object> paramValues = new List<object>();
     foreach (String param in Parameters)
     {
         if (param == ".")
         {
             continue;
         }
         object binding = environment.FindBindingValue(param);
         if (binding == null)
         {
             throw new Exception("can't find binding");
         }
         paramValues.Add(GetNumber(binding));
     }
     object restText = environment.FindBindingValue(".");
     if (restText != null)
     {
         RestParameters rest = (RestParameters)restText;
         foreach (object number in rest.Values)
         {
             paramValues.Add(GetNumber(number));
         }
     }
     return EvaluateResult(paramValues);
 }
Пример #2
0
        public override object Evaluate(Frame environment)
        {
            if (environment == null)
            {
                throw new ArgumentNullException("Environment can not be null.");
            }
            List<double> paramValues = new List<double>();
            foreach (String param in Parameters)
            {
                String binding = environment.FindBindingValue(param).ToString();
                if (binding == null)
                {
                    throw new Exception("can't find binding");
                }
                double number;
                if (double.TryParse(binding, out number))
                {
                    paramValues.Add(number);
                }
            }
            if (paramValues.Count < 2)
            {
                throw new Exception("Illegal number of arguments, need at least 2.");
            }

            return CompareValues(paramValues[0], paramValues[1]);
        }
Пример #3
0
        public override object Evaluate(Frame environment)
        {
            if (environment == null)
            {
                throw new ArgumentNullException("Environment can not be null.");
            }
            string path = environment.FindBindingValue(Parameters[0]).ToString();
            if (!File.Exists(path))
            {
                throw new Exception("Could not find file: " + path);
            }

            using (StreamReader codeReader = new StreamReader(File.Open(path, FileMode.Open)))
            {
                Scanner scanner = new Scanner(codeReader);

                Expression expr = scanner.NextExpression;
                string evaluation = string.Empty;
                while (expr != null)
                {
                    evaluation = environment.Evaluate(expr).ToString();
                    expr = scanner.NextExpression;
                }

                return evaluation;
            }
        }
Пример #4
0
 public override object Evaluate(Frame environment)
 {
     if (Parameters.Count <= 0)
     {
         throw new Exception("Invalid number of parameters.");
     }
     SList list = environment.FindBindingValue(Parameters[0]) as SList;
     return list.IsEmpty;    //TODO what if it's not a list, but a binding that can't be found.
 }
Пример #5
0
 public override object Evaluate(Frame environment)
 {
     if (Parameters.Count <= 0) //TODO WTF! How can this be 0??
     {
         throw new Exception("Invalid number of parameters.");
     }
     string message = environment.FindBindingValue(Parameters[0]).ToString();
     throw new InterpreterException(message);
 }
Пример #6
0
 public override object Evaluate(Frame environment)
 {
     if (environment == null)
     {
         throw new ArgumentNullException("Environment can not be null.");
     }
     object value = environment.FindBindingValue(Parameters[0]);
     Console.Write(value);
     return string.Empty;
 }
Пример #7
0
        public override object Evaluate(Frame environment)
        {
            if (environment == null)
            {
                throw new ArgumentNullException("cons: Environment can not be null.");
            }

            object firstBinding = environment.FindBindingValue(Parameters[0]);
            if (firstBinding == null)
            {
                throw new Exception("cons: Can't find binding for first argument.");
            }
            object restBinding = environment.FindBindingValue(Parameters[1]);
            if (restBinding == null)
            {
                throw new Exception("cons: Can't find binding for second argument.");
            }
            return ConsFactory.CreatePair(firstBinding, restBinding);
        }
Пример #8
0
 public override object Evaluate(Frame environment)
 {
     if (environment == null)
     {
         throw new ArgumentNullException("sin: Environment can not be null.");
     }
     double angle = 0;
     if (!double.TryParse(environment.FindBindingValue(Parameters[0]).ToString(), out angle))
     {
         throw new Exception("sin: Argument must be an number.");
     }
     return _function(angle);
 }
Пример #9
0
 public override object Evaluate(Frame environment)
 {
     if (environment == null)
     {
         throw new ArgumentNullException("Environment can not be null.");
     }
     object predicate = environment.FindBindingValue(Parameters[0]);
     bool result = false;
     if (!bool.TryParse(predicate.ToString(), out result))
     {
         throw new Exception("not: parameter not a predicate.");
     }
     return !result;
 }
Пример #10
0
        public override object Evaluate(Frame environment)
        {
            if (environment == null)
            {
                throw new ArgumentNullException("Environment can not be null.");
            }

            object pairObject = environment.FindBindingValue(Parameters[0]);
            if (pairObject == null || !(pairObject is IPair))
            {
                throw new Exception("Invalid argument: not a pair");
            }
            IPair pair = (IPair)pairObject;
            return GetPairPart(pair);
        }
Пример #11
0
 public override object Evaluate(Frame environment)
 {
     if (environment == null)
     {
         throw new ArgumentNullException("Environment can not be null.");
     }
     int limit;
     object bindingValue = environment.FindBindingValue(Parameters[0]);
     if (bindingValue is int)
     {
         limit = (int)bindingValue;
     }
     else if (!int.TryParse(bindingValue.ToString(), out limit))
     {
         throw new Exception("random: Argument must be an integer");
     }
     System.Random rand = new System.Random();
     int result = rand.Next(limit);
     return result;
 }
Пример #12
0
 public override object Evaluate(Frame environment)
 {
     object first = environment.FindBindingValue(Parameters[0]); //TODO maybe FindBindingValue should throw an exception if a binding is not found.
     RestParameters rest = (RestParameters)environment.FindBindingValue(Parameters[1]);
     return new SList(first,rest.Values.Cast<object>());
 }