Exemple #1
0
        public ExpDone()
        {
            /////////////////////////////////////////////////////
            //添加自定义函数
            P.CustomFunction += new SIS.Arithmetic.FunctionHandler(CustomFunction);

            //按此方式添加自定义函数名称,并在此类中实现。
            P.AddCustomFunction("CFSZBCLV", 2);
            P.AddCustomFunction("CFSZBCJJ", 4);
            P.AddCustomFunction("CFSZJJDD", 2);
            P.AddCustomFunction("CFSZQCLV", 4);

            //Added by pyf 2013-09-12
            P.AddCustomFunction("GETALARMCOUNT", 2);
            P.AddCustomFunction("TSK", 1);
            P.AddCustomFunction("PSK", 1);
            P.AddCustomFunction("POWERDIFF", 2);
            //End of Added.

            P.AddCustomFunction("AVG", 1);
            P.AddCustomFunction("IFF", 3);

            /////////////////////////////////////////////////////

            P.OnError += new ErrorHandler(OnError);
        }
Exemple #2
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 #3
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);
                    }
                }
            }
        }