Home > Back-end >  DAF program run results has a problem, a great god help!!!!!!
DAF program run results has a problem, a great god help!!!!!!

Time:10-24

Here is my code
# include & lt; Stdio. H>
# include & lt; The malloc. H>
//////////////////////////////////////////////////
//////////Make a link list////////////////////////
//////////////////////////////////////////////////
Typedef struct Node
{
Char data;
struct Node *next;
} LNode * LinkList;
//////////////////////////////////////////////////
//////////Save the input string in the link list//////////
//////////////////////////////////////////////////
LinkList input ()
{
LinkList L;
LNode * s * r;
Char x;
L=r=NULL;
The scanf (" % c ", & amp; X);
While (x!='#')
{
S=(LNode *) malloc (sizeof (LNode));
S - & gt; data=https://bbs.csdn.net/topics/x;
If (L==NULL)
L=s;
The else
R - & gt; Next=s;
R=s;
The scanf (" % c ", & amp; X);
}
If (r!=NULL)
R - & gt; Next=NULL;
Return the L;
}
/////////////////////////////////////////////////
/////////////////grammer///////////////
/////////////////////////////////////////////////
Char nextview1 (char a1, char a2)
{
Char b='A';
{
If (a1=='A' & amp; & A2=='a')
B='b';
Else if (a1=='A' & amp; & A2=='b')
B='D';
Else if (a1=='B' & amp; & A2=='a')
B='C';
Else if (a1=='B' & amp; & A2=='b')
B='D';
Else if (a1=='C' & amp; & A2=='a')
B='C';
Else if (a1=='C' & amp; & A2=='b')
B='C';
Else if (a1=='D' & amp; & A2=='a')
B='b';
Else if (a1=='D' & amp; & A2=='b')
B='E';
Else if (a1=='E' & amp; & A2=='a')
B='F'.
Else if (a1=='E' & amp; & A2=='b')
B='E';
Else if (a1=='F' & amp; & A2=='a')
B='C';
Else if (a1=='F' & amp; & A2=='b')
B='E';
}
Printf (" stat is: \ n ", b);
Return b;
}

////////////////////////////////////////////////////////
///////////judge the string content the grammer or not///////////////
///////////////////////////////////////////////////////
Int move1 (LinkList song)
{
Char view;
View='A';
LNode * dou1;
Dou1=song;
int i=0;
While (dou1!=NULL)
{
If (the view! )
='E'{
View=nextview1 (view, dou1 - & gt; The data);
Dou1=dou1 - & gt; Next;
}
Else if (the view! )
='F'{
View=nextview1 (view, dou1 - & gt; The data);
Dou1=dou1 - & gt; Next;
}
Else if (view=='E')
{
i=1;
}
Else if (view=='F')
{
i=1;
}
}
Printf (" the Display I: ", I);
return i;
}


Int main ()
{
LinkList song;
Int choose1, choose2;
Int c;
Printf (" input your string (add # after you finish your input) \ n ");
Song=input ();
Printf (" DFA choice \ n ");
Printf (" 1. Grammer1 \ n ");
/* printf (" 2. (a | b) left, BBB left \ n "); */
Printf (" (2) the EXIT \ n ");
While (c!
=3){

The switch (c)
{
Case 1:
{

Choose1=move1 (song);
If (choose1==1)
{
Printf (" string accord grammer \ n ");
}
The else
Printf (" string is not accord grammr \ n ");
break;
}


Case 2:
{
C=4;
break;
}
}
The scanf (" % d ", & amp; C);
}

}
Application requirement is to check the input string is in line with the process of DFA grammar but I every output string output is not conform to really don't know why, and I want to show in nextview1 this function STATE also show not to come out, I checked on the net output statements should be no problem, hope god can help me to solve
  • Related