Mercurial > pub > ImplabNet
diff Implab/Automaton/RegularExpressions/RegularDFABuilder.cs @ 165:e227e78d72e4 ref20160224
DFA refactoring
author | cin |
---|---|
date | Mon, 29 Feb 2016 02:02:17 +0300 |
parents | ec35731ae299 |
children | 181119ef3b39 |
line wrap: on
line diff
--- a/Implab/Automaton/RegularExpressions/RegularDFABuilder.cs Thu Feb 25 02:11:13 2016 +0300 +++ b/Implab/Automaton/RegularExpressions/RegularDFABuilder.cs Mon Feb 29 02:02:17 2016 +0300 @@ -11,7 +11,7 @@ /// <see cref="BuildDFA(IDFADefinition)"/> для построения автомата. /// </summary> public class RegularDFABuilder<TTag> : IVisitor<TTag> { - int m_idx = 0; + int m_idx; Token<TTag> m_root; HashSet<int> m_firstpos; HashSet<int> m_lastpos; @@ -26,18 +26,18 @@ public HashSet<int> Followpos(int pos) { HashSet<int> set; - if (m_followpos.TryGetValue(pos, out set)) - return set; - return m_followpos[pos] = new HashSet<int>(); + return m_followpos.TryGetValue(pos, out set) ? set : m_followpos[pos] = new HashSet<int>(); } bool Nullable(object n) { if (n is EmptyToken<TTag> || n is StarToken<TTag>) return true; - if (n is AltToken<TTag>) - return Nullable(((AltToken<TTag>)n).Left) || Nullable(((AltToken<TTag>)n).Right); - if (n is CatToken<TTag>) - return Nullable(((CatToken<TTag>)n).Left) && Nullable(((CatToken<TTag>)n).Right); + var altToken = n as AltToken<TTag>; + if (altToken != null) + return Nullable(altToken.Left) || Nullable(altToken.Right); + var catToken = n as CatToken<TTag>; + if (catToken != null) + return Nullable(catToken.Left) && Nullable(catToken.Right); return false; } @@ -122,7 +122,7 @@ m_ends.Add(m_idx, token.Tag); } - public void BuildDFA(IDFATransitionTableBuilder<TTag> dfa) { + public void BuildDFA(IDFATableBuilder<TTag> dfa) { Safe.ArgumentNotNull(dfa,"dfa"); var states = new MapAlphabet<HashSet<int>>(new CustomEqualityComparer<HashSet<int>>(