예제 #1
0
파일: NFAConverter.cs 프로젝트: zxs1215/VBF
        public override NFAModel ConvertAlternation(AlternationExpression exp)
        {
            var nfa1 = Convert(exp.Expression1);
            var nfa2 = Convert(exp.Expression2);

            NFAState head = new NFAState();
            NFAState tail = new NFAState();

            //build edges

            head.AddEdge(nfa1.EntryEdge);
            head.AddEdge(nfa2.EntryEdge);

            nfa1.TailState.AddEmptyEdgeTo(tail);
            nfa2.TailState.AddEmptyEdgeTo(tail);

            NFAModel alternationNfa = new NFAModel();

            alternationNfa.AddState(head);
            alternationNfa.AddStates(nfa1.States);
            alternationNfa.AddStates(nfa2.States);
            alternationNfa.AddState(tail);

            //add an empty entry edge
            alternationNfa.EntryEdge = new NFAEdge(head);
            alternationNfa.TailState = tail;

            return(alternationNfa);
        }
예제 #2
0
파일: NFAConverter.cs 프로젝트: zxs1215/VBF
        public override NFAModel ConvertStringLiteral(StringLiteralExpression exp)
        {
            NFAModel literalNfa = new NFAModel();

            NFAState lastState = null;

            foreach (var symbol in exp.Literal)
            {
                var symbolState = new NFAState();
                int cclass      = CompactCharSetManager.GetCompactClass(symbol);
                var symbolEdge  = new NFAEdge(cclass, symbolState);

                if (lastState != null)
                {
                    lastState.AddEdge(symbolEdge);
                }
                else
                {
                    literalNfa.EntryEdge = symbolEdge;
                }

                lastState = symbolState;

                literalNfa.AddState(symbolState);
            }

            literalNfa.TailState = lastState;

            return(literalNfa);
        }
예제 #3
0
파일: NFAConverter.cs 프로젝트: zxs1215/VBF
        public override NFAModel ConvertAlternationCharSet(AlternationCharSetExpression exp)
        {
            NFAState head = new NFAState();
            NFAState tail = new NFAState();
            //build edges

            NFAModel charSetNfa = new NFAModel();

            charSetNfa.AddState(head);

            HashSet <int> classesSet = new HashSet <int>();

            foreach (var symbol in exp.CharSet)
            {
                int cclass = CompactCharSetManager.GetCompactClass(symbol);
                if (classesSet.Add(cclass))
                {
                    var symbolEdge = new NFAEdge(cclass, tail);
                    head.AddEdge(symbolEdge);
                }
            }

            charSetNfa.AddState(tail);

            //add an empty entry edge
            charSetNfa.EntryEdge = new NFAEdge(head);
            charSetNfa.TailState = tail;

            return(charSetNfa);
        }
예제 #4
0
파일: NFAConverter.cs 프로젝트: zxs1215/VBF
        public override NFAModel ConvertKleeneStar(KleeneStarExpression exp)
        {
            var innerNFA = Convert(exp.InnerExpression);

            var newTail = new NFAState();
            var entry   = new NFAEdge(newTail);

            innerNFA.TailState.AddEmptyEdgeTo(newTail);
            newTail.AddEdge(innerNFA.EntryEdge);

            var kleenStarNFA = new NFAModel();

            kleenStarNFA.AddStates(innerNFA.States);
            kleenStarNFA.AddState(newTail);
            kleenStarNFA.EntryEdge = entry;
            kleenStarNFA.TailState = newTail;

            return(kleenStarNFA);
        }
예제 #5
0
파일: DFAModel.cs 프로젝트: wywsq/VBF
        private void ConvertLexcionToNFA()
        {
            //Compact transition char set
            CompactCharSetManager = m_lexicon.CreateCompactCharSetManager();
            NFAConverter converter = new NFAConverter(CompactCharSetManager);

            NFAState entryState = new NFAState();
            NFAModel lexerNFA   = new NFAModel();

            lexerNFA.AddState(entryState);
            foreach (var token in m_lexicon.GetTokens())
            {
                NFAModel tokenNFA = token.CreateFiniteAutomatonModel(converter);

                entryState.AddEdge(tokenNFA.EntryEdge);
                lexerNFA.AddStates(tokenNFA.States);
            }

            lexerNFA.EntryEdge = new NFAEdge(entryState);

            m_nfa = lexerNFA;
        }
예제 #6
0
파일: DFAModel.cs 프로젝트: jiangzhen/VBF
        private void ConvertLexcionToNFA()
        {
            //Compact transition char set
            CompactCharSetManager = m_lexicon.CreateCompactCharSetManager();
            NFAConverter converter = new NFAConverter(CompactCharSetManager);

            NFAState entryState = new NFAState();
            NFAModel lexerNFA = new NFAModel();

            lexerNFA.AddState(entryState);
            foreach (var token in m_lexicon.GetTokens())
            {
                NFAModel tokenNFA = token.CreateFiniteAutomatonModel(converter);

                entryState.AddEdge(tokenNFA.EntryEdge);
                lexerNFA.AddStates(tokenNFA.States);
            }

            lexerNFA.EntryEdge = new NFAEdge(entryState);

            m_nfa = lexerNFA;
        }