ImageVerifierCode 换一换
格式:DOCX , 页数:41 ,大小:87.70KB ,
资源ID:6019122      下载积分:3 金币
快捷下载
登录下载
邮箱/手机:
温馨提示:
快捷下载时,用户名和密码都是您填写的邮箱或者手机号,方便查询和重复下载(系统自动生成)。 如填写123,账号就是123,密码也是123。
特别说明:
请自助下载,系统不会自动发送文件的哦; 如果您已付费,想二次下载,请登录后访问:我的下载记录
支付方式: 支付宝    微信支付   
验证码:   换一换

加入VIP,免费下载
 

温馨提示:由于个人手机设置不同,如果发现不能下载,请复制以下地址【https://www.bdocx.com/down/6019122.html】到电脑端继续下载(重复下载不扣费)。

已注册用户请登录:
账号:
密码:
验证码:   换一换
  忘记密码?
三方登录: 微信登录   QQ登录  

下载须知

1: 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。
2: 试题试卷类文档,如果标题没有明确说明有答案则都视为没有答案,请知晓。
3: 文件的所有权益归上传用户所有。
4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
5. 本站仅提供交流平台,并不能对任何下载内容负责。
6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

版权提示 | 免责声明

本文(课程设计报告.docx)为本站会员(b****5)主动上传,冰豆网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。 若此文所含内容侵犯了您的版权或隐私,请立即通知冰豆网(发送邮件至service@bdocx.com或直接QQ联系客服),我们立即给予删除!

课程设计报告.docx

1、课程设计报告编译原理课程设计报告学 院: 装备制造学院 专 业: 计算机12级 学 号: 1233050168 姓 名: 徐 晓 臣 教 师: 闫 红 时 间:2014.6.162014.6.23成 绩: 第一部分:词法分析一词法分析的功能: 输入-源程序文件原程序文件名:pas.cpp内容: if a =0 then b = 1 do a-a*b# 输出-(1)相应Token序列(f,”NUL”)(i,”a”)(=,”NUL”)(x,”0”)(t,”NUL”)(i,”b”)(=,”NUL”)(x,”1”)(d,”NUL”)(i,”a”)(-,” NUL”)(i,”a”)(*,”NUL”)(i

2、,”b”) (2)关键字、界限符、常数等内部码内部码编码号ifSy_if0thenSy_then1elseSy_else2whileSy_while3beginSy_begin4doSy_do5endSy_end6标识符Ident56#JingHao10;Semicolon8+Plus34*Times36:Becomes38(lParent48)rParent49二词法分析程序设计1单词- -Token序列2关键字等对照表内部码编码号ifSy_if0thenSy_then1elseSy_else2whileSy_while3beginSy_begin4doSy_do5endSy_end6标识符

3、Ident56#JingHao10;Semicolon8+Plus34*Times36:Becomes38(lParent48)rParent49单 词内部码编码号if Sy_if03.画出自动机转换图三程序实现1数据结构1 struct rWords ResWords10 = if,Sy_if, do,Sy_do, else,Sy_else, while,Sy_while, then,Sy_then, begin,Sy_begin, end,Sy_end, and,op_and, or,op_or, not,op_not;定义单词数组。char sp10;int sy; ;是对单词数组的数范

4、围定义2. static int action1913 = 2,-1,-1,3,4,-1,-1,5,-1,-1,-1,1,-1, -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,ACC,-1,-1, -1,-1,-1,-1,-1,-1,-1,-1,-1,6,-1,-1,-1, -1,-1,-1,-1,-1,-1,-1,-1,-1,7,-1,-1,-1, 2,-1,-1,3,4,-1,-1,5,-1,-1,-1,9,8, -1,-1,104,-1,-1,-1,104,-1,104,-1,104,-1,-1, -1,10,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1

5、, -1,-1,-1,-1,-1,11,-1,-1,-1,-1,-1,-1,-1, -1,-1,-1,-1,-1,-1,12,-1,-1,-1,-1,-1,-1, -1,-1,-1,-1,-1,-1,105,-1,13,-1,-1,-1,-1, 2,-1,-1,3,4,-1,-1,5,-1,-1,-1,14,-1, 2,-1,-1,3,4,-1,-1,5,-1,-1,-1,15,-1, -1,-1,103,-1,-1,-1,103,-1,103,-1,103,-1,-1, 2,-1,-1,3,4,-1,-1,5,-1,-1,-1,9,16, -1,-1,17,-1,-1,-1,-1,-1,-1

