static void Main(string[] args)
        {
            Host host = new Host();

            host.Trace      = false;
            host.TraceSteps = 100;
            host.Parameters.Add("a", "string parameter a");
            host.Parameters.Add("b", "string parameter b");

            host.Parameters.Add("i", 10);
            host.Parameters.Add("j", 0);

            host.Parameters.Add("x", 1.23);
            host.Parameters.Add("y", 0.56);

            string line = null;
            ActionQuery <ACValue>       ac = new ActionQuery <ACValue>();
            ActionQueryRunner <ACValue> runner;

            Console.WriteLine("Press enter on empty line for exit or enter an expression and press enter to execute it.");
            line = Console.ReadLine();
            while (!string.IsNullOrWhiteSpace(line))
            {
                runner = ac.Compile(line);
                if (runner.ErrorText != null)
                {
                    Console.WriteLine($"Compile error: {runner.ErrorText}");
                    Console.WriteLine("===> program dump ===");
                    Console.WriteLine(runner.DumpProgram());
                    Console.WriteLine("<=== end dump ===");
                    Console.WriteLine("try again");
                }
                else
                {
                    Console.WriteLine("=== program dump ===");
                    Console.WriteLine(runner.DumpProgram());
                    Console.WriteLine("=== program run follows ===");
                    try {
                        ACValue result = runner.ExecuteScalar(host);
                        Console.WriteLine($"Executed, result = {result.Value}");
                        Console.WriteLine("try again");
                    } catch (Exception ex) {
                        Console.WriteLine(ex);
                        Console.WriteLine("try again");
                    }
                }
                line = Console.ReadLine();
            }

            Console.WriteLine("Exiting ...");
        }
        static void Main(string[] args)
        {
            if (args.Length != 2)
            {
                Console.WriteLine("usage acrun <script> <configuration>");
                Console.WriteLine("Available functions in ac files are:");
                Console.WriteLine("  Add(a,b)");
                Console.WriteLine("  Equal(a,b)");
                Console.WriteLine("  Not(a)");
                Console.WriteLine("  Concat(a,b,c ...) as strings");
                return;
            }
            try {
                Console.WriteLine("Starting ...");
                string script = File.ReadAllText(args[0]);
                string conf   = File.ReadAllText(args[1]);
                Conf   cfg    = JsonSerializer.Deserialize <Conf>(conf);
                if (cfg.HardLimit == 0)
                {
                    cfg.HardLimit = 1;
                }
                if (cfg.TraceSteps == 0)
                {
                    cfg.TraceSteps = 100;
                }


                Host host = new Host(cfg);
                ActionQueryRunner <ACValue> runner;
                ActionQuery <ACValue>       ac = new ActionQuery <ACValue>();

                runner = ac.Compile(script);

                if (runner.ErrorText != null)
                {
                    Console.WriteLine($"Compile error: {runner.ErrorText}");
                    Console.WriteLine("===> program dump ===");
                    Console.WriteLine(runner.DumpProgram());
                    Console.WriteLine("<=== end dump ===");
                }
                else
                {
                    if (cfg != null && cfg.DumpProgram)
                    {
                        Console.WriteLine(runner.DumpProgram());
                    }
                    else
                    {
                        try {
                            ACValue result = runner.ExecuteScalar(host, cfg.HardLimit);
                            Console.WriteLine($"Executed, result = {result.Value}");
                        } catch (Exception ex) {
                            Console.WriteLine("runtime error: " + ex.Message);
                        }
                    }
                }
            } catch (IOException ex) {
                Console.WriteLine("Error reading the script or the configuration:" + ex.Message);
            }

            return;
        }
Beispiel #3
0
 public static ActionQueryRunner <ParameterResolverValue> Compile(string query)
 {
     return(_instance.Compile(query));
 }