📄 1.txt
字号:
}
else if(ch=='.')
{
state=6;
}
else{
state=0;
forward = forward - 1;
token[index]='\0';
index++;
flag=1;
output(flag);
}
break;
case 3: ch = Buffer[forward]; /*寻找注释符的前半部分*/
if(ch=='*')
{
state=4;
}
else if(ch=='=')
{
state=0;
token[index]=ch;
index++;
token[index]='\0';
index++;
flag=2;
output(flag);
}
else{
token[index]='\0';
index++;
flag=2;
output(flag);
state=0;
forward = forward - 1;
}
break;
case 4: ch = Buffer[forward];
temp = forward - 1;
if(ch!='/') /*寻找注释符后半部分*/
state=4;
else{
if(Buffer[temp]=='*')
state=0;
else{
printf("Remark symbol error!\n");
state=0;
}
}
break;
case 5: ch = Buffer[forward];
if(ch=='=')
{
state=0;
token[index]=ch;
index++;
token[index]='\0';
index++;
flag=2;
output(flag);
}
else if(ch=='+')
{
state=0;
token[index]=ch;
index++;
token[index]='\0';
index++;
flag=2;
output(flag);
}
else if(ch=='-')
{
state=0;
token[index]=ch;
index++;
token[index]='\0';
index++;
flag=2;
output(flag);
}
else{
token[index]='\0';
index++;
flag=2;
output(flag);
state=0;
forward = forward - 1;
}
break;
case 6: ch = Buffer[forward];
temp = forward - 1;
if(isdigit(ch))
{
token[index]=Buffer[temp]; /*将'.'放入token*/
index++;
token[index]=ch; /*将该数字放入token*/
index++;
state=7;
}
else{
token[index]='\0'; /*输出前面的数字*/
index++;
flag=1;
output(flag);
index=0; /*输出'.'*/
token[index]=Buffer[temp];
token[index]='\0';
index++;
flag=2;
output(flag);
forward = forward - 1;
state=0;
}
break;
case 7: ch = Buffer[forward];
if(isdigit(ch))
{
state=7;
token[index]=ch;
index++;
}
else if(ch=='E'||ch=='e'){ /*找到表示指数的E或e*/
state=8;
temp=forward; /*temp用于保存指向E或e的指针*/
}
else{
token[index]='\0';
index++;
flag=1;
output(flag);
state=0;
forward = forward - 1;
}
break;
case 8: ch = Buffer[forward];
/*temp1=q;*/
if(ch=='+'||ch=='-') /*如果E或e后面跟着+或-*/
{
temp1=forward; /*用temp1保存指向+或-的指针*/
state=9;
}
else if(isdigit(ch)){ /*如果E或e后面跟着一个数字*/
state=10;
token[index]=Buffer[temp]; /*将E或e放入token*/
index++;
token[index]=ch; /*将该数字放入token*/
index++;
}
else{ /*如果E或e后面跟着其他字符*/
token[index]='\0'; /*输出前面的数*/
index++;
flag=1;
output(flag);
index=0; /*将E或e放入token,回退字符,转入状态1*/
token[index]=Buffer[temp];
index++;
forward = forward - 1;
state=1; /*转入状态1,判断字符串*/
}
break;
case 9: ch = Buffer[forward];
if(isdigit(ch)) /*若E或e后面的+或-的后面跟一个数字*/
{
token[index]=Buffer[temp]; /*将E或e和+或-放入token*/
index++;
/*printf("\ntemp is %c\n",temp->ch);*/
token[index]=Buffer[temp1];
index++;
/*printf("\ntemp1 is %c\n",temp1->ch);*/
token[index]=ch; /*将该数字放入token*/
index++;
state=10; /*转入状态10*/
}
else{
token[index]='\0'; /*输出前面的数*/
index++;
flag=1;
output(flag);
index=0; /*输出E或e*/
token[index]=Buffer[temp];
index++;
token[index]='\0';
index++;
flag=0;
output(flag);
index=0;
token[index]=Buffer[temp1]; /*将+或-放入token*/
index++;
if(ch=='=') /*判断+=或-=*/
{
token[index]=ch;
index++;
token[index]='\0';
index++;
flag=2;
output(flag);
state=0;
}
else{
token[index]='\0';
index++;
flag=2;
output(flag);
forward = forward - 1;
state=0;
}
}
break;
case 10: ch = Buffer[forward];
if(isdigit(ch))
{
token[index]=ch;
index++;
state=10;
}
else{
token[index]='\0';
index++;
flag=1;
output(flag);
forward = forward - 1;
state=0;
}
break;
case 11: ch = Buffer[forward];
if(ch=='|')
{
token[index]=ch;
index++;
token[index]='\0';
index++;
flag=2;
output(flag);
state = 0;
}
else
{
token[index]='\0';
index++;
flag=1;
output(flag);
forward = forward - 1;
state=0;
}
break;
case 12: ch = Buffer[forward];
if(ch=='&')
{
token[index]=ch;
index++;
token[index]='\0';
index++;
flag=2;
output(flag);
state = 0;
}
else
{
token[index]='\0';
index++;
flag=1;
output(flag);
forward = forward - 1;
state=0;
}
break;
}
}
printf("\nThe end!\nThe number of lines in this source file is %d.\n",lineno);
fprintf(out,"\nThe end!\nThe number of lines in this source file is %d.\n",lineno);
fclose(fp);
}
void print()
{
struct entry *q;
q=headOfEntry;
printf("The followed is symbol list:\n");
while(q->next!=NULL)
{
printf("(%d,%s)\n",q->next->attr,q->next->value);
fprintf(out,"(%d,%s)\n",q->next->attr,q->next->value);
q=q->next;
}
}
main()
{
char *in;
char *outf;
printf("Enter the name of Source file:\n");
scanf("%s",in);
printf("Enter the name of output file:\n");
scanf("%s",outf);
entryinit();
outFile(outf);
analyse(in);
print();
fclose(out);
getch();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -