Exemplo n.º 1
0
 // Creates an NFA that matches a sequence of the two provided NFAs.
 public static NFA Sequence(NFA first, NFA second)
 {
     first.exit.isFinalState  = false;
     second.exit.isFinalState = true;
     first.exit.AddAnonymousEdge(second.entry);
     return(new NFA(first.entry, second.exit, RegExType.Sequence));
 }
Exemplo n.º 2
0
        public static NFA CharacterClass(char start, char end, bool included = true)
        {
            var charMap = new CharacterClass(start, end);

            if (!included)
            {
                charMap = Ast.CharacterClass.Negate(charMap);
            }

            return(NFA.CharacterClass(charMap));
        }
Exemplo n.º 3
0
        // Creates an NFA that matches either provided NFA.
        public static NFA Alternation(NFA a, NFA b)
        {
            a.exit.isFinalState = false;
            b.exit.isFinalState = false;
            var entry = new NFAState(RegExType.Choice);
            var exit  = new NFAState(RegExType.Choice);

            exit.isFinalState = true;
            entry.AddAnonymousEdge(a.entry);
            entry.AddAnonymousEdge(b.entry);
            a.exit.AddAnonymousEdge(exit);
            b.exit.AddAnonymousEdge(exit);
            return(new NFA(entry, exit, RegExType.Choice));
        }
Exemplo n.º 4
0
        public static NFA Sequence(params object[] rexps)
        {
            NFA exp = empty();

            for (int i = 0; i < rexps.Length; i++)
            {
                var r = CastToNFA(rexps[i]);
                if (r is NFA && exp is NFA)
                {
                    exp = Sequence((NFA)exp, (NFA)r);
                }
                else
                {
                    exp = Sequence(exp, r);
                }
            }
            return(exp);
        }
Exemplo n.º 5
0
 // Creates an NFA which matches one zero or one times of the given NFA.
 public static NFA ZeroOrOne(NFA nfa)
 {
     nfa.entry.AddAnonymousEdge(nfa.exit);
     return(nfa);
 }
Exemplo n.º 6
0
 // Creates an NFA which matches at least one or more repetitions of the given NFA.
 public static NFA OneOrMany(NFA nfa)
 {
     nfa.exit.AddAnonymousEdge(nfa.entry);
     return(nfa);
 }