《C语言词法分析器》开发文档及源代码Word文档格式.docx

上传人:b****6 文档编号:16258768 上传时间:2022-11-22 格式:DOCX 页数:33 大小:69.82KB
下载 相关 举报
《C语言词法分析器》开发文档及源代码Word文档格式.docx_第1页
第1页 / 共33页
《C语言词法分析器》开发文档及源代码Word文档格式.docx_第2页
第2页 / 共33页
《C语言词法分析器》开发文档及源代码Word文档格式.docx_第3页
第3页 / 共33页
《C语言词法分析器》开发文档及源代码Word文档格式.docx_第4页
第4页 / 共33页
《C语言词法分析器》开发文档及源代码Word文档格式.docx_第5页
第5页 / 共33页
点击查看更多>>
下载资源
资源描述

《C语言词法分析器》开发文档及源代码Word文档格式.docx

《《C语言词法分析器》开发文档及源代码Word文档格式.docx》由会员分享,可在线阅读,更多相关《《C语言词法分析器》开发文档及源代码Word文档格式.docx(33页珍藏版)》请在冰豆网上搜索。

《C语言词法分析器》开发文档及源代码Word文档格式.docx

调用字符常量判断函数voidc_search进行处理

字符串常量

调用字符串常量判断函数voidcc_search进行处理

整数常量

调用整数类型判断函数voidinta_search进行处理

浮点数常量

调用浮点类型判断函数voidintb_search进行处理

注释

限制符

写入注释文件

查运算符、分隔符表并写入输出文件

五、关键代码

#include<

stdio.h>

string.h>

stdlib.h>

char*key0[]={"

"

"

auto"

break"

case"

char"

const"

continue"

default"

do"

double"

else"

enum"

extern"

float"

for"

goto"

if"

int"

long"

register"

return"

short"

signed"

sizeof"

static"

struct"

switch"

typedef"

_Complex"

_Imaginary"

union"

unsigned"

void"

volatile"

while"

};

/*保留字表*/

char*key1[]={"

("

)"

["

]"

{"

}"

;

"

'

/*分隔符表*/

char*key2[]={"

+"

-"

*"

/"

%"

<

>

=="

="

!

&

||"

~"

|"

^"

?

:

->

++"

--"

."

+="

-="

*="

/="

/*运算符表*/

intxx0[35],xx1[10],xx2[31];

inttemp_key3=0,temp_c40=0,temp_c41=0,temp_c42=0,temp_c43=0;

/*******初始化函数*******/

voidload()

{

intmm;

for(mm=0;

mm<

=34;

mm++)

{

xx0[mm]=0;

}

=9;

xx1[mm]=0;

=30;

xx2[mm]=0;

FILE*floading;

if((floading=fopen("

key0.txt"

w"

))==NULL)

printf("

Error!

Can'

tcreatefile:

key0.txt"

);

return;

fclose(floading);

/*建立保留字表文件:

key0.txt*/

key1.txt"

key1.txt"

/*建立分隔符表文件:

key1.txt*/

key2.txt"

key2.txt"

fclose(floading);

/*建立运算符表文件:

key2.txt*/

key3.txt"

key3.txt"

/*建立标识符表文件:

key3.txt*/

c40.txt"

c40.txt"

/*建立整数类型常量表文件:

c40.txt*/

c41.txt"

c41.txt"

/*建立浮点类型常量表文件:

c41.txt*/

c42.txt"

c42.txt"

/*建立字符类型常量表文件:

c42.txt*/

c43.txt"

c43.txt"

/*建立字符串类型常量表文件:

c43.txt*/

defination.txt"

defination.txt"

/*建立注释文件:

defination.txt*/

output.txt"

output.txt"

/*建立内部码文件:

output.txt*/

temp_key1"

temp_key1"

/*建立保留字临时表文件:

temp_key1*/

temp_key3"

temp_key3"

/*建立标识符临时文件:

temp_key3*/

temp_c40"

temp_c40"

/*建立整数类型常量临时文件:

temp_c40*/

temp_c41"

temp_c41"

/*建立浮点类型常量临时文件:

temp_c41*/

temp_c42"

temp_c42"

/*建立字符类型常量临时文件:

temp_c42*/

temp_c43"

temp_c43"

/*建立字符串类型常量临时文件:

temp_c43*/

}

/*******保留字及标识符判断函数*******/

voidchar_search(char*word)

intm,line=0,csi=0;

intvalue=0;

intvalue2=0;

charc,cs[100];

FILE*foutput,*finput;

for(m=1;

m<

m++)

if(strcmp(word,key0[m])==0)

{

value=1;

break;

}

if(value==1)

if(xx0[m]==0)

foutput=fopen("

a"

fprintf(foutput,"

0\t%d\t\t%s\n"

m,word);

fclose(foutput);

xx0[m]=1;

foutput=fopen("

fprintf(foutput,"

fclose(foutput);

else

if(temp_key3==0)

%s\n"

word);

temp_key3++;

3\t1\t\t%s\n"

finput=fopen("

r"

c=fgetc(finput);

while(c!

=EOF)

while(c!

='

\n'

{

cs[csi++]=c;

c=fgetc(finput);

}

cs[csi]='

\0'

csi=0;

line++;

if((strcmp(cs,word))==0)

value2=1;

break;

else

value2=0;

fclose(finput);

if(value2==1)

3\t%d\t\t%s\n"

line,word);

else

temp_key3,word);

/*******整数类型判断函数*******/

voidinta_search(char*word)

charc;

charcs[100];

intcsi=0;

intline=0;

if(temp_c40==0)

temp_c40++;

4\t0\t1\t%s\n"

finput=fopen("

c=fgetc(finput);

while(c!

cs[csi++]=c;

c=fgetc(finput);

cs[csi]='

csi=0;

line++;

if(strcmp(cs,word)==0)

value2=1;

fclose(finput);

if(value2==1)

4\t0\t%d\t%s\n"

temp_c40,word);

/*******浮点类型判断函数*******/

voidintb_search(char*word)

if(temp_c41==0)

temp_c41++;

4\t1\t1\t%s\n"

4\t1\t%d\t%s\n"

temp_c41,word);

/*******字符串常量判断函数*******/

voidcc_search(char*word)

if(temp_c43==0)

temp_c43++;

4\t3\t1\t%s\n"

4\t3\t%d\t%s\n"

temp_c43,word);

/*******字符常量判断函数*******/

voidc_search(char*word)

if(temp_c42==0)

temp_c42++;

4\t2\t1\t%s\n"

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 小学教育 > 语文

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

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