编译原理词法分析器C源代码.txt资料文档下载
《编译原理词法分析器C源代码.txt资料文档下载》由会员分享,可在线阅读,更多相关《编译原理词法分析器C源代码.txt资料文档下载(9页珍藏版)》请在冰豆网上搜索。
);
exit(0);
}
else
�ɹ����ĵ�in.txt\n"
if((out=fopen("
out.txt"
w"
���ܴ��ĵ�out.txt�������Ŀ¼
�ɹ����ĵ�out.txt\n"
cp=fgetc(in);
while(cp!
=EOF)
/*���ĵ�ո��Ʊ�������з�*/
while(cp=='
'
||cp=='
\t'
\n'
)
{
cp=fgetc(in);
}
/*cp���鸴λ*/
i=0;
/*���ּ��*/
if(cp>
='
0'
&
cp<
9'
word[i++]=cp;
while(cp>
{
word[i++]=cp;
cp=fgetc(in);
}
if(cp=='
+'
-'
*'
/'
>
'
<
!
;
:
'
{'
}'
['
]'
('
)'
word[i]='
\0'
fprintf(out,"
%c%c%s%c,%d%c\n"
"
word,'
28,'
else
while(cp!
cp!
{
word[i++]=cp;
cp=fgetc(in);
}
%s%c%s%c%s\n"
error:
"
���ǺϷ��ı�ʶ��"
continue;
/*�ַ������*/
if((cp>
a'
z'
)||(cp>
A'
Z'
)||cp=='
_'
while((cp>
/*���������ּ��*/
if(strcmp(word,"
main"
)==0)
fprintf(out,"
1,'
elseif(strcmp(word,"
void"
2,'
int"
3,'
float"
4,'
double"
5,'
char"
6,'
struct"
7,'
elseif(strcmp(word,"
const"
8,'
extern"
9,'
register"
10,'
static"
11,'
if"
12,'
else"
13,'
switch"
14,'
elseif(strcmp(word,"
case"
15,'
for"
16,'
do"
17,'
while"
18,'
goto"
19,'
continue"
20,'
break"
21,'
default"
22,'
sizeof"
23,'
return"
24,'
else
�Զ����ʶ��:
29,'
/*�Ŵ�����ֻ������ĸ�����֡��»
��߹��ɣ�*/
while(cp!
{
word[i++]=cp;
cp=fgetc(in);
}
word[i]='
/*�����*/
if(cp=='
word[i]='
fprintf(out,"
31,'
32,'
33,'
word[i++]=cp;
cp=fgetc(in);
if(cp=='
){word[--i]='
while(cp!
){cp=fgetc(in);
}cp=fgetc(in);
}
else
fprintf(out,"
34,'
word[i]='
39,'
27,'
36,'
35,'
38,'
37,'
40,'
/*���*/
41,'
42,'
43,'
44,'
45,'
46,'
47,'
48,'
49,'
/*����ʶ����ַ�*/
word[i++]=cp;
cp=fgetc(in);
word[i]='
fprintf(out,"
fclose(in);
fclose(out);
printf("
�ɹ���in.txt�ĵ��ڴ�����дʷ��������������������out.txt�ĵ���\n"
return0;