예제 #1
0
        public void BooleanFilterTest()
        {
            string input = "A[?]," +
                           "A[?]," +
                           "A[?]," +
                           "B[]" +
                           "; A[@.:v == 5] *--> B";

            var p = new ResedaParser();

            p.dispTree(input);

            var term  = p.Generate(input);
            var term2 = p.Generate(term.subProcess.ToSource());

            Assert.AreEqual(term.ToSource(), term2.ToSource());



            InputEvent  a0 = (InputEvent)term.subProcess.structuredData[0];
            InputEvent  a1 = (InputEvent)term.subProcess.structuredData[1];
            InputEvent  a2 = (InputEvent)term.subProcess.structuredData[2];
            OutputEvent b  = (OutputEvent)term.subProcess.structuredData[3];


            a0.Execute(1);
            System.Diagnostics.Debug.WriteLine(term.PrintTree(true));

            a1.Execute(5);
            System.Diagnostics.Debug.WriteLine(term.PrintTree(true));

            a2.Execute(3);
            System.Diagnostics.Debug.WriteLine(term.PrintTree(true));
        }
예제 #2
0
        public void GuardedCondition()
        {
            string input = @"A[],
B[],
D[],
C[];
A[(count(@/C)==0)] -->* B,
D -->* C
";
            var    p     = new ResedaParser();

            p.dispTree(input);
            var term = p.Generate(input);

            System.Diagnostics.Debug.WriteLine(term.subProcess.ToSource());
            var term2 = p.Generate(term.subProcess.ToSource());

            Assert.AreEqual(term.ToSource(), term2.ToSource());
            OutputEvent a = (OutputEvent)term.subProcess.structuredData[0];
            OutputEvent b = (OutputEvent)term.subProcess.structuredData[1];
            OutputEvent d = (OutputEvent)term.subProcess.structuredData[2];
            OutputEvent c = (OutputEvent)term.subProcess.structuredData[3];

            Assert.IsTrue(b.IsEnabled());
            b.Execute();

            Assert.IsFalse(c.IsEnabled());
            Assert.ThrowsException <Exception>(() =>
            {
                c.Execute();
            });
        }
예제 #3
0
        public void Example2()
        {
            string input = @"!name[?],
!price[?],
!quantity[?],
amount[@price:value * @quantity:value],
invoiceRow[@name:value + ';' + @price:value + ';' + @quantity:value + ';' + @amount:value],
checkout[?],
ship[?]
~
name --><> checkout,
price --><> checkout,
quantity --><> checkout, 
checkout -->% name,
checkout -->% price,
checkout -->% quantity,
checkout -->* ship,
checkout*--> ship,
ship -->% checkout
";
            var    p     = new ResedaParser();

            p.dispTree(input);
            var term = p.Generate(input);

            System.Diagnostics.Debug.WriteLine(term.subProcess.ToSource());
            var term2 = p.Generate(term.subProcess.ToSource());

            Assert.AreEqual(term.ToSource(), term2.ToSource());
        }
예제 #4
0
        public void Example3()
        {
            string input = @"itemInCart[!]{
  data[!]{
        !name[?],
        !price[?], 
        !quantity[?],
        amount[@price:value * @quantity:value],
        invoiceRow[@name:value + ';' + @price:value + ';' + @quantity:value + ';' + @amount:value]
        ~
        * --><> ../../checkout
      }
},
checkout[?],
ship[?],
%printInvoice[@itemInCart/data/invoiceRow]
~
checkout -->%  itemInCart/data,
checkout -->* ship,
checkout *--> ship,
ship -->% checkout,
ship -->+ printInvoice,
ship *--> printInvoice";
            var    p     = new ResedaParser();

            p.dispTree(input);
            var term = p.Generate(input);

            System.Diagnostics.Debug.WriteLine(term.subProcess.ToSource());
            var term2 = p.Generate(term.subProcess.ToSource());

            Assert.AreEqual(term.ToSource(), term2.ToSource());
        }
