Advertisement
Guest User

Untitled

a guest
Oct 27th, 2016
51
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.14 KB | None | 0 0
  1. public void Build(DfaBuildContext c)
  2. {
  3. var state = Closure.DfaState;
  4.  
  5. //Process the transitions by unique symbol / terminal
  6. var transitions = Transitions.GetTransitionsByTerminalIntervals();
  7.  
  8. //We need to split the terminal transitions into unique non overlapping intervals
  9. var nonOverlappingIntervalTransitions = new NonOverlappingIntervalSet<NfaTransition>();
  10. foreach (var transitionsByTerminalIntervals in transitions)
  11. {
  12. var interval = transitionsByTerminalIntervals.Interval;
  13. var nfaTransitions = transitionsByTerminalIntervals.Transitions;
  14.  
  15. //Add the interval, which will split into non overlapping intervals, but keep the association of the nfa transitions for each of the splits
  16. nonOverlappingIntervalTransitions.AddInterval(interval, nfaTransitions);
  17. }
  18.  
  19. //Now lets iterate each of the non overlapping intervall transitions
  20. foreach (var transitionsByTerminalIntervals in nonOverlappingIntervalTransitions)
  21. {
  22. var terminalTransitions = transitionsByTerminalIntervals.AssociatedItems;
  23.  
  24. //Get the closure for the transitions - basically expand the transitions one step ahead, following until a "terminal transition" is reached...
  25. //We are basically expanding the "nfa path tree"
  26. var closure = c.Closure(terminalTransitions);
  27.  
  28. //Only process each "location" once
  29. var nextClosure = c.EnqueueOrGetExisting(closure);
  30. if (nextClosure != closure)
  31. {
  32. //We have received an existing... dispose the other...
  33. closure.Dispose();
  34. }
  35.  
  36. var terminals = terminalTransitions.Select(t => (t as TerminalNfaTransition).Terminal);
  37. var interval = transitionsByTerminalIntervals.Interval;
  38.  
  39. //Add transition to the next DFA state
  40. state.AddTransition(new DfaTransition(interval, terminals, nextClosure.DfaState));
  41. }
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement