comparison Implab/Automaton/RegularExpressions/Grammar.cs @ 164:ec35731ae299 ref20160224

Almost complete DFA refactoring
author cin
date Thu, 25 Feb 2016 02:11:13 +0300
parents 419aa51b04fd
children e227e78d72e4
comparison
equal deleted inserted replaced
163:419aa51b04fd 164:ec35731ae299
69 } 69 }
70 70
71 protected CDFADefinition BuildDFA(Token<TTag> lang) { 71 protected CDFADefinition BuildDFA(Token<TTag> lang) {
72 Safe.ArgumentNotNull(lang, "lang"); 72 Safe.ArgumentNotNull(lang, "lang");
73 73
74 var dfa = new CDFADefinition(Alphabet); 74 var dfa = new RegularDFADefinition<TSymbol, TTag>(Alphabet, 0);
75 75
76 var table = new DFATransitionTable<TTag>();
77
76 var builder = new RegularDFABuilder<TTag>(); 78 var builder = new RegularDFABuilder<TTag>();
77 79
78 lang.Accept( builder ); 80 lang.Accept( builder );
79 81
80 builder.BuildDFA(dfa); 82 var initialState = builder.BuildDFA(table);
81 if (dfa.InitialStateIsFinal) 83 if (table.IsFinalState(initialState))
82 throw new ApplicationException("The specified language contains empty token"); 84 throw new ApplicationException("The specified language contains empty token");
83 85
84 return dfa.Optimize(); 86 return dfa.Optimize();
85 } 87 }
86 88