6、,-1,-1,-1,-1, -1,-1,102,-1,-1,-1,102,-1,102,-1,102,-1,-1, -1,-1,-1,-1,-1,-1,106,-1,-1,-1,-1,-1,-1, 2,-1,-1,3,4,-1,-1,5,-1,-1,-1,18,-1, -1,-1,101,-1,-1,-1,101,-1,101,-1,101,-1,-1;static int action1107 = 3,-1,-1,2,-1,-1,1, -1,4,5,-1,-1,ACC,-1, 3,-1,-1,2,-1,-1,6, -1,104,104,-1,104,104,-1, 3,-1,-1,2,-1,

7、-1,7, 3,-1,-1,2,-1,-1,8, -1,4,5,-1,9,-1,-1, -1,101,5,-1,101,101,-1, -1,102,102,-1,102,102,-1, -1,103,103,-1,103,103,-1; static int action21611 = 1,-1,4,-1,5,-1,-1,-1,13,7,8, -1,2,-1,101,-1,101,101,101,-1,-1,-1, 3,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, -1,-1,-1,102,-1,102,102,102,-1,-1,-1, 1,-1,4,-1,5,-1,-1,

8、-1,11,7,8, 1,-1,4,-1,5,-1,-1,-1,6,7,8, -1,-1,-1,104,-1,9,10,104,-1,-1,-1, 1,-1,4,-1,5,-1,-1,-1,14,7,8, 1,-1,4,-1,5,-1,-1,-1,15,7,8, 105,-1,105,-1,105,-1,-1,-1,-1,-1,-1, 107,-1,107,-1,107,-1,-1,-1,-1,-1,-1, -1,-1,-1,12,-1,9,10,-1,-1,-1,-1, -1,-1,-1,103,-1,103,103,103,-1,-1,-1, -1,-1,-1,-1,-1,9,10,ACC

