- 1、本文档共11页,可阅读全部内容。
- 2、原创力文档(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。
- 3、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载。
- 4、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
查看更多
编译词法分析器(Compile lexical analyzer)
编译词法分析器(Compile lexical analyzer)
# includes stdio.h
# includes stdlib.h
# includes string.h
char kindcode [34] [20] = {undefined, identifier, integer, +, -, *, /,
%, , = , =, = =, . = , , | | , = , (,
, ,, ],, (, ), ;,, , void, int, float, char.
if, else, white, do, return}; / / 种别码定义
char prog [200].
int p = 0; / / 搜索指示器
void combine (char * token, char c)
{
int i;
the = strlen (token).
token [+ +] = c;
}
bool isletter (char c)
{
if (c = c = zs | | c = a c = z)
return 1;
else
return 0;
}
bool isdigit (char c)
{
if (c = 0 c = 9)
return 1;
else
return 0;
}
int checkbiao (char token [])
{
int i;
for (i = 0; i 34; i + +)
{
if (strcmp (token, kindcode [i]) = = 0)
return i;
}
return 0;
}
void menu ()
{
printf (* * * * 欢迎使用c语言小子集词法分析程序 * * * \ n );
printf (* * * 0 - - undefined 1 - - 2 - - integer identifier is * * * \ n );
printf (* * *) - + 4 - - - 5 - - * * * * * \ n );
printf (* * 6 - / 7 - % 8 * * * n );
printf (* * 9 - = 10 - 11 - = * * n);
printf (* * 12 - = = 13 - ! = 14 - * * n );
printf (* * 15 - | | 16 - = 17 - ( * * n);
printf (* 18 - 19 - - [20] * * n );
printf (* 21 - - - - {22} 23 ; * * n );
printf (* * 24 - , 25 - void 26 - int * * n);
printf (* * 27 - float 28 char 29 - - if * * n);
printf (* * 30 - else 31 - while 32 - do * * n);
printf (* * 33 - - return * * n);
}
int main ()
{* fp1 file * fp;
int i;
char token [200], filename [30];
char ch;
memset (token, 0, sizeof (token));
memset (prog, 0, sizeof (prog));
menu ();
printf (请输入文件名: \ n);
scanf (% s, filename);
if ((fp = fopen (filename, r)) = = null)
{
printf (此文件不存在! \ n );
return 0;
}
printf (读取程序成功! \ n );
Printf (the result of lexical analysis is also available in the E disk, result.Txt): \n;
For (i=0; (ch=fgetc (FP)) =EOF; i++)
{
Prog[i]=ch;
}
Prog[i]=\0;
Fclose (FP);
Ch=prog[0];
Fp1=fopen (E:\\ results.Txt, w+);
While (CH, =\0)
{
If (isletter (CH))
{
While (isletter (CH) ==1||isdigit (CH) ==1)
{
Combine (token, CH);
Ch=prog[++p];
}
I=checkbiao (token);
If (I) / /
您可能关注的文档
- 给排水说明及工程量计算规则(Specification of water supply and drainage and calculation rules of quantities).doc
- 给系统添加查看ai、psd、cdr、eps图片缩略图功能(Add AI, PSD, CDR and EPS thumbnail images to the system).doc
- 给编程初学者的一些建议(Some suggestions for beginners programming).doc
- 给美容院老板的一封信(A letter to the owner of the beauty salon).doc
- 给花友的养天资料(A date for a friend).doc
- 给药学本科毕业工作、考研迷茫的同学们(For graduates of pharmacy, postgraduate studies, confused students).doc
- 给高三学生5个建议(Give 5 suggestions to senior three students).doc
- 给宝宝选用枕头,4个误区和3个关键点(Choose the pillow for your baby, 4 mistakes and 3 key points).doc
- 络合滴定练习题(Complexometric titration exercises).doc
- 给排水安装工程施工组织设计(Construction design of water supply and drainage installation project).doc
文档评论(0)