91av视频/亚洲h视频/操亚洲美女/外国一级黄色毛片 - 国产三级三级三级三级

  • 大小: 20KB
    文件類型: .cpp
    金幣: 1
    下載: 0 次
    發布日期: 2021-05-05
  • 語言: C/C++
  • 標簽: LL1文法??

資源簡介

輸入文法,輸入表達式,判斷表達式是否符合文法,有求解first和follow集,有匹配過程

資源截圖

代碼片段和文件信息

//用LL(1)方法構造語法分析器
//程序源代碼及注釋:
/*******************************************
?
語法分析程序
?
********************************************/
#include
#include
#include
/*******************************************/

int?count=0;??????????????/*分解的產生式的個數*/
int?number;???????????????/*所有終結符和非終結符的總數*/
char?start;???????????????/*開始符號*/
char?termin[50];??????????/*終結符號*/
char?non_ter[50];?????????/*非終結符號*/
char?v[50];???????????????/*所有符號*/
char?left[50];????????????/*左部*/
char?right[50][50];???????/*右部*/
char?first[50][50]follow[50][50];???????/*各產生式右部的FIRST和左部的FOLLOW集合*/
char?first1[50][50];??????/*所有單個符號的FIRST集合*/
char?select[50][50];??????/*各單個產生式的SELECT集合*/
char?f[50]F[50];?????????/*記錄各符號的FIRST和FOLLOW是否已求過*/
char?empty[20];???????????/*記錄可直接推出^的符號*/
char?TEMP[50];????????????/*求FOLLOW時存放某一符號串的FIRST集合*/
int?validity=1;???????????/*表示輸入文法是否有效*/
int?ll=1;?????????????????/*表示輸入文法是否為LL(1)文法*/
int?M[20][20];????????????/*分析表*/
char?choose;??????????????/*用戶輸入時使用*/
char?empt[20];????????????/*求_emp()時使用*/
char?fo[20];??????????????/*求FOLLOW集合時使用*/

/*******************************************
?判斷一個字符是否在指定字符串中
********************************************/
int?in(char?cchar?*p)
{
int?i;
if(strlen(p)==0)
return(0);
for(i=0;;i++)
{
if(p[i]==c)
return(1);???????/*若在,返回1*/
if(i==strlen(p))
????return(0);???????/*若不在,返回0*/
}
}
/*******************************************
?得到一個不是非終結符的符號
********************************************/
char?c()
{
char?c=‘A‘;
????while(in(cnon_ter)==1)
c++;
return(c);
}
/*******************************************
?分解含有左遞歸的產生式
********************************************/
void?recur(char?*point)
{?????????????????????/*完整的產生式在point[]中*/
????int?jm=0n=3k;
char?temp[20]ch;
ch=c();???????????/*得到一個非終結符*/
k=strlen(non_ter);
non_ter[k]=ch;
non_ter[k+1]=‘\0‘;
for(j=0;j<=strlen(point)-1;j++)
{
if(point[n]==point[0])???//A->A...情況?
{??????????????????????????
for(j=n+1;j<=strlen(point)-1;j++)
{
??? while(point[j]!=‘|‘&&point[j]!=‘\0‘)
????temp[m++]=point[j++];
left[count]=ch;
memcpy(right[count]tempm);
right[count][m]=ch;
right[count][m+1]=‘\0‘;
m=0;
count++;
if(point[j]==‘|‘)
{
n=j+1;
break;
}
}
}
else
{?????????????????????????//A->a...情況?
left[count]=ch;
right[count][0]=‘^‘;
right[count][1]=‘\0‘;
count++;
for(j=n;j<=strlen(point)-1;j++)
{
????if(point[j]!=‘|‘)
????????temp[m++]=point[j];
????else
{
????left[count]=point[0];
????memcpy(right[count]tempm);
????right[count][m]=ch;
????right[count][m+1]=‘\0‘;
printf(“?count=%d?“count);
m=0;
????count++;
}
}
????????????left[count]=point[0];
????memcpy(right[count]tempm);
????right[count][m]=ch;
?????? right[count][m+1]=‘\0‘;
count++;
????m=0;
}
}
}
/********

評論

共有 條評論