diff Implab/Formats/Grammar.cs @ 178:d5c5db0335ee ref20160224

working on JSON parser
author cin
date Wed, 23 Mar 2016 19:51:45 +0300
parents a0ff6a0e9c44
children 6fa235c5a760
line wrap: on
line diff
--- a/Implab/Formats/Grammar.cs	Wed Mar 23 01:42:00 2016 +0300
+++ b/Implab/Formats/Grammar.cs	Wed Mar 23 19:51:45 2016 +0300
@@ -9,14 +9,14 @@
     /// <summary>
     /// Базовый абстрактный класс. Грамматика, позволяет формулировать выражения над алфавитом типа <c>char</c>.
     /// </summary>
-    public abstract class Grammar<TSymbol, TTag> {
+    public abstract class Grammar<TSymbol> {
         
         protected abstract IAlphabetBuilder<TSymbol> AlphabetBuilder {
             get;
         }
 
-        protected SymbolToken<TTag> UnclassifiedToken() {
-            return new SymbolToken<TTag>(DFAConst.UNCLASSIFIED_INPUT);
+        protected SymbolToken UnclassifiedToken() {
+            return new SymbolToken(AutomatonConst.UNCLASSIFIED_INPUT);
         }
 
         protected void DefineAlphabet(IEnumerable<TSymbol> alphabet) {
@@ -26,23 +26,23 @@
                 AlphabetBuilder.DefineSymbol(ch);
         }
 
-        protected Token<TTag> SymbolToken(TSymbol symbol) {
-            return Token<TTag>.New(TranslateOrAdd(symbol));
+        protected Token SymbolToken(TSymbol symbol) {
+            return Token.New(TranslateOrAdd(symbol));
         }
 
-        protected Token<TTag> SymbolToken(IEnumerable<TSymbol> symbols) {
+        protected Token SymbolToken(IEnumerable<TSymbol> symbols) {
             Safe.ArgumentNotNull(symbols, "symbols");
 
-            return Token<TTag>.New(TranslateOrAdd(symbols).ToArray());
+            return Token.New(TranslateOrAdd(symbols).ToArray());
         }
 
-        protected Token<TTag> SymbolSetToken(params TSymbol[] set) {
+        protected Token SymbolSetToken(params TSymbol[] set) {
             return SymbolToken(set);
         }
 
         int TranslateOrAdd(TSymbol ch) {
             var t = AlphabetBuilder.Translate(ch);
-            if (t == DFAConst.UNCLASSIFIED_INPUT)
+            if (t == AutomatonConst.UNCLASSIFIED_INPUT)
                 t = AlphabetBuilder.DefineSymbol(ch);
             return t;
         }
@@ -53,7 +53,7 @@
 
         int TranslateOrDie(TSymbol ch) {
             var t = AlphabetBuilder.Translate(ch);
-            if (t == DFAConst.UNCLASSIFIED_INPUT)
+            if (t == AutomatonConst.UNCLASSIFIED_INPUT)
                     throw new ApplicationException(String.Format("Symbol '{0}' is UNCLASSIFIED", ch));
             return t;
         }
@@ -62,22 +62,21 @@
             return symbols.Distinct().Select(TranslateOrDie);
         }
 
-        protected Token<TTag> SymbolTokenExcept(IEnumerable<TSymbol> symbols) {
+        protected Token SymbolTokenExcept(IEnumerable<TSymbol> symbols) {
             Safe.ArgumentNotNull(symbols, "symbols");
 
-            return Token<TTag>.New( Enumerable.Range(0, AlphabetBuilder.Count).Except(TranslateOrDie(symbols)).ToArray() );
+            return Token.New( Enumerable.Range(0, AlphabetBuilder.Count).Except(TranslateOrDie(symbols)).ToArray() );
         }
 
         protected abstract IndexedAlphabetBase<TSymbol> CreateAlphabet();
 
-        protected ScannerContext<TTag> BuildScannerContext(Token<TTag> regexp) {
+        protected ScannerContext<TTag> BuildScannerContext<TTag>(Token regexp) {
             
             var dfa = new RegularDFA<TSymbol, TTag>(AlphabetBuilder);
 
-            var visitor = new RegularExpressionVisitor<TTag>();
-            regexp.Accept( visitor );
-
-            visitor.BuildDFA(dfa);
+            var visitor = new RegularExpressionVisitor<TTag>(dfa);
+            regexp.Accept(visitor);
+            visitor.BuildDFA();
 
             if (dfa.IsFinalState(dfa.InitialState))
                 throw new ApplicationException("The specified language contains empty token");