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

加入VIP,免费下载
 

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

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

下载须知

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

版权提示 | 免责声明

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

编译原理实验报告.docx

1、编译原理实验报告编译原理实验报告指导老师: 丁老师专业班级:08软件工程3班姓 名: xxxx学 号: 0801070311xx时 间:2010年12月26日1试验目的设计编制并调试一个词法分析程序,加深对此法分析原理的理解。可以识别浮点数。2试验要求单词符号种别码单词符号 种别码单词符号种别码单词符号种别码main1=21,30“39int2+22;310100char3-23:32ERROR-1if4*2433public8else5/25=35include10while7)27=36struct11ID5028=37float12NUM2029!=38static13说明:在源程序的基

2、础上添加了许多新单词和对浮点数的识别。3程序结构程序用C编写,编译环境是VC6.0。syn 整型,记录单词符号的种别编码。tmp 字符数组,长度为256,可以缓存用户输入的字符串。token 字符数组,长度为32,存放识别出来的单词符号。ch 字符型,存放当前所取的字符。void getch() /读字符函数,从缓冲区读入下一个字符放在ch中,并指向下一个字符。void output() /打印指针所指向的字符串。void getbc() /检查ch是否为空白字符,若是则调用getch()直到ch中读入一个非空白字符。void concat() /把当前ch中字符与token中字符串连接。in

3、t letter() /判定ch中是否为字母。int digit() /判定ch中是否为数字。int ispoint() /判定ch中是否为小数点。int reserve() /对token中的字符串查表。若是返回关键字,否则返回50。void scanner() /扫描buffer字符串的词法分析函数。4总结程序可以成功运行,每次由用户输入一行字符串,程序将扫描此串,并将词法分析结果在屏幕上显示。程序也可以做到对浮点数的识别。如下程序:public static void main() int a = 0; int b = 100; float f = 1.5; char c = a; wh

4、lie(a!=z) a=a+1; f=(a+b-c)/a;5程序#include#include#include#include#define LEN sizeof(struct Node)struct Node char data; struct Node*next;struct Node*head,*p;char ch;char*key13=main,int,char,if,else,for,while,public,void,include,struct,float,static;char token20;void getch() ch=p-data; p=p-next;void out

5、put(struct Node*head) if(!head) printf(something wrong whith head node); exit(1); p=head-next; while(p-next!=NULL) printf(%c,p-data); p=p-next; printf(n);void getbc() while(ch= ) getch();void concat() unsigned int i; i=strlen(token); tokeni=ch; tokeni+1=0;int letter(char ch) return isalpha(int)ch);i

6、nt digit(char ch) return isdigit(int)ch);int ispoint(char ch) if(ch=.) return 1; else return 0;int reserve() int k; for(k=0;knext; while(Q-next!=p) Q=Q-next; p=Q;void back(int a,char*b) printf(%d,%s)n,a,b);void scaner() int c; token0=NULL; getch(); getbc(); if(letter(ch) while(letter(ch)|digit(ch) c

7、oncat(); getch(); retract(); c=reserve(); if(c!=10) back(c,token); else back(10,token); else if(digit(ch) int i=0; while(digit(ch)|ispoint(ch) if(ispoint(ch) i+; if(i=2) break; concat(); getch(); retract(); if(i=0)printf(20,%d)n,atoi(token); else printf(20,);printf(token);printf()n); else switch(ch)

8、 case+: back(22,+);break; case-: back(23,-);break; case*: back(24,*);break; case/: back(25,/); case(: back(26,();break; case): back(27,);break; case: back(28,); case: back(29,);break; case,: back(30,);break; case;: back(31,;);break; case: back(32,:);break; case=: getch(); if(ch=) back(37,=); else re

9、tract(); back(21,=); break; case: getch(); if(ch=) back(35,); else retract(); back(33,); break; case: getch(); if(ch=) back(36,=); else retract(); back(34,next=NULL; head-data= ; p=head; printf(please input your code:n); while(1) int i=0; char tmp256; gets(tmp); if(tmp0=#) break; p-next=(struct Node

10、*)malloc(LEN); if(!(head-next) printf(failed to create a new node!);exit(1); p=p-next; while(tmpi!=0)&(idata=tmpi; p-next=(struct Node*)malloc(LEN); if(!(p-next) printf(failed to create a new node!); exit(1); p=p-next; i+; p-data=n; p-next=NULL; printf(nthe code you input is:n); output(head); printf(nafter compling, the result is:n); p=head-next; while(p-next!=NULL) scaner(); system(pause); return 0;

copyright@ 2008-2023 冰点文库 网站版权所有

经营许可证编号:鄂ICP备19020893号-2