private void InstantiateFromRegex(RegExpr re) { _startState = NewState(); _finishState.Add(NewState()); foreach (var alt in re.Alternatives) { var altnfa = new NFAGraph(alt); CopyInto(altnfa); var nsl = new NFALink(); var nfl = new NFALink(); nsl.IsEmpty = true; nfl.IsEmpty = true; nsl.Target = altnfa._startState; nfl.Target = _finishState.Single(); _adjList[_startState].Add(nsl); _adjList[altnfa._finishState.Single()].Add(nfl); } }
private void InstantiateFromMatchFactorOp(MatchFactorWithOp mop) { var mf = new NFAGraph(mop.Factor); CopyIntoWithTerminals(mf); switch (mop.Op.Type) { case UnaryOperatorType.None: break; case UnaryOperatorType.Optional: var elink1 = new NFALink(); elink1.IsEmpty = true; elink1.Target = _finishState.Single(); _adjList[_startState].Add(elink1); break; case UnaryOperatorType.OneMany: var elink2 = new NFALink(); elink2.IsEmpty = true; elink2.Target = _startState; _adjList[_finishState.Single()].Add(elink2); break; case UnaryOperatorType.NoneMany: var newend = NewState(); var blink = new NFALink(); var flink = new NFALink(); blink.IsEmpty = true; flink.IsEmpty = true; blink.Target = _startState; flink.Target = newend; _adjList[_finishState.Single()].Add(blink); _adjList[_startState].Add(flink); _finishState = new HashSet<NFAState>{newend}; break; } }
private void InstantiateFromAlternative(Alternative alt) { _startState = NewState(); _finishState.Add(NewState()); var curtail = _startState; foreach (var mf in alt.Factors) { var mfnfa = new NFAGraph(mf); CopyInto(mfnfa); var nl = new NFALink(); nl.IsEmpty = true; nl.Target = mfnfa._startState; _adjList[curtail].Add(nl); curtail = mfnfa._finishState.Single(); } var nel = new NFALink(); nel.IsEmpty = true; nel.Target = _finishState.Single(); _adjList[curtail].Add(nel); }
private void InstantiateFromCharClass(CharacterClass CClass) { _startState = NewState(); _finishState.Add(NewState()); var link = new NFALink(); link.CharClass = CClass; link.Target = _finishState.Single(); _adjList[_startState].Add(link); }
private bool CanFollowLink(NFALink link, char c) { if (link.CharClass == null) return false; return link.CharClass.Elements.Any(el => el.StartC >= c && el.EndC <= c); }