Exemple #1
0
    // Update is called once per frame
    void Update()
    {
        windowX0 = -1 / scale;
        windowX0 = 1 / scale;

        if (graphString != "")
        {
//			try {
            Parser.AddCustomConstant("x", 0);
            Parser.AddCustomConstant("X", 0);
            parser = Parser.Parse(graphString);
            //float testValue = (float)((ScalarValue)parser.Execute()).Value;
//			}
//			catch (YAMPParseException ex0) {
//			}
//			catch (YAMPSymbolMissingException ex1) {
//			}
//			catch (YAMPArgumentNumberException ex2) {
//			}

            GenerateGraph();
        }
    }
Exemple #2
0
    public float GetY(float xValue)
    {
        float yValue;

        Parser.AddCustomConstant("x", (double)xValue);
        Parser.AddCustomConstant("X", (double)xValue);
        try     {
            yValue = (float)((ScalarValue)parser.Execute()).Value;
        }
        catch (YAMPParseException ex0) {
            yValue = 0;
        }
        catch (YAMPSymbolMissingException ex1) {
            yValue = 0;
        }

        if (float.IsNaN(yValue) || float.IsInfinity(yValue))
        {
            yValue = 0;
        }

        //yValue = expressionGeneric.Evaluate();
        return(yValue);
    }
Exemple #3
0
        public static void Run()
        {
            var query  = String.Empty;
            var buffer = new StringBuilder();
            var parser = new Parser();

            parser.LoadPlugin(typeof(PhysicsPlugin).Assembly);
            parser.LoadPlugin(typeof(SensorsPlugin).Assembly);
            parser.LoadPlugin(typeof(IoPlugin).Assembly);
            parser.LoadPlugin(typeof(SetsPlugin).Assembly);
            var exit = false;

            parser.InteractiveMode = true;
            parser.UseScripting    = true;

            parser.AddCustomFunction("G", v => new ScalarValue(((ScalarValue)v).Re * Math.PI));
            parser.AddCustomConstant("R", 2.53);

            parser.NotificationReceived += OnNotified;
            parser.UserInputRequired    += OnUserPrompt;
            parser.PauseDemanded        += OnPauseDemanded;

            while (!exit)
            {
                buffer.Remove(0, buffer.Length);
                Console.Write("> ");

                while (true)
                {
                    query = Console.ReadLine();

                    if (query.Length == 0 || query[query.Length - 1] != '\\')
                    {
                        buffer.Append(query);
                        break;
                    }

                    buffer.Append(query.Substring(0, query.Length - 1)).Append("\n");
                }

                query = buffer.ToString();
                exit  = query.Equals("exit");

                if (!exit)
                {
                    try
                    {
                        var value = parser.Evaluate(query);

                        if (value != null)
                        {
                            var result = value.ToString(parser.Context);
                            Console.WriteLine(result);
                        }
                    }
                    catch (YAMPParseException parseex)
                    {
                        Console.WriteLine(parseex.Message);
                        Console.WriteLine("---");
                        Console.Write(parseex.ToString());
                        Console.WriteLine("---");
                    }
                    catch (YAMPRuntimeException runex)
                    {
                        Console.WriteLine("An exception during runtime occured:");
                        Console.WriteLine(runex.Message);
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine(ex.Message);
                        Console.WriteLine(ex.StackTrace);
                    }
                }
            }
        }
Exemple #4
0
        public static void Run()
        {
            var query   = string.Empty;
            var buffer  = new StringBuilder();
            var context = Parser.PrimaryContext;

            Console.WriteLine();
            Console.WriteLine("*****************************************************************");
            Console.WriteLine("*                                                               *");
            Console.WriteLine("*                                                               *");
            Console.WriteLine("* Enter your own statements now (exit with the command 'exit'). *");
            Console.WriteLine("*                                                               *");
            Console.WriteLine("*                                                               *");
            Console.WriteLine("* You are in interactive mode with scripting being enabled.     *");
            Console.WriteLine("*                                                               *");
            Console.WriteLine("*                                                               *");
            Console.WriteLine("*****************************************************************");
            Console.WriteLine();

            Parser.InteractiveMode = true;
            Parser.UseScripting    = true;

            Parser.AddCustomFunction("G", v => new ScalarValue(((ScalarValue)v).Re * Math.PI));
            Parser.AddCustomConstant("R", 2.53);

            Parser.OnNotificationReceived += OnNotified;
            Parser.OnUserInputRequired    += OnUserPrompt;
            Parser.OnPauseDemanded        += OnPauseDemanded;

            while (true)
            {
                buffer.Remove(0, buffer.Length);
                Console.Write(">> ");

                while (true)
                {
                    query = Console.ReadLine();

                    if (query.Length != 0 && query[query.Length - 1] == '\\')
                    {
                        buffer.Append(query.Substring(0, query.Length - 1)).Append("\n");
                        continue;
                    }
                    else
                    {
                        buffer.Append(query);
                    }

                    break;
                }

                query = buffer.ToString();

                if (query.Equals("exit"))
                {
                    break;
                }
                else
                {
                    try
                    {
                        var result = context.Run(query);

                        if (result.Output != null)
                        {
                            Console.WriteLine(result.Result);
                            Console.Write(result.Parser);
                        }
                    }
                    catch (YAMPParseException parseex)
                    {
                        Console.WriteLine(parseex.Message);
                        Console.WriteLine("---");
                        Console.Write(parseex.ToString());
                        Console.WriteLine("---");
                    }
                    catch (YAMPRuntimeException runex)
                    {
                        Console.WriteLine("An exception during runtime occured:");
                        Console.WriteLine(runex.Message);
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine(ex.Message);
                        Console.WriteLine(ex.StackTrace);
                    }
                }
            }
        }