Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void traceTree(myString &inputString) // creates tree of all possible traces
- {
- myVector<State> currentStates{this->q0}; // keeps track of current states
- myVector<State> tempVector;
- myVector<State> newStates;
- myVector<State> epsilonStates;
- myString *temp = &inputString;
- if (temp->isEmpty()) // inputString is the emptyString
- {
- tempVector = epsilonTrans(this->q0); // check for epsilon transitions from start state
- currentStates.insert(currentStates.begin(), tempVector.begin(), tempVector.end());
- std::cout << std::endl;
- std::cout << this->q0 << std::endl;
- for (auto x : currentStates)
- std::cout << x << " ";
- }
- std::cout << std::endl;
- // step through NFA with the input string
- while (temp->isEmpty() != true)
- {
- newStates.clear(); // prepare to get new set of states from transFunc
- epsilonStates.clear();
- for (State x : currentStates)
- {
- std::cout << x << " ";
- tempVector = transFunc(x, temp->charObject()); // generate new sets of states from input char w/ each current state
- newStates.insert(newStates.end(), tempVector.begin(), tempVector.end());
- }
- std::cout << std::endl; // epsilon transitions from current states will be on next level of tree
- for (State x : currentStates)
- {
- tempVector = epsilonTrans(x); // check whether there are epsilon transitions from current states
- epsilonStates.insert(epsilonStates.end(), tempVector.begin(), tempVector.end());
- }
- if (epsilonStates.size() > 0)
- {
- for (State x : epsilonStates) // print all epsilon transitions
- std::cout << x << " ";
- std::cout << std::endl;
- }
- currentStates = newStates; // update current states for next iteration through
- currentStates.insert(currentStates.end(), epsilonStates.begin(), epsilonStates.end());
- temp = temp->next(); // move to next character in the string
- }
- for (State x : currentStates)
- std::cout << x << " ";
- std::cout << std::endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement