- 博客(0)
- 资源 (3)
空空如也
用MFC做的一个Pascal词法分析器
FILE *outfp;
char dir[100000];
char ch;
char *keyword[400]={"and","array","begin","case","const","div","do","downto","to","else,","end",
"file","for","function","goto","if","in","label","mod","nil","not","of","or","packed",
"procedure","program","record","repeat","then","type","until","var","while","with","rewrite",
"reset","put","write","writeln","read","readln"};
int begin=0,forward=0;
void Keyword(int a)
{
begin=a;
forward=begin;
char ss[100];
int k,j=0;
int flag=0;
while( isalpha(dir[forward])||isdigit(dir[forward]) )
{
ss[j]=dir[forward];
forward++;
j++;
}
ss[j]='\0';
for(k=0;k<41;k++)
{
if( strcmp(ss,keyword[k])==0 )
{
flag=1;
fwrite(ss,strlen(ss),1,outfp);
fwrite("\t [关键字] \n",12,1,outfp);
begin=forward;
}
}
if(!flag)
{
fwrite(ss,strlen(ss),1,outfp);
fwrite("\t [标识符] \n",12,1,outfp);
begin=forward;
}
}
2011-04-04
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人