這里是我的代碼
#include <stdio.h>
#include <malloc.h>
//////////////////////////////////////////////////
//////////Make a link list////////////////////////
//////////////////////////////////////////////////
typedef struct Node
{
char data;
struct Node *next;
}LNode,*LinkList;
//////////////////////////////////////////////////
//////////Save the input string in link list//////////
//////////////////////////////////////////////////
LinkList input()
{
LinkList L;
LNode *s,*r;
char x;
L=r=NULL;
scanf("%c",&x);
while(x!='#')
{
s=(LNode*)malloc(sizeof(LNode));
s->data=https://bbs.csdn.net/topics/x;
if(L==NULL)
L=s;
else
r->next=s;
r=s;
scanf("%c",&x);
}
if(r!=NULL)
r->next=NULL;
return L;
}
/////////////////////////////////////////////////
/////////////////grammer///////////////
/////////////////////////////////////////////////
char nextview1(char a1,char a2)
{
char b='A';
{
if(a1 == 'A' && a2== 'a' )
b='B';
else if(a1 == 'A' && a2 == 'b' )
b='D';
else if(a1 == 'B' && a2 == 'a')
b='C';
else if(a1 == 'B' && a2 == 'b' )
b='D';
else if(a1 == 'C' && a2 == 'a' )
b='C';
else if(a1 == 'C' && a2 == 'b' )
b='C';
else if(a1 == 'D' && a2 == 'a' )
b='B';
else if(a1 == 'D' && a2 == 'b' )
b='E';
else if (a1 == 'E' && a2 == 'a' )
b='F';
else if (a1 == 'E' && a2 == 'b' )
b='E';
else if (a1 == 'F' && a2 == 'a' )
b='C';
else if (a1 == 'F' && a2 == 'b' )
b='E';
}
printf("stat is:\n",b);
return b;
}
////////////////////////////////////////////////////////
///////////judge 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(view!='E')
{
view=nextview1(view,dou1->data);
dou1=dou1->next;
}
else if(view!='F')
{
view=nextview1(view,dou1->data);
dou1=dou1->next;
}
else if(view=='E')
{
i=1;
}
else if(view=='F')
{
i=1;
}
}
printf("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)﹡bbb﹡\n");*/
printf("2. EXIT\n");
while (c!=3)
{
switch (c)
{
case 1:
{
choose1=move1(song);
if(choose1==1)
{
printf("string accord grammer\n");
}
else
printf("string is not accord grammr\n");
break;
}
case 2:
{
c=4;
break;
}
}
scanf("%d",&c);
}
}
程式要求是檢查輸入的字串是否符合程DFA定的語法 但是我每一次輸出字串 輸出結果都是不符合 實在不知道原因, 而且在nextview1這個函式里 我想顯示出STATE也顯示不出來, 我在網上查過 我的輸出陳述句應該是沒問題的 ,希望大神能幫我解答
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/145996.html
標籤:基礎類
上一篇:關于TreeView的問題
