资源简介
LR1分析器代码实现

代码片段和文件信息
/*-------------------LR(1) grammar -------------------------------------
S->E
E->E*E
E->E+E
E->(E)
E->i
----------------------------LR(1) parsing table-------------------------------------------
state * + ( ) i $ E
0 s2 s3 1
1 s4 s5 r0
2 s7 s8 6
3 r4 r4 r4
4 s2 s3 9
5 r2 r2 r2 10
6 s12 s13 s11
7 s7 s8 14
8 r4 r4 r4
9 s4 r1 r1
10 s4 s5 r2
11 r3 r3 r3
12 s7 s8 15
13 s7 s8 16
14 s12 s13 s17
15 s12 r1 r1
16 r2 s13 r2
17 r3 r3 r3
---------------------------------------------------------------------------------------*/
#include “CPT.h“
//----------------------Global Declarition---------------------------------
#define SIZE 20
#define sSIZE 18 //There are sSIZE status
#define aSIZE 6 //There will ecounter aSIZE symbol
#define gSIZE 1 //May be goto next gSIZE status
#define geSIZE 5 //There are geSIZE generate expression
#define MAXSIZE 3
//---------------------Finish defining struct-------------------------------------
typedef struct Ge
{
char head; //Leftpart of Generate expression
char gen[4]; //Rightpart of Generate expression
}Generate;//--------------------------------Generate expression base datastruct
typedef struct A
{
int st[aSIZE]; //aSIZE status when encountering terminated symbol
int re[aSIZE]; //Using reduce
}Action;//----------------------------------Action table base datastruct
typedef struct G
{
char head[gSIZE]; //Nonterminated symbol :‘E‘
int gt[gSIZE]; //Mark the next status
}GOTO;//------------------------------------GOTO table base datastruct
int status[SIZE]; //stack of status
int sta_Index; //top of stack of status
char symbol[SIZE]; //stack of symbol
int sym_Index; //Current index of symbol stack
char expression[SIZE]; //Inputed expression
int exp_Index; //index of inputed expression
int exp_top; //top of expression that inputed
int step; //accumulated steps
int IsAccept = 0; //Initlize accept flag to 0
Generate gene[geSIZE +1];
Action act[sSIZE];
GOTO go[sSIZE];
fstream outFile;
//------------------------------------------------------------------------
void GOTOTable(int sta char symb);
void Inputexpression()
{
char ch;
printf(“请输入分析串“);
printf(“[包括:{ + * ( )i # }以‘#‘结束]:\n“);
exp_Index = 0;
do
{
scanf(“%c“&ch);
if ((ch!=‘i‘) &&(ch!=‘+‘) &&(ch!=‘*‘)&&(ch!=‘#‘)&&(ch!=‘(‘)&&(ch!=‘)‘))
{
printf(“Illegal Word inside...Press any key to EXIT!\n“);
getchar();
exit(0);
}
expression[exp_Index++]=ch;
}while(ch!=‘#‘);
}
void PrintStatus()
{
long i = 0;
for(i = 0; i <= sta_Index; i++)
{
p
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
目录 0 2012-01-08 01:21 LR1 analyser\
文件 1049 2011-12-29 20:58 LR1 analyser\CPT.CPP
文件 325 2011-12-29 20:58 LR1 analyser\CPT.H
目录 0 2012-01-08 01:21 LR1 analyser\Debug\
文件 1346 2011-12-29 21:00 LR1 analyser\Debug\cl.command.1.tlog
文件 18246 2011-12-29 21:00 LR1 analyser\Debug\CL.read.1.tlog
文件 902 2011-12-29 21:00 LR1 analyser\Debug\CL.write.1.tlog
文件 381150 2011-12-29 21:00 LR1 analyser\Debug\CPT.obj
文件 2 2011-12-29 21:00 LR1 analyser\Debug\li
文件 2 2011-12-29 21:00 LR1 analyser\Debug\li
文件 2 2011-12-29 21:00 LR1 analyser\Debug\li
文件 2 2011-12-29 21:00 LR1 analyser\Debug\li
文件 2 2011-12-29 21:00 LR1 analyser\Debug\li
文件 2 2011-12-29 21:00 LR1 analyser\Debug\li
文件 1614 2011-12-29 21:00 LR1 analyser\Debug\li
文件 3356 2011-12-29 21:00 LR1 analyser\Debug\li
文件 876 2011-12-29 21:00 LR1 analyser\Debug\li
文件 644608 2011-12-29 21:00 LR1 analyser\Debug\LR1 analyser.exe
文件 406 2011-12-29 21:00 LR1 analyser\Debug\LR1 analyser.exe.em
文件 472 2011-12-29 21:00 LR1 analyser\Debug\LR1 analyser.exe.em
文件 381 2011-12-29 21:00 LR1 analyser\Debug\LR1 analyser.exe.intermediate.manifest
文件 1628736 2011-12-29 21:00 LR1 analyser\Debug\LR1 analyser.ilk
文件 61 2011-12-29 21:00 LR1 analyser\Debug\LR1 analyser.lastbuildstate
文件 3917 2011-12-29 21:00 LR1 analyser\Debug\LR1 analyser.log
文件 502472 2011-12-29 21:00 LR1 analyser\Debug\LR1 analyser.obj
文件 2681856 2011-12-29 21:00 LR1 analyser\Debug\LR1 analyser.pdb
文件 220 2011-12-29 20:54 LR1 analyser\Debug\LR1 analyser_manifest.rc
文件 412 2011-12-29 21:00 LR1 analyser\Debug\mt.command.1.tlog
文件 310 2011-12-29 21:00 LR1 analyser\Debug\mt.read.1.tlog
文件 310 2011-12-29 21:00 LR1 analyser\Debug\mt.write.1.tlog
文件 566 2011-12-29 21:00 LR1 analyser\Debug\rc.command.1.tlog
............此处省略24个文件信息
相关资源
- VisualStudioUninstaller vs卸载工具
- 组态王驱动开发包3.0.0.7(中文)
- 多窗口后台鼠标连点器
- 使用选择性重传协议实现UDP可靠通信
- VC 获得文件属性 获取文件的创建时
- 读者写者问题(读者优先,写者优先
- 用VC 编写的仿QQ聊天室程序源代码
- 外点法程序
- 外罚函数程序
- qt-电子点菜系统
- 推箱子及人工智能寻路C 源代码
- 自己写的航空订票系统c 版--数据结构
- 数据结构实验魔王语言
- MUSIC算法c 实现
- C 餐厅叫号系统(QT平)
- 国际象棋c 完整版
-
ob
jectARX给Auto CAD加工具条 - 画图程序MFC/VC/VC CRectTracker 串行化
- MFC网络编程实例
- c 课程设计 职工信息管理系统
- VC 游戏编程—附源代码
- IpHlpApi.h&IpHlpApi.lib
- 清华大学 c 郑莉 ppt课件
- c 程序判断离散数学中命题公式
- 多项式求和(数据结构C 版)
- vc 6.0开发的流程图编辑器
- VC 天空盒(skyBox)实现(附源代码)
- c MFC 画多边形
- 用C 实现的对网络上的ARP数据包进行
- Microsoft基本类库 (MFC)(C 库)
评论
共有 条评论