diff Implab/Automaton/RegularExpressions/Grammar.cs @ 176:0c3c69fe225b ref20160224

rewritten the text scanner
author cin
date Tue, 22 Mar 2016 18:58:40 +0300
parents 92d5278d1b10
children
line wrap: on
line diff
--- a/Implab/Automaton/RegularExpressions/Grammar.cs	Mon Mar 21 18:41:45 2016 +0300
+++ b/Implab/Automaton/RegularExpressions/Grammar.cs	Tue Mar 22 18:58:40 2016 +0300
@@ -66,9 +66,9 @@
             return Token<TTag>.New( Enumerable.Range(0, AlphabetBuilder.Count).Except(TranslateOrDie(symbols)).ToArray() );
         }
 
-        protected abstract IAlphabetBuilder<TSymbol> CreateAlphabet();
+        protected abstract IndexedAlphabetBase<TSymbol> CreateAlphabet();
 
-        protected RegularDFA<TSymbol, TTag> BuildDFA(Token<TTag> regexp) {
+        protected ScannerContext<TTag> BuildScannerContext(Token<TTag> regexp) {
             
             var dfa = new RegularDFA<TSymbol, TTag>(AlphabetBuilder);
 
@@ -80,7 +80,16 @@
             if (dfa.IsFinalState(dfa.InitialState))
                 throw new ApplicationException("The specified language contains empty token");
 
-            return dfa.Optimize(CreateAlphabet());
+            var ab = CreateAlphabet();
+            var optimal = dfa.Optimize(ab);
+
+            return new ScannerContext<TTag>(
+                optimal.CreateTransitionTable(),
+                optimal.CreateFinalStateTable(),
+                optimal.CreateTagTable(),
+                optimal.InitialState,
+                ab.GetTranslationMap()
+            );
         }
 
     }