示例#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);
        }
示例#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);
        }
示例#3
0
        public void DFA_matches_input_correctly()
        {
            // Given alphabet
            const int A = 0;
            const int B = 1;

            GivenRegularExpression(
                new CatNode(new List <AstNode> {
                RepeatNode.ZeroOrMore(
                    new OrNode(new List <AstNode> {
                    CharSetNode.Create(A),
                    CharSetNode.Create(B)
                })),
                CharSetNode.Create(A),
                CharSetNode.Create(B),
                CharSetNode.Create(B)
            })
                );

            CreateDfa();

            DfaShouldMatch(A, B, B);
            DfaShouldMatch(A, A, A, A, B, B);
            DfaShouldMatch(B, B, B, A, B, B);
            DfaShouldMatch(A, B, B, A, B, B);

            DfaShouldNotMatch();
            DfaShouldNotMatch(A, B);
            DfaShouldNotMatch(A, B, B, A);
            DfaShouldNotMatch(A, B, B, B);

            DfaShouldMatchBeginning(A, B, B);
            DfaShouldMatchBeginning(A, A, A, A, B, B);
            DfaShouldMatchBeginning(B, B, B, A, B, B);
            DfaShouldMatchBeginning(A, B, B, A, B, B);
            DfaShouldMatchBeginning(A, B, B, A);
            DfaShouldMatchBeginning(A, B, B, B);

            DfaShouldNotMatchBeginning();
            DfaShouldNotMatchBeginning(A, B, A, B);
            DfaShouldNotMatchBeginning(A, A, A, A);
            DfaShouldNotMatchBeginning(B, B, B, B);
        }
示例#4
0
        public void input_equivalence_classes_are_used()
        {
            // Given alphabet
            int A = 0;
            int B = 0x10FFFF; // Unicode max

            GivenRegularExpression(
                new CatNode(new List <AstNode> {
                RepeatNode.ZeroOrMore(CharSetNode.CreateRange(A, B)),
                CharSetNode.Create(A),
                CharSetNode.Create(B),
                CharSetNode.Create(B)
            })
                );

            CreateDfa();

            DfaShouldMatch(A, B, B);
            DfaShouldMatch(A, A, A, A, B, B);
            DfaShouldMatch(B, B, B, A, B, B);
            DfaShouldMatch(A, B, B, A, B, B);

            DfaShouldNotMatch();
            DfaShouldNotMatch(A, B);
            DfaShouldNotMatch(A, B, B, A);
            DfaShouldNotMatch(A, B, B, B);

            DfaShouldMatchBeginning(A, B, B);
            DfaShouldMatchBeginning(A, A, A, A, B, B);
            DfaShouldMatchBeginning(B, B, B, A, B, B);
            DfaShouldMatchBeginning(A, B, B, A, B, B);
            DfaShouldMatchBeginning(A, B, B, A);
            DfaShouldMatchBeginning(A, B, B, B);

            DfaShouldNotMatchBeginning();
            DfaShouldNotMatchBeginning(A, B, A, B);
            DfaShouldNotMatchBeginning(A, A, A, A);
            DfaShouldNotMatchBeginning(B, B, B, B);
        }
示例#5
0
 public Piece ZeroOrMore(Piece atom)
 {
     return(new Piece {
         Node = RepeatNode.ZeroOrMore(atom.Node)
     });
 }
示例#6
0
 public SreExpr ZeroOrMore(OpenSreExpr items)
 {
     return(new SreExpr {
         Node = RepeatNode.ZeroOrMore(items.Node)
     });
 }