Question: // ** Complete this program in c++ look for ** // info on each DFA struct info { string name; // token name int startstate;
// ** Complete this program in c++ look for **
// info on each DFA struct info { string name; // token name int startstate; int finalstate; };
info DFA[4]; // store up to 4 dfas' start and final int TRS[10][4]; // store trs's - states 0-9 and chars a b c d
// ----- utility functions -----------------------
void displayTables() { // ** display DFA nicely labeled //** display TRS nicely labeled }
void readTables() {
ifstream fin ("trs.txt", ios::in); ifstream fin2 ("dfa.txt", ios::in); // ** read in the files into TRS and DFA }
bool accept(info dfa, string word) { // ** does the dfa accept the word? }
int main() { cout << "This is a table driven scanner. Needs trs.txt and dfa.txt." << endl; cout << "States are 0 to 9 and chars are a to d" << endl;
readTables(); displayTables(); cout << ".....done reading tables...." << endl;
string word; while(true)
{ cout << "@@Enter a string: " ;
cin >> word; // ** try the DFAs one by one and see // if the word is accepted // ** if so, display the word and the token name // ** if no DFA does, generate a lexical error message. cout << "do control-C to quit" << endl; } }
output should look like this:
This is a table driven scanner. Needs trs.txt and dfa.txt. States are 0 to 9 and chars are a to d a b c d State 0:0 1 State 1: State 2: 2 3 State 3: State 4: State 5: State 6: State 7: State 8: State 9: Token abs: 0 is start and ends in 1 Token cds: 2 is start and ends in 3 .....done reading tables.... @@Enter a string: abs Trying dfa 0-------- state: 0 char: a new state: 0 state: 0 char: b new state: 1 state: 1 char: s new state: -1 Trying dfa 1-------- state: 2 char: a new state: -1 Lexical error! do control-C to quit @@Enter a string:
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
