Advertisement
Guest User

Untitled

a guest
Nov 13th, 2019
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.08 KB | None | 0 0
  1.  
  2.   void traceTree(myString &inputString) // creates tree of all possible traces
  3.   {
  4.     myVector<State> currentStates{this->q0}; // keeps track of current states
  5.     myVector<State> tempVector;
  6.     myVector<State> newStates;
  7.     myVector<State> epsilonStates;
  8.     myString *temp = &inputString;
  9.  
  10.     if (temp->isEmpty()) // inputString is the emptyString
  11.     {
  12.       tempVector = epsilonTrans(this->q0); // check for epsilon transitions from start state
  13.       currentStates.insert(currentStates.begin(), tempVector.begin(), tempVector.end());
  14.       std::cout << std::endl;
  15.       std::cout << this->q0 << std::endl;
  16.       for (auto x : currentStates)
  17.         std::cout << x << " ";
  18.     }
  19.  
  20.     std::cout << std::endl;
  21.     // step through NFA with the input string
  22.     while (temp->isEmpty() != true)
  23.     {
  24.       newStates.clear(); // prepare to get new set of states from transFunc
  25.       epsilonStates.clear();
  26.  
  27.       for (State x : currentStates)
  28.       {
  29.         std::cout << x << " ";
  30.         tempVector = transFunc(x, temp->charObject()); // generate new sets of states from input char w/ each current state
  31.         newStates.insert(newStates.end(), tempVector.begin(), tempVector.end());
  32.       }
  33.       std::cout << std::endl; // epsilon transitions from current states will be on next level of tree
  34.  
  35.       for (State x : currentStates)
  36.       {
  37.         tempVector = epsilonTrans(x); // check whether there are epsilon transitions from current states
  38.         epsilonStates.insert(epsilonStates.end(), tempVector.begin(), tempVector.end());
  39.       }
  40.       if (epsilonStates.size() > 0)
  41.       {
  42.         for (State x : epsilonStates) // print all epsilon transitions
  43.           std::cout << x << " ";
  44.         std::cout << std::endl;
  45.       }
  46.  
  47.       currentStates = newStates; // update current states for next iteration through
  48.       currentStates.insert(currentStates.end(), epsilonStates.begin(), epsilonStates.end());
  49.       temp = temp->next(); // move to next character in the string
  50.     }
  51.     for (State x : currentStates)
  52.       std::cout << x << " ";
  53.     std::cout << std::endl;
  54.   }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement