Question: Help complete code! this is the pda.h file #ifndef PDA _ H 2 #define PDA _ H 3 4 #include 5 #include 6 #include 7

Help complete code! this is the pda.h file #ifndef PDA_H 2 #define PDA_H 34 #include 5 #include 6 #include 78 using namespace std; 910 class TableEntry 11{12 public: 13 TableEntry(char stackSymbol, char inputSymbol, string pushPop, uint state)14{15 setStackSymbol(stackSymbol); 16 setInputSymbol(inputSymbol); 17 setPushPop(pushPop); 18 setNextState(state); 19}20 void setStackSymbol(char ch)21{22 stackSymbol = ch; 23} Figure 1./usr/local/4301/include/pda.h (Part 1 of 3) CS 4301 Algorithmic Languages and Compilers Page 1 Lab 6 Due Date: See Blackboard 24 void setInputSymbol(char ch)25{26 inputSymbol = ch; 27}28 void setPushPop(string s)29{30 pushPop = s; 31}32 void setNextState(uint state)33{34 nextState = state; 35}36 char getStackSymbol() const 37{38 return stackSymbol; 39}40 char getInputSymbol() const 41{42 return inputSymbol; 43}44 string getPushPop() const 45{46 return pushPop; 47}48 uint getNextState() const 49{50 return nextState; 51}52 private: 53 char stackSymbol; 54 char inputSymbol; 55 string pushPop; 56 uint nextState; 57}; 5859 class PDA 60{61 public: 62// default constructor -- initializes private data members name, 63// labNumber, and description 64 PDA(); 65// Member function InitializeMachine() initializes the private data 66// member machine, a multimap where the key is the current state and 67// the value is a class object containing the stack symbol, input 68// symbol, push_pop, and next state 69 void initializeMachine(); Figure 1./usr/local/4301/include/pda.h (Part 2 of 3) Page 2 CS 4301 Algorithmic Languages and Compilers Lab 6 Due Date: See Blackboard 70// Member function OutputID() writes name, class, lab number, and 71// lab description to output stream out 72 void outputID(ostream& out) const; 73// Member function ImplementPDA() returns true if dataLine is 74// recognized by the PDA as valid and false otherwise 75 bool implementPDA(string dataLine) const; 76 private: 77 string name; 78 int labNumber; 79 string description; 80 multimap machine; 81}; 8283 #endif and here is the main.C file 1 #include 2 #include 34 using namespace std; 56 int main()7{8 PDA myPDA; 9 string dataLine; 1011 myPDA.initializeMachine(); 12 myPDA.outputID(cout); 1314 while (getline(cin, dataLine))15{16 cout "Input: " dataLine ""; 17 dataLine +="%"; 18 if (myPDA.implementPDA(dataLine))19 cout "Result: ** accepted **" endl endl; 20 else 21 cout "Result: -- NOT accepted --" endl endl; 22}2324 return 0; 25}26 Figure 2./usr/local/4301/src/lab06main.C (Part 1 of 3) CS 4301 Algorithmic Languages and Compilers Page 3 Lab 6 Due Date: See Blackboard 27 void PDA::outputID(ostream& out) const 28{29 out name endl; 30 out "CS 4301" endl; 31 out "Lab " labNumber endl; 32 out description endl endl; 33}3435 bool PDA::implementPDA(string dataLine) const 36{37 int currentState =1; 38 string::iterator dataItr = dataLine.begin(); 39 multimap::const_iterator pdaItr; 40 stack pdaStack; 41 bool done; 4243 pdaStack.push(@); 4445 while (currentState >0)46{47// Use find to return an iterator to the first entry with a key of 48// currentState 49 pdaItr = machine.find(currentState); 50 if (pdaItr != machine.end())// found a key of currentState 51{52 done = false; 53 while (!done && pdaItr != machine.upper_bound(currentState))54 if (pdaItr->second.getInputSymbol()==* && 55(pdaItr->second.getStackSymbol()==*||56(!pdaStack.empty() && 57 pdaItr->second.getStackSymbol()== pdaStack.top())))58 done = true; 59 else if (pdaItr->second.getInputSymbol()==*dataItr && 60(pdaItr->second.getStackSymbol()==*||61(!pdaStack.empty() && 62 pdaItr->second.getStackSymbol()== pdaStack.top())))63 done = true; 64 else 65++pdaItr; 66 Figure 2./usr/local/4301/src/lab06main.C (Part 2 of 3) Page 4 CS 4301 Algorithmic Languages and Compilers Lab 6 Due Date: See Blackboard 67 if (pdaItr != machine.upper_bound(currentState))68{69 if (pdaItr->second.getStackSymbol()==*||70(!pdaStack.empty() && 71 pdaItr->second.getStackSymbol()== pdaStack.top()))72{73 currentState = pdaItr->second.getNextState(); 74 switch (pdaItr->second.getPushPop()[0])75{76 case +: 77 pdaStack.push(pdaItr->second.getPushPop()[1]); 78 break; 79 case -: 80 if (pdaStack.empty())81 currentState =-1; 82 if (pdaItr->second.getPushPop()[1]!= pdaStack.top())83 currentState =-1; 84 pdaStack.pop(); 85}86 if (*dataItr !=% && pdaItr->second.getInputSymbol()!=*)87++dataItr; 88}89 else 90 currentState =-1; 91}92 else 93 currentState =-1; 94}95 else 96 currentState =-1; 97}9899 return currentState ==0 && *dataItr ==% && 100 pdaStack.size()==1 && pdaStack.top()==@; 101}
Help complete code! this is the pda.h file

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!