资源简介
编译原理实验:非递归预测分析;对LL1文法进行预测分析、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、////////////////////////////////////////////////////////////////

代码片段和文件信息
#include
#include
#include
#include
using namespace std;
char termin[7]={‘#‘‘;‘‘+‘‘*‘‘(‘‘)‘‘i‘}; /*终结符号*/
char non_ter[8]={‘p‘‘P‘‘e‘‘t‘‘E‘‘f‘‘T‘‘S‘}; /*非终结符号*/
char Yy_pushtab[13][3]= /*逆序存放产生式右部内容*/
{
{‘P‘‘;‘‘E‘}
{‘p‘}
{‘\0‘}
{‘E‘‘t‘}
{‘\0‘}
{‘E‘‘t‘‘+‘}
{‘\0‘}
{‘T‘‘f‘}
{‘T‘‘f‘‘*‘}
{‘\0‘}
{‘)‘‘e‘‘(‘}
{‘i‘}
{‘p‘}
};
int Yy_d[8][7]= //LL1分析表
{
{-10-1-10-10}
{21-1-11-11}
{-14-1-1343}
{-1-1-1-17-17}
{-165-1-16-1}
{-1-1-1-110-111}
{-1998-19-1}
{-112-1-112-112}
};
bool is_Vt(char xchar y[])//判断是否为终结符
{
int i;
for(i=0;i {
if(y[i]==x)
return(1); //若是,返回1
}
return(0); //若不是,返回0
}
/*******************************************
主函数
********************************************/
void main()
{ int ijkpqwhat_to_do;
char chre;
char W[20]=“S“S[20]=“S“str[20]st[20];
printf(“\n 请输入该文法的句型:“);
scanf(“%s“st);
for(int a=0;a<=strlen(st);a++)
{
r=st[a];
if(isdigit(r))
str[a]=‘i‘;
else str[a]=st[a];
}
st[strlen(st)]=‘#‘;
i=strlen(str);
// str[i]=‘#‘;
// str[i+1]=‘\0‘;
j=0;
ch=str[j];
cout< while(S[0]!=‘\0‘)//分析栈非空则继续
{for(q=0;S[q]!=‘\0‘;q++)
W[q]=S[q];
W[q]=‘\0‘;
if(is_Vt(S[strlen(S)-1]termin))//栈顶为终结符
{
what_to_do=-1;
if(S[strlen(S)-1]!=ch)//栈顶与输入符号不等
{
printf(“\n分析结果:该符号串不是文法的句型!\n“);
return;
}
else
{
S[strlen(S)-1]=‘\0‘;
j++;
ch=str[j];
}
}
else //栈顶为非终结符
{
for(i=0;;i++)//获得Yy_d[][]的第一个下标
if(non_ter[i]==S[strlen(S)-1])
break;
for(k=0;;k++)//获得Yy_d[][]的第二个下标
{
if(termin[k]==ch)
break;
if(k==strlen(termin))//输入符号不是终结符
{
printf(“词法错误!“);
return;
}
}
what_to_do=Yy_d[i][k];
if(what_to_do==-1)
{
printf(“语法错误!“);
return;
}
else //把栈顶元素弹出 再把右部压栈
{
if(Yy_pushtab[what_to_do][0]==‘\0‘)
S[strlen(S)-1]=‘\0‘;
else
{int mn;
n=strlen(S)-1;
m=n;
for(int h=0;h S[n++]=Yy_pushtab[what_to_do][h];
S[m+strlen(Yy_pushtab[what_to_do])]=‘\0‘;
}
}
}
printf(“ %s “W);
for(p=j;p printf(“%c“st[p]);
if(what_to_do>=0)
printf(“ %d“what_to_do);
printf(“ \n“);
}
printf(“\n分析结果:该符号串是文法的句型.\n“);
return;
}
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 127 2009-06-08 19:59 LL1文法.txt
文件 3110 2009-04-27 21:36 LL1.cpp
----------- --------- ---------- ----- ----
3237 2
相关资源
- C++获取计算机的CPU ID,硬盘序列号等
- C++头文件转delphi工具 + 源码
- 国际象棋的qt源代码
- C++中头文件与源文件的作用详解
- C++多线程网络编程Socket
- VC++ 多线程文件读写操作
- 利用C++哈希表的方法实现电话号码查
- 移木块游戏,可以自编自玩,vc6.0编写
- C++纯文字DOS超小RPG游戏
- VC++MFC小游戏实例教程(实例)+MFC类库
- 连铸温度场计算程序(C++)
- 6自由度机器人运动学正反解C++程序
- Em算法(使用C++编写)
- libstdc++-4.4.7-4.el6.i686.rpm
- VC++实现CMD命令执行与获得返回信息
- 白话C++(全)
- C++标准库第1、2
- 大数类c++大数类
- C++语言编写串口调试助手
- c++素数筛选法
- C++ mqtt 用法
- 商品库存管理系统 C++ MFC
- c++ 多功能计算器
- C++17 In Detail
- 嵌入式QtC++编程课件
- 颜色识别形状识别STM103嵌入式代码
- c++ 邮件多附件群发
- c++ 透明代理(hookproxy)
- mfc 调用redis
- FTP客户端源码(c++)
评论
共有 条评论