Mercurial > pub > ImplabNet
diff Implab/Automaton/RegularExpressions/Grammar.cs @ 172:92d5278d1b10 ref20160224
Working on text scanner
author | cin |
---|---|
date | Mon, 14 Mar 2016 01:19:38 +0300 |
parents | e227e78d72e4 |
children | 0c3c69fe225b |
line wrap: on
line diff
--- a/Implab/Automaton/RegularExpressions/Grammar.cs Thu Mar 10 01:19:33 2016 +0300 +++ b/Implab/Automaton/RegularExpressions/Grammar.cs Mon Mar 14 01:19:38 2016 +0300 @@ -66,23 +66,21 @@ return Token<TTag>.New( Enumerable.Range(0, AlphabetBuilder.Count).Except(TranslateOrDie(symbols)).ToArray() ); } - protected void BuildDFA(Token<TTag> lang, IDFATableBuilder<TTag> dfaTable, IAlphabetBuilder<TSymbol> dfaAlphabet) { - Safe.ArgumentNotNull(lang, "lang"); - Safe.ArgumentNotNull(dfaAlphabet, "dfaAlphabet"); - - var dfa = new RegularDFADefinition<TSymbol, TTag>(AlphabetBuilder); + protected abstract IAlphabetBuilder<TSymbol> CreateAlphabet(); - var builder = new RegularDFABuilder<TTag>(); + protected RegularDFA<TSymbol, TTag> BuildDFA(Token<TTag> regexp) { + + var dfa = new RegularDFA<TSymbol, TTag>(AlphabetBuilder); - lang.Accept( builder ); + var visitor = new RegularExpressionVisitor<TTag>(); + regexp.Accept( visitor ); - builder.BuildDFA(dfa); + visitor.BuildDFA(dfa); if (dfa.IsFinalState(dfa.InitialState)) throw new ApplicationException("The specified language contains empty token"); - dfa.Optimize(dfaTable, dfaAlphabet); - + return dfa.Optimize(CreateAlphabet()); } }