Esempio n. 1
0
        public void DFA_triggers_actions_correctly()
        {
            // Given alphabet
            const int A = 0;
            const int B = 1;

            // Given actions
            const int Action0 = 1001;
            const int Action1 = 1002;
            const int Action2 = 1003;

            GivenRegularExpression(
                AstNode.Or(
                    AstNode.Cat(
                        CharSetNode.Create(A),          // 0
                        ActionNode.Create(Action0)),    // 1
                    AstNode.Cat(                        //
                        CharSetNode.Create(A),          // 2
                        CharSetNode.Create(B),          // 3
                        CharSetNode.Create(B),          // 4
                        ActionNode.Create(Action1)      // 5
                        ),
                    AstNode.Cat(
                        RepeatNode.ZeroOrMore(CharSetNode.Create(A)), // 6
                        RepeatNode.OneOrMore(CharSetNode.Create(B)),  // 7, 8
                        ActionNode.Create(Action2))                   // 9
                    ));

            CreateDfa();

            DfaShouldTriggerAction(Action0, A);
            DfaShouldTriggerAction(Action1, A, B, B);
            DfaShouldTriggerAction(Action2, A, B);
            DfaShouldTriggerAction(Action2, A, B, B, B);
        }
Esempio n. 2
0
        public void dfa_provides_correct_serialization_information()
        {
            // Given alphabet
            const int A = 0;
            const int B = 1;

            // Given actions
            const int Action0 = 1001;
            const int Action1 = 1002;
            const int Action2 = 1003;

            GivenRegularExpression(
                AstNode.Or(
                    AstNode.Cat(
                        CharSetNode.Create(A),
                        ActionNode.Create(Action0)),
                    AstNode.Cat(
                        CharSetNode.Create(A),
                        CharSetNode.Create(B),
                        CharSetNode.Create(B),
                        ActionNode.Create(Action1)
                        ),
                    AstNode.Cat(
                        RepeatNode.ZeroOrMore(CharSetNode.Create(A)),
                        RepeatNode.OneOrMore(CharSetNode.Create(B)),
                        ActionNode.Create(Action2))
                    ));

            CreateDfa();
            var output = new StringBuilder();

            serialization.Print(output);
            // DUBUG: Console.WriteLine(output);
        }
Esempio n. 3
0
 public Piece Action(Integer action)
 {
     return(new Piece {
         Node = ActionNode.Create(action.Value)
     });
 }
Esempio n. 4
0
 public SreExpr Action(Num num)
 {
     return(new SreExpr {
         Node = ActionNode.Create(int.Parse(num.Text))
     });
 }