예제 #5
0
        public void BPMExample2()
        {
            string input = @"customers[]{
    create_customer[?],
    customer[] {
      customer_id[0],
      customer_name['John']  
    },
    customer[]{
      customer_id[1],
      customer_name['Mary']
    }
    ~
    create_customer -->> {
        customer[]{
            !customer_id[freshid()],
            !customer_name[?:string]
}
    }
}
";
            var    p     = new ResedaParser();

            p.dispTree(input);
            var term = p.Generate(input);

            System.Diagnostics.Debug.WriteLine(term.subProcess.ToSource());
            var term2 = p.Generate(term.subProcess.ToSource());

            Assert.AreEqual(term.ToSource(), term2.ToSource());
        }
예제 #6
0
        public void MarkingTest()
        {
            string input = "%!A[?]," +
                           "!B[?]," +
                           "%C[?]," +
                           "!%D[?]" +
                           ";" +
                           "";
            var p = new ResedaParser();

            p.dispTree(input);

            //System.Diagnostics.Debug.WriteLine(p.Generate(input).PrintTree());

            var term = p.Generate(input);

            System.Diagnostics.Debug.WriteLine(term.subProcess.ToSource());

            //var term2 = term.CloneJson();
            var term2 = p.Generate(term.subProcess.ToSource());

            Assert.AreEqual(term.ToSource(), term2.ToSource());


            //Assert.AreEqual(term.ToSource(), term.shallow().ToSource());
        }
예제 #7
0
        public void BPMExample4()
        {
            string input = @"orders[]{
    create_order[?:@../customers/customer/customer_id:value]
    ~
    create_order -->>{
        order[]{
            !order_id[freshid()],
            !customer_id[@trigger:value],
            !pick_item[?:@../../products/product/product_id:value]
            ~
            pick_item -->>{
                order_line[]{
                    !order_line_id[freshid()],
                    !product_id[@trigger:value],
                    !wrap_item[?:@order_line_id:value]
                    ~
                    wrap_item -->% wrap_item
                }
            }
        }
    }
}
";
            var    p     = new ResedaParser();

            p.dispTree(input);
            var term = p.Generate(input);

            System.Diagnostics.Debug.WriteLine(term.subProcess.ToSource());
            var term2 = p.Generate(term.subProcess.ToSource());

            Assert.AreEqual(term.ToSource(), term2.ToSource());
        }
예제 #8
0
        public void BasicPathParserTest()
        {
            string input = "A/B";
            var    p     = new ResedaParser();
            var    path  = p.GeneratePath(input);
            var    path2 = p.GeneratePath(path.ToSource());

            Assert.AreEqual(path.ToSource(), "A/B");
            Assert.AreEqual(path.ToSource(), path2.ToSource());
            System.Diagnostics.Debug.WriteLine(path.ToSource());
        }
예제 #9
0
        public void BPMExample5()
        {
            string input = @"deliveries[]{
   ~   
   ../orders/create_order -->> { 
     delivery[]{
       delivery_id[freshid()],
       deliver_items[?:@trigger:value],
       customer_id[@trigger:value],
       items_to_deliver[]{
         ~
         /orders/order[@customer_id:value==@trigger:value]/order_line/wrap_item[@/deliver_items:included] 
             -->> {
                 !item_id[@trigger:value]
             }
       }
       ~
       deliver_items -->% deliver_items,
       deliver_items[count(@items_to_deliver/*)==0] -->* deliver_items 
    }
  },
   delivery/deliver_items -->> { 
     delivery[]{
       delivery_id[freshid()],
       deliver_items[?:@trigger:value],
       customer_id[@trigger:value],
       items_to_deliver[]{
         ~
         /orders/order[@customer_id:value==@trigger:value]/order_line/wrap_item[@/deliver_items:included] 
             -->> {
                 !item_id[@trigger:value]
             }
       }
       ~
       deliver_items -->% deliver_items,
       deliver_items[count(@items_to_deliver/*)==0] -->* deliver_items 
    }
  }  
}



    ";
            var    p     = new ResedaParser();

            p.dispTree(input);
            var term = p.Generate(input);

            System.Diagnostics.Debug.WriteLine(term.subProcess.ToSource());
            var term2 = p.Generate(term.subProcess.ToSource());

            Assert.AreEqual(term.ToSource(), term2.ToSource());
        }
예제 #10
0
        public void BPMTestThomas()
        {
            string input = @"orders[]{
 create_order[?:@/customers/customer/customer_id:value]
 ;
 create_order -->>{
 order[]{
 !order_id[freshid()],
 !customer_id[@trigger:value]
 }
}
},
customers[]{
 create_customer[?],
 customer[] {
 customer_id(0)[],
 customer_name('John')[] 
 },
 customer[]{
 customer_id(1)[],
 customer_name('Mary')[]
 }
 ;
 create_customer -->> {
 customer[]{
 !customer_id[freshid()],
 !customer_name[?]
 }
 }
}";
            var    p     = new ResedaParser();

            p.dispTree(input);
            var term = p.Generate(input);

            System.Diagnostics.Debug.WriteLine(term.subProcess.ToSource());
            var term2 = p.Generate(term.subProcess.ToSource());

            //Assert.AreEqual(term.ToSource(), term2.ToSource());
            InputEvent create_order = (InputEvent)term.subProcess.structuredData[0].subProcess.structuredData[0];

            create_order.Execute(1);

            System.Diagnostics.Debug.WriteLine(term.ToSource());

            OutputEvent o1 = (OutputEvent)term.subProcess.structuredData[0].subProcess.structuredData[1].subProcess.structuredData[0];
            OutputEvent o2 = (OutputEvent)term.subProcess.structuredData[0].subProcess.structuredData[1].subProcess.structuredData[1];

            o1.Execute();
            o2.Execute();
            System.Diagnostics.Debug.WriteLine(term.ToSource());
        }
예제 #11
0
        public void InitialValueTest()
        {
            string input = @"
!A(3)[?],
!B[?],
!C(1)[freshid()];";
            var    p     = new ResedaParser();

            p.dispTree(input);
            var         term = p.Generate(input);
            InputEvent  a    = (InputEvent)term.subProcess.structuredData[0];
            InputEvent  b    = (InputEvent)term.subProcess.structuredData[1];
            OutputEvent c    = (OutputEvent)term.subProcess.structuredData[2];

            System.Diagnostics.Debug.WriteLine(term.subProcess.ToSource());
            var term2 = p.Generate(term.subProcess.ToSource());

            Assert.AreEqual(term.ToSource(), term2.ToSource());

            Assert.AreEqual(c.marking.value.ToString(), "1");
            Assert.AreEqual(a.marking.value.ToString(), "3");
            Assert.IsNull(b.marking.value);
            c.Execute();
            Assert.AreEqual(c.marking.value.ToString(), "4");
            b.Execute(1);
            Assert.AreEqual(c.marking.value.ToString(), "4");
            a.Execute(5);
            Assert.AreEqual(a.marking.value.ToString(), "5");
            c.Execute();
            Assert.AreEqual(c.marking.value.ToString(), "6");

            /*
             * c.Execute();
             * System.Diagnostics.Debug.WriteLine(c.ToSource());
             * System.Diagnostics.Debug.WriteLine(c.marking.value);
             * Assert.AreEqual(c.marking.value.ToString(), "0");
             * c.Execute();
             * Assert.AreEqual(c.marking.value.ToString(), "1");
             * a.Execute(3);
             * c.Execute();
             * Assert.AreEqual(c.marking.value.ToString(), "4");
             *
             * b.Execute(1);
             * c.Execute();
             * Assert.AreEqual(c.marking.value.ToString(), "5");
             *
             * b.Execute(10);
             * c.Execute();
             * Assert.AreEqual(c.marking.value.ToString(), "11");
             */
        }
예제 #12
0
        public void SpawnIterator()
        {
            string input = @"A[?],
B[?]
~
A -->> {C[!]},
B -(p in C)->> {D[!]}
";
            var    p     = new ResedaParser();

            p.dispTree(input);
            var term = p.Generate(input);

            System.Diagnostics.Debug.WriteLine(term.subProcess.ToSource());
            var term2 = p.Generate(term.subProcess.ToSource());

            Assert.AreEqual(term.ToSource(), term2.ToSource());
        }
예제 #13
0
        public void FunctionTest()
        {
            string input = @"
!name[?],
!price[?],
!quantity[freshid()],
amount[afuntion(@price:value * @quantity:value)],
invoiceRow[@name:value + ';' + @price:value + ';' + @quantity:value + ';' + @amount:value]";
            var    p     = new ResedaParser();

            p.dispTree(input);
            var term = p.Generate(input);

            System.Diagnostics.Debug.WriteLine(term.subProcess.ToSource());
            var term2 = p.Generate(term.subProcess.ToSource());

            Assert.AreEqual(term.ToSource(), term2.ToSource());
        }
예제 #14
0
        public void BoundedTest()
        {
            var p = new ResedaParser();


            string input = "A[?]," +
                           "A[?]," +
                           "A[?]," +
                           "B[]" +
                           "; A[@.:v == 5] *--> B";
            var term = p.Generate(input);

            Assert.IsTrue(term.Bounded());


            input = "B[]" +
                    "; B -->> {B[];}";
            term = p.Generate(input);
            Assert.IsFalse(term.Bounded());


            input = "B[]" +
                    "; * -->> {C[];}";
            term = p.Generate(input);
            Assert.IsFalse(term.Bounded());

            input = "B[]" +
                    "; B -->> {C[];C -->> {C[];}}";
            term = p.Generate(input);
            Assert.IsFalse(term.Bounded());


            input = "B[]{A[]; A-->> {A[];}}" +
                    ";";
            term = p.Generate(input);
            Assert.IsFalse(term.Bounded());

            // Cycles
            input = "B[]" +
                    "; B -->> {C[];}, C -->> {B[];}";
            term = p.Generate(input);
            Assert.IsFalse(term.Bounded());
        }
예제 #15
0
        public void Example1()
        {
            string input = @"# First step:
# ** Input and computational events
!name[?],
!price[?],
!quantity[?],
amount[@price:value * @quantity:value],
invoiceRow[@name:value + ';' + @price:value + ';' + @quantity:value + ';' + @amount:value]";
            var    p     = new ResedaParser();

            p.dispTree(input);
            var term = p.Generate(input);

            System.Diagnostics.Debug.WriteLine(term.subProcess.ToSource());
            var term2 = p.Generate(term.subProcess.ToSource());

            Assert.AreEqual(term.ToSource(), term2.ToSource());
        }
예제 #16
0
        public void BPMExample1()
        {
            string input = @"customer[] {
  customer_id(0)[0],
  customer_name['John']  
},
customer[]{
  customer_id[1],
  customer_name['Mary']
    }";
            var    p     = new ResedaParser();

            p.dispTree(input);
            var term = p.Generate(input);

            System.Diagnostics.Debug.WriteLine(term.subProcess.ToSource());
            var term2 = p.Generate(term.subProcess.ToSource());

            Assert.AreEqual(term.ToSource(), term2.ToSource());
        }
예제 #17
0
        public void BasicParserTest()
        {
            string input = "A[ 2 * 2 + 4 ]," +
                           "B[3 + 4 + 5 * 6 + 7 + 8 + 9]{C[1 + (3 * 5) - @c/d];}" +
                           "; A -->* /B," +
                           " A/*/C -->* /B/.././F,"
                           + "B -->% *";
            var p = new ResedaParser();

            p.dispTree(input);

            var term  = p.Generate(input);
            var term2 = p.Generate(term.ToSource());

            Assert.AreEqual(term.ToSource(), "A[2 * 2 + 4],B[3 + 4 + 5 * 6 + 7 + 8 + 9]{C[1 + 3 * 5 - @c/d];};A -->* /B,A/*/C -->* /B/.././F,B -->% *");
            Assert.AreEqual(term.ToSource(), term2.ToSource());



            //System.Diagnostics.Debug.WriteLine(p.Generate(input).PrintTree());

            /*
             * var term = p.Generate(input);
             * System.Diagnostics.Debug.WriteLine(term.PrintTree());
             * System.Diagnostics.Debug.WriteLine(term.PrintTree(true));
             *
             * var c = (Condition)term.subProcess.relations[0];
             * System.Diagnostics.Debug.WriteLine(c.source.ToString());
             * System.Diagnostics.Debug.WriteLine(c.target.ToString());
             *
             * c = (Condition)term.subProcess.relations[1];
             * System.Diagnostics.Debug.WriteLine(c.source.ToString());
             * System.Diagnostics.Debug.WriteLine(c.target.ToString());
             *
             * term.subProcess.structuredData[0].Execute();
             * System.Diagnostics.Debug.WriteLine(term.PrintTree(true));
             *
             * term.subProcess.structuredData[1].Execute();
             * System.Diagnostics.Debug.WriteLine(term.PrintTree(true));
             */
        }
예제 #18
0
        public void BooleanExpresionTest()
        {
            string input = "A[?]," +
                           "B[?]," +
                           "C[@A:v + @B:v > 5 && !(@A:v - @B:v > 10)]" +
                           "; ";

            var p = new ResedaParser();

            p.dispTree(input);

            var term  = p.Generate(input);
            var term2 = p.Generate(term.subProcess.ToSource());

            Assert.AreEqual(term.ToSource(), term2.ToSource());



            InputEvent  a = (InputEvent)term.subProcess.structuredData[0];
            InputEvent  b = (InputEvent)term.subProcess.structuredData[1];
            OutputEvent c = (OutputEvent)term.subProcess.structuredData[2];



            a.Execute(3);
            b.Execute(5);
            System.Diagnostics.Debug.WriteLine(term.PrintTree(true));

            c.Execute();
            var val = (BoolType)c.marking.value;

            Assert.AreEqual(val.value, true);
            System.Diagnostics.Debug.WriteLine(term.PrintTree(true));


            a.Execute(20);
            c.Execute();
            val = (BoolType)c.marking.value;
            Assert.AreEqual(val.value, false);
            System.Diagnostics.Debug.WriteLine(term.PrintTree(true));
        }
예제 #19
0
        public void CloneTestDataExpression()
        {
            string input = "A[5 * 6]" +
                           ";";
            var p = new ResedaParser();

            p.dispTree(input);

            //System.Diagnostics.Debug.WriteLine(p.Generate(input).PrintTree());

            var term  = p.Generate(input);
            var term2 = term.Clone(null);

            System.Diagnostics.Debug.WriteLine(term.subProcess.ToSource());
            System.Diagnostics.Debug.WriteLine(term2.subProcess.ToSource());

            Assert.AreEqual(term.ToSource(), term2.ToSource());


            //Assert.AreEqual(term.ToSource(), term.shallow().ToSource());
        }
예제 #20
0
        public void CountTest()
        {
            string input = @"
!A[?],
!A[?],
!C[count(@A)];";
            var    p     = new ResedaParser();

            p.dispTree(input);
            var         term = p.Generate(input);
            OutputEvent c    = (OutputEvent)term.subProcess.structuredData[2];

            System.Diagnostics.Debug.WriteLine(term.subProcess.ToSource());
            var term2 = p.Generate(term.subProcess.ToSource());

            Assert.AreEqual(term.ToSource(), term2.ToSource());
            c.Execute();
            System.Diagnostics.Debug.WriteLine(c.ToSource());
            System.Diagnostics.Debug.WriteLine(c.marking.value);
            Assert.AreEqual(c.marking.value.ToString(), "2");
        }
예제 #21
0
        public void BPMExample3()
        {
            string input = @"products[]{
    create_product[?]
    ~
    create_product -->>{
        product[]{
            !product_id[freshid()],
            !product_name[?:string]
        }
    }
}";
            var    p     = new ResedaParser();

            p.dispTree(input);
            var term = p.Generate(input);

            System.Diagnostics.Debug.WriteLine(term.subProcess.ToSource());
            var term2 = p.Generate(term.subProcess.ToSource());

            Assert.AreEqual(term.ToSource(), term2.ToSource());
        }
예제 #22
0
        public void FilterTest()
        {
            string input = "A[]," +
                           "B[]," +
                           "B[]," +
                           "C[]" +
                           "; A -->* B[1]";

            var p = new ResedaParser();

            p.dispTree(input);

            var term  = p.Generate(input);
            var term2 = p.Generate(term.subProcess.ToSource());

            Assert.AreEqual(term.ToSource(), term2.ToSource());



            OutputEvent a  = (OutputEvent)term.subProcess.structuredData[0];
            OutputEvent b0 = (OutputEvent)term.subProcess.structuredData[1];
            OutputEvent b1 = (OutputEvent)term.subProcess.structuredData[2];
            OutputEvent c  = (OutputEvent)term.subProcess.structuredData[3];


            b0.Execute();
            System.Diagnostics.Debug.WriteLine(term.PrintTree(true));

            try
            {
                b1.Execute();
                Assert.Fail();
            }
            catch
            { }

            System.Diagnostics.Debug.WriteLine(term.PrintTree(true));
        }
예제 #23
0
        public void SpawnTrigger()
        {
            string input = @"A[?],
B[?]
;
A -->> {C[@trigger:v];}";
            var    p     = new ResedaParser();

            p.dispTree(input);
            var term = p.Generate(input);

            System.Diagnostics.Debug.WriteLine(term.subProcess.ToSource());
            var term2 = p.Generate(term.subProcess.ToSource());

            Assert.AreEqual(term.ToSource(), term2.ToSource());
            InputEvent a = (InputEvent)term.subProcess.structuredData[0];
            InputEvent b = (InputEvent)term.subProcess.structuredData[1];

            a.Execute(15);
            OutputEvent c = (OutputEvent)term.subProcess.structuredData[2];

            System.Diagnostics.Debug.WriteLine(term.subProcess.ToSource());
        }
예제 #24
0
        public void InputTypeTest()
        {
            string input = @"customers[]{
    create_customer[?],
    customer[] {
      customer_id(0)[?],
      customer_name('John')[?]  
    },
    customer[]{
      customer_id(1)[?],
      customer_name('Mary')[?]
    }
    ~
    create_customer -->> {
        customer[]{
            !customer_id[freshid()],
            !customer_name[?]
}
    }
},
viewcustomer[?:@/customers/customer/customer_id:value]
";
            var    p     = new ResedaParser();

            p.dispTree(input);
            var term = p.Generate(input);

            System.Diagnostics.Debug.WriteLine(term.subProcess.ToSource());
            var term2 = p.Generate(term.subProcess.ToSource());
            //Assert.AreEqual(term.ToSource(), term2.ToSource());

            InputEvent viewcustomer = (InputEvent)term.subProcess.structuredData[1];

            System.Diagnostics.Debug.WriteLine(viewcustomer.ValidInputs().ToString());
            viewcustomer.Execute(1);
        }
예제 #25
0
        public void CloneTest()
        {
            string input = "A[?]{D[?];}" +
                           ";" +
                           " A -->> {B[?]{C[?];};}";
            var p = new ResedaParser();

            p.dispTree(input);

            //System.Diagnostics.Debug.WriteLine(p.Generate(input).PrintTree());

            var term = p.Generate(input);

            System.Diagnostics.Debug.WriteLine(term.subProcess.ToSource());
            InputEvent d = (InputEvent)term.subProcess.structuredData[0].subProcess.structuredData[0];

            //var term2 = term.CloneJson();
            var term2 = p.Generate(term.subProcess.ToSource());

            Assert.AreEqual(term.ToSource(), term2.ToSource());


            //Assert.AreEqual(term.ToSource(), term.shallow().ToSource());
        }
예제 #26
0
        public void SpawnTriggerInitialValue()
        {
            string input = @"A(3)[?],
B[?]
;
A -->> {C(@trigger:v)[?];}, 
B -->> {C(@trigger:v)[?];}";
            var    p     = new ResedaParser();

            p.dispTree(input);
            var term = p.Generate(input);

            System.Diagnostics.Debug.WriteLine(term.subProcess.ToSource());
            var term2 = p.Generate(term.subProcess.ToSource());

            Assert.AreEqual(term.ToSource(), term2.ToSource());
            InputEvent a = (InputEvent)term.subProcess.structuredData[0];
            InputEvent b = (InputEvent)term.subProcess.structuredData[1];

            Assert.AreEqual(a.marking.value.ToString(), "3");
            Assert.IsNull(b.marking.value);
            a.Execute(15);
            InputEvent c = (InputEvent)term.subProcess.structuredData[2];

            System.Diagnostics.Debug.WriteLine(term.subProcess.ToSource());
            Assert.AreEqual(c.marking.value.ToString(), "15");
            Assert.IsNull(b.marking.value);
            b.Execute(45);
            InputEvent c2 = (InputEvent)term.subProcess.structuredData[3];

            System.Diagnostics.Debug.WriteLine(term.subProcess.ToSource());
            Assert.AreEqual(c2.marking.value.ToString(), "45");
            Assert.AreEqual(b.marking.value.ToString(), "45");
            Assert.AreEqual(a.marking.value.ToString(), "15");
            Assert.AreEqual(c.marking.value.ToString(), "15");
        }
예제 #27
0
        static void Main(string[] args)
        {
            parser = new ResedaParser();
            var exit = false;

            while (exit == false)
            {
                Console.WriteLine();
                Console.WriteLine("Enter command (help to display help): ");
                var commandParts = Console.ReadLine().Split(' ').ToList();
                var commandName  = commandParts[0];
                var commandArgs  = commandParts.Skip(1).ToList(); // the arguments is after the command
                try
                {
                    switch (commandName)
                    {
                    // Create command based on CommandName (and maybe arguments)
                    case "exit": exit = true; break;

                    case "parse":
                        String s = "";
                        foreach (var i in commandArgs)
                        {
                            s += i + " ";
                        }
                        Parse(s);
                        break;

                    case "load":
                        Load(commandArgs[0]);
                        break;

                    case "term": Console.WriteLine(term.ToSource()); break;

                    case "auto": autoCompute = !autoCompute;  Console.WriteLine(autoCompute); break;

                    case "tree": Console.WriteLine(term.PrintTree(true)); break;

                    case "live": Console.WriteLine(term.ProcessIsLive()); break;

                    case "inseq": term = term.MakeInSeq(); break;

                    case "glitchfree": term = term.MakeGlitchFree(); break;

                    case "list":
                        foreach (var pe in term.GetAllEnabledEvents())
                        {
                            Console.WriteLine(pe.ToSource());
                        }
                        break;

                    case "execute":
                        if (commandArgs.Count > 1)
                        {
                            Execute(commandArgs[0], commandArgs[1]);
                        }
                        else
                        {
                            Execute(commandArgs[0]);
                        }
                        break;

                    default:
                        if (commandArgs.Count > 0)
                        {
                            Execute(commandName, commandArgs[0]);
                        }
                        else
                        {
                            Execute(commandName);
                        }

                        break;
                    }
                }
                catch (Exception e)
                {
                    Console.WriteLine("Command " + commandName + "failed, because:");
                    Console.WriteLine(e.Message);
                }
            }
        }
예제 #28
0
        public void ProcessIsLiveTest()
        {
            var p = new ResedaParser();


            string input = "A[?]," +
                           "A[?]," +
                           "A[?]," +
                           "B[]" +
                           "; A[@.:v == 5] *--> B";
            var term = p.Generate(input);

            Assert.IsTrue(term.ProcessIsLive());


            input = "B[]" +
                    "; B -->> {B[];}";
            term = p.Generate(input);
            //System.Diagnostics.Debug.WriteLine(term.subProcess.ToSource());
            Assert.IsFalse(term.Bounded());
            Assert.IsFalse(term.ProcessIsLive());



            input = "A[?]," +
                    "B[]" +
                    "; A *--> B";
            term = p.Generate(input);
            Assert.IsTrue(term.ProcessIsLive());

            input = "A[?]," +
                    "B[]" +
                    "; A *--> A";
            term = p.Generate(input);
            Assert.IsTrue(term.ProcessIsLive());


            input = "A[?]," +
                    "B[]" +
                    "; A *--> B, B *--> A";
            term = p.Generate(input);
            Assert.IsTrue(term.ProcessIsLive());


            input = "A[?]," +
                    "B[]" +
                    "; A -->* B, B -->* A";
            term = p.Generate(input);
            Assert.IsFalse(term.ProcessIsLive());

            input = "A[?]," +
                    "B[]" +
                    "; A *--> B, B -->* A";
            term = p.Generate(input);
            Assert.IsFalse(term.ProcessIsLive());

            input = "A[?]," +
                    "B[]," +
                    "C[]" +
                    "; A -->* B, B -->* C, C -->* A";
            term = p.Generate(input);
            Assert.IsFalse(term.ProcessIsLive());


            input = "A[?]," +
                    "B[]," +
                    "C[]" +
                    "; A -->* B, B -->* C, C -->* A";
            term = p.Generate(input);
            Assert.IsFalse(term.ProcessIsLive());


            input = "A[?]{D[];}," +
                    "B[]," +
                    "C[]" +
                    "; D -->* C, C -->* B, B -->* A";
            term = p.Generate(input);
            Assert.IsTrue(term.ProcessIsLive());

            input = "A[?]{D[];}," +
                    "B[]," +
                    "C[]" +
                    "; A/D -->* C, C -->* B, B -->* A";
            term = p.Generate(input);
            Assert.IsFalse(term.ProcessIsLive());


            // typo: would be nice to syntax check this somehow as well, since it doesn't make sense to have this path expression.
            input = "A[?]{D[];}," +
                    "B[]," +
                    "C[]" +
                    "; D -->* C, C -->* B, B -->* A";
            term = p.Generate(input);
            Assert.IsTrue(term.ProcessIsLive());


            input = "A[?]," +
                    "B[?]," +
                    "C[@A:v + @B:v]," +
                    "N[]{A[];A-->>{D[],E[@../C:v];}};" +
                    "A-->*C," +
                    "B-->*C";
            term = p.Generate(input);
            Assert.IsTrue(term.ProcessIsLive());


            // Note: Responses do not need to be flattened!
            input = "A[?]{D[];}," +
                    "B[]," +
                    "C[]" +
                    "; A/D --><> C, C -->* B, B *--> A";
            term = p.Generate(input);
            Assert.IsTrue(term.ProcessIsLive());
        }
예제 #29
0
        public void CurrentHackingTest()
        {
            string input = "A[?]," +
                           "B[?]," +
                           "C[@A:v + @B:v * 10]," +
                           "D[]," +
                           "E[]" +
                           "; A -->* B," +
                           " D -->> {N[?];}," +
                           "E -->% *";
            var p = new ResedaParser();

            p.dispTree(input);

            //System.Diagnostics.Debug.WriteLine(p.Generate(input).PrintTree());

            var term = p.Generate(input);

            System.Diagnostics.Debug.WriteLine(term.subProcess.ToSource());

            //var term2 = term.CloneJson();
            var term2 = p.Generate(term.subProcess.ToSource());

            InputEvent  a = (InputEvent)term.subProcess.structuredData[0];
            InputEvent  b = (InputEvent)term.subProcess.structuredData[1];
            OutputEvent c = (OutputEvent)term.subProcess.structuredData[2];
            OutputEvent d = (OutputEvent)term.subProcess.structuredData[3];
            OutputEvent e = (OutputEvent)term.subProcess.structuredData[4];

            a.Execute(1);
            System.Diagnostics.Debug.WriteLine(term.PrintTree(true));

            b.Execute(5);
            System.Diagnostics.Debug.WriteLine(term.PrintTree(true));

            c.Execute();
            System.Diagnostics.Debug.WriteLine(term.PrintTree(true));

            d.Execute();
            System.Diagnostics.Debug.WriteLine(term.PrintTree(true));

            d.Execute();
            System.Diagnostics.Debug.WriteLine(term.PrintTree(true));

            System.Diagnostics.Debug.WriteLine("TERM 2");

            a = (InputEvent)term2.subProcess.structuredData[0];
            b = (InputEvent)term2.subProcess.structuredData[1];
            c = (OutputEvent)term2.subProcess.structuredData[2];
            d = (OutputEvent)term2.subProcess.structuredData[3];
            e = (OutputEvent)term2.subProcess.structuredData[4];

            System.Diagnostics.Debug.WriteLine(term2.PrintTree(true));
            a.Execute(1);
            System.Diagnostics.Debug.WriteLine(term2.PrintTree(true));

            b.Execute(5);
            System.Diagnostics.Debug.WriteLine(term2.PrintTree(true));

            c.Execute();
            System.Diagnostics.Debug.WriteLine(term2.PrintTree(true));

            d.Execute();
            System.Diagnostics.Debug.WriteLine(term2.PrintTree(true));

            d.Execute();
            System.Diagnostics.Debug.WriteLine(term2.PrintTree(true));
        }