public override NFAModel ConvertAlternationCharSet(AlternationCharSetExpression exp) { NFAState head = new NFAState(); NFAState tail = new NFAState(); //build edges NFAModel charSetNfa = new NFAModel(); charSetNfa.AddState(head); HashSet <int> classesSet = new HashSet <int>(); foreach (var symbol in exp.CharSet) { int cclass = CompactCharSetManager.GetCompactClass(symbol); if (classesSet.Add(cclass)) { var symbolEdge = new NFAEdge(cclass, tail); head.AddEdge(symbolEdge); } } charSetNfa.AddState(tail); //add an empty entry edge charSetNfa.EntryEdge = new NFAEdge(head); charSetNfa.TailState = tail; return(charSetNfa); }
public override NFAModel ConvertStringLiteral(StringLiteralExpression exp) { NFAModel literalNfa = new NFAModel(); NFAState lastState = null; foreach (var symbol in exp.Literal) { var symbolState = new NFAState(); int cclass = CompactCharSetManager.GetCompactClass(symbol); var symbolEdge = new NFAEdge(cclass, symbolState); if (lastState != null) { lastState.AddEdge(symbolEdge); } else { literalNfa.EntryEdge = symbolEdge; } lastState = symbolState; literalNfa.AddState(symbolState); } literalNfa.TailState = lastState; return(literalNfa); }
public override NFAModel ConvertEmpty(EmptyExpression exp) { NFAState tail = new NFAState(); NFAEdge entryEdge = new NFAEdge(tail); NFAModel emptyNfa = new NFAModel(); emptyNfa.AddState(tail); emptyNfa.TailState = tail; emptyNfa.EntryEdge = entryEdge; return(emptyNfa); }
public override NFAModel ConvertSymbol(SymbolExpression exp) { NFAState tail = new NFAState(); int cclass = CompactCharSetManager.GetCompactClass(exp.Symbol); NFAEdge entryEdge = new NFAEdge(cclass, tail); NFAModel symbolNfa = new NFAModel(); symbolNfa.AddState(tail); symbolNfa.TailState = tail; symbolNfa.EntryEdge = entryEdge; return(symbolNfa); }
public override NFAModel ConvertKleeneStar(KleeneStarExpression exp) { var innerNFA = Convert(exp.InnerExpression); var newTail = new NFAState(); var entry = new NFAEdge(newTail); innerNFA.TailState.AddEmptyEdgeTo(newTail); newTail.AddEdge(innerNFA.EntryEdge); var kleenStarNFA = new NFAModel(); kleenStarNFA.AddStates(innerNFA.States); kleenStarNFA.AddState(newTail); kleenStarNFA.EntryEdge = entry; kleenStarNFA.TailState = newTail; return(kleenStarNFA); }
internal void AddEdge(NFAEdge edge) { CodeContract.RequiresArgumentNotNull(edge, "edge"); m_outEdges.Add(edge); }