SHARE
TWEET

Untitled

a guest Nov 22nd, 2019 76 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. template<class state>
  2. class ttNode
  3. {
  4. public:
  5.     int status; //-1 == not at end, 0 == reached end; rejecting, 1 == reached end; accepting
  6.     state currentState; //keep track of the current state
  7.     vector<pair<state, ttNode>> moreTraceTrees; //a dynamically allocated list of states and a node to the next part of the tree
  8.  
  9.     ttNode(int status, state currentState, vector<pair<state, ttNode>> moreTraceTrees)
  10.         : status(status), currentState(currentState), moreTraceTrees(moreTraceTrees) {};
  11. };
  12.  
  13. template<class state>
  14. ttNode<state>* fork(NFA<state>* nfa, state currentState, vector<Character> string, vector<Character>::iterator stringIter)
  15. {
  16.     int status;
  17.     //ttNode<state> tree;
  18.  
  19.     if ((stringIter > string.end()) && (nfa->acceptingState(currentState)))
  20.     {
  21.         status = 1;
  22.         //return tree;
  23.     }
  24.     else if ((stringIter > string.end()) && !(nfa->acceptingState(currentState)))
  25.     {
  26.         status = 0;
  27.         //return tree;
  28.     }
  29.     else
  30.     {
  31.         status = -1;
  32.         vector<state> stateSet = nfa->delta(currentState, *stringIter);
  33.         ttNode<state>* tree = new ttNode<state>(status, currentState, vector<pair<state, ttNode<state>>>{});
  34.  
  35.         for (int i = 0; i < stateSet.size(); i++)
  36.         {
  37.             auto nextBranch = fork(nfa, currentState, string, stringIter++);
  38.             auto temp = make_pair(stateSet.at(i), nextBranch);
  39.             tree->moreTraceTrees.emplace_back(temp);
  40.             stringIter--;
  41.         }
  42.         return tree;
  43.     }
  44.     //return tree;
  45.    
  46.     /*
  47.     Use the delta function to get the next state(s) for given chars
  48.     for each element of the set returned by delta: Add the char that too you there + the next ttNode to the moreTraceTrees vector
  49.  
  50.     The next ttNode is a just a call to fork with the next element from the set of states + the character
  51.  
  52.     When each element of the set of states is used then go onto the next character and repeat -> this is to get the next layer of the tree
  53.     */
  54. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top