Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- template<class state>
- class ttNode
- {
- public:
- int status; //-1 == not at end, 0 == reached end; rejecting, 1 == reached end; accepting
- state currentState; //keep track of the current state
- vector<pair<state, ttNode>> moreTraceTrees; //a dynamically allocated list of states and a node to the next part of the tree
- ttNode(int status, state currentState, vector<pair<state, ttNode>> moreTraceTrees)
- : status(status), currentState(currentState), moreTraceTrees(moreTraceTrees) {};
- };
- template<class state>
- ttNode<state>* fork(NFA<state>* nfa, state currentState, vector<Character> string, vector<Character>::iterator stringIter)
- {
- int status;
- //ttNode<state> tree;
- if ((stringIter > string.end()) && (nfa->acceptingState(currentState)))
- {
- status = 1;
- //return tree;
- }
- else if ((stringIter > string.end()) && !(nfa->acceptingState(currentState)))
- {
- status = 0;
- //return tree;
- }
- else
- {
- status = -1;
- vector<state> stateSet = nfa->delta(currentState, *stringIter);
- ttNode<state>* tree = new ttNode<state>(status, currentState, vector<pair<state, ttNode<state>>>{});
- for (int i = 0; i < stateSet.size(); i++)
- {
- auto nextBranch = fork(nfa, currentState, string, stringIter++);
- auto temp = make_pair(stateSet.at(i), nextBranch);
- tree->moreTraceTrees.emplace_back(temp);
- stringIter--;
- }
- return tree;
- }
- //return tree;
- /*
- Use the delta function to get the next state(s) for given chars
- for each element of the set returned by delta: Add the char that too you there + the next ttNode to the moreTraceTrees vector
- The next ttNode is a just a call to fork with the next element from the set of states + the character
- 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
- */
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement