Пример #1
0
        public static object EvaluateInput(string input)
        {
            if (input.Contains("=="))//comparison operator
            {
                string[] parts = input.Split("==");

                object original = Parse.ParseAnything(parts[0]);

                //compare all of the following to the original object
                for (int i = 1; i < parts.Length; i++)
                {
                    //if not equal, return now
                    if (!Function.compare(original, Parse.ParseAnything(parts[i])))
                    {
                        return(false);
                    }
                }

                //if it made it this far, it is equal
                return(true);
            }
            else if (input.Contains('='))  //assignment operator
            {
                string[] parts = input.Split('=');

                if (parts.Length > 2)
                {
                    PrintError("You can only use one assignment operator (=) in one line. (Input.EvaluateInput)");
                    return(null);
                }

                string name = parts[0].Trim();

                object value = Parse.ParseAnything(parts[1]);

                Sandbox.SetVariable(name, value);

                return(value);
            }
            else
            {
                return(Parse.ParseAnything(input));
            }
        }
Пример #2
0
        private static void UseFunction(string funcChoice)
        {
            //get the function itself
            System.Reflection.MethodInfo mi = Function.GetFunctionFromFullName(funcChoice);

            string funcName = mi.Name;

            //get the parameters so we know what to ask
            System.Reflection.ParameterInfo[] pis = mi.GetParameters();

            object[] args = new object[pis.Length];

            Clear();

            //LINE 1: Preview of function
            //LINE 2: Instructions
            //LINE 3: Input

            int argsEntered = 0;

            while (argsEntered < args.Length)
            {
                Type t = pis[argsEntered].ParameterType;

                Console.SetCursorPosition(0, 0);
                PrintPartialFunction(funcName, args);

                Console.SetCursorPosition(0, 1);
                Console.Write(string.Format("Enter a {0}.{1}", t.Name.ToLower(), new string(' ', 30)));//write the instructions

                Console.SetCursorPosition(0, 2);

                object input = null;

                if (t == typeof(string))
                {
                    input = EnterString();
                }
                else if (t == typeof(MathNet.Symbolics.SymbolicExpression))
                {
                    input = EnterExpression();
                }
                else if (t.IsArray)
                {
                    input = ParseDoubleArray(EnterString());
                }
                else if (t == typeof(int))
                {
                    input = EnterInt();
                }
                else if (t == typeof(double))
                {
                    input = EnterDouble();
                }
                else if (t == typeof(bool))
                {
                    input = EnterBool();
                }
                else
                {
                    input = EnterString();
                }

                args[argsEntered++] = input;

                Console.SetCursorPosition(0, 2);
                Console.Write(new string(' ', input.ToString().Length + 1));
            }

            //input is done, print the output info and then go into sanbox mode
            Clear();

            object output = Function.EvaluateFunction(funcName, args);

            Sandbox.SetVariable("ans", output);

            PrintPartialFunction(funcName, args);
            PrintLine();
            Print(string.Format("ans = {0}", output));
            Print("Use ans to refer to your answer.");
            PrintLine(2);

            Sandbox.SandboxLoop(false);
        }