c++ program with code

profilethetig
hw3-2.docx

I already did the logic for the given CFG, so you do not have to worry about it. I just need the program to run.

#include<iostream>

#include<ctype.h>

#include<stdlib.h>

using namespace std;

int ststes[4][3]={0,1,2,

2,1,3

0,3,3

1,3,2};

int state=0; i=0;

while (i<w.length())

{

if (w[i]== 'a') cal=0;

if (w[i]== 'b') cal=1;

else cal=2;

switch (w[i])

{ case 'a' : state = states [state][cal];break;

case 'b' : state = states [state][cal];break;

case 'c' : state = states [state][cal];break;

cout<<"is accepted \n";

else

cout<<" reject \n";

return 0;

}}