9、,-1,-1,-1, -1,-1,-1,106,-1,9,10,106,-1,-1,-1, -1,-1,-1,108,-1,9,10,108,-1,-1,-1; static int action1913,static int action1107 ,static int action21611:是对SLR(1)的定义3. while (ss1 = 0 & ii a 0 102 101 j 0 102 = 1 b一共五列,第一列为地址,在输出程序Disp2( )中用temp1表示;第二列是算符OP,存储在程序中fexptemp1.op中;第三列是第一操作数,存储在程序中的nTab1fexpte

10、mp1.arg1.pos中;第四列是第二操作数,存储在程序中的nTab1fexptemp1.arg2.pos中;第五列是出口,程序中用tr和fr分别存储真出口和假出口3程序实现#include #include #include using namespace std;const int ACC = -2;const int Sy_if = 0;const int Sy_then = 1;const int Sy_else = 2;const int Sy_while = 3;const int Sy_begin = 4;const int Sy_do = 5;const int Sy_end

11、 = 6;const int a = 7;const int Semicolon = 8;const int e = 9;const int JingHao = 10;const int S = 11;const int L = 12;const int Tempsy = 15;const int EA = 18;const int EO = 19;const int Plus = 34;const int Times = 36;const int Becomes = 38;const int op_and = 39;const int op_or = 40;const int op_not

12、= 41;const int rop = 42;const int lParent = 48;const int rParent = 49;const int ident = 56;const int intConst = 57;char ch = 0;int Count = 0;static char Spelling10 = ;static char Line81 = ;char *Pline;static char nTab110010;struct nTab int tc; int fc;nTab2200;int Label = 0;struct rWords char sp10; i

13、nt sy;struct rWords ResWords10 = if,Sy_if, do,Sy_do, else,Sy_else, while,Sy_while, then,Sy_then, begin,Sy_begin, end,Sy_end, and,op_and, or,op_or, not,op_not;struct aa int sy1; int pos;buf1000,n,n1,E,sstack100,ibuf100,stack1000;struct aa oth1;struct FourExp char op10; struct aa arg1; struct aa arg2;

14、 int result;fexp200;int ssp = 0;struct aa *pbuf = buf;int nLength = 0;int Lnum = 0;int tt1 = 0;ifstream cfile(pas.cpp);ofstream mfile(pas.txt);int newt = 0;int nxq = 100;int Ir;int Ir1;int sp = 0;int stack1100;int sp1 = 0;int num = 0;struct ll int nxq1; int tc1; int fc1;LabelMark10;int LabelTemp10;i

15、nt PointMark = -1,PointTemp = -1;int sign = 0;static int action1913 = 2,-1,-1,3,4,-1,-1,5,-1,-1,-1,1,-1, -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,ACC,-1,-1, -1,-1,-1,-1,-1,-1,-1,-1,-1,6,-1,-1,-1, -1,-1,-1,-1,-1,-1,-1,-1,-1,7,-1,-1,-1, 2,-1,-1,3,4,-1,-1,5,-1,-1,-1,9,8, -1,-1,104,-1,-1,-1,104,-1,104,-1,104,-1,-1

16、, -1,10,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, -1,-1,-1,-1,-1,11,-1,-1,-1,-1,-1,-1,-1, -1,-1,-1,-1,-1,-1,12,-1,-1,-1,-1,-1,-1, -1,-1,-1,-1,-1,-1,105,-1,13,-1,-1,-1,-1, 2,-1,-1,3,4,-1,-1,5,-1,-1,-1,14,-1, 2,-1,-1,3,4,-1,-1,5,-1,-1,-1,15,-1, -1,-1,103,-1,-1,-1,103,-1,103,-1,103,-1,-1, 2,-1,-1,3,4,-1,-1,5,-

17、1,-1,-1,9,16, -1,-1,17,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, -1,-1,102,-1,-1,-1,102,-1,102,-1,102,-1,-1, -1,-1,-1,-1,-1,-1,106,-1,-1,-1,-1,-1,-1, 2,-1,-1,3,4,-1,-1,5,-1,-1,-1,18,-1, -1,-1,101,-1,-1,-1,101,-1,101,-1,101,-1,-1;static int action1107 = 3,-1,-1,2,-1,-1,1, -1,4,5,-1,-1,ACC,-1, 3,-1,-1,2,-1,-1,6,

18、 -1,104,104,-1,104,104,-1, 3,-1,-1,2,-1,-1,7, 3,-1,-1,2,-1,-1,8, -1,4,5,-1,9,-1,-1, -1,101,5,-1,101,101,-1, -1,102,102,-1,102,102,-1, -1,103,103,-1,103,103,-1; static int action21611 = 1,-1,4,-1,5,-1,-1,-1,13,7,8, -1,2,-1,101,-1,101,101,101,-1,-1,-1, 3,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, -1,-1,-1,102,-1,

19、102,102,102,-1,-1,-1, 1,-1,4,-1,5,-1,-1,-1,11,7,8, 1,-1,4,-1,5,-1,-1,-1,6,7,8, -1,-1,-1,104,-1,9,10,104,-1,-1,-1, 1,-1,4,-1,5,-1,-1,-1,14,7,8, 1,-1,4,-1,5,-1,-1,-1,15,7,8, 105,-1,105,-1,105,-1,-1,-1,-1,-1,-1, 107,-1,107,-1,107,-1,-1,-1,-1,-1,-1, -1,-1,-1,12,-1,9,10,-1,-1,-1,-1, -1,-1,-1,103,-1,103,1

20、03,103,-1,-1,-1, -1,-1,-1,-1,-1,9,10,ACC,-1,-1,-1, -1,-1,-1,106,-1,9,10,106,-1,-1,-1, -1,-1,-1,108,-1,9,10,108,-1,-1,-1;void ReadLine( ) char ch1; Pline = Line; ch1 = cfile.get(); while( ch1 != n) *Pline = ch1; Pline +; ch1 = cfile.get(); *Pline = 0; Pline = Line;void Readch( ) if (ch = 0) ReadLine( ); L

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1