分析器有个问题一直无法解决,分析完会出现27和28。
#include<stdio.h>
#include<stdlib.h>
void main()
{
int i;
char s[100];
printf("请输入字符串:");
scanf("%s",&s);
for(i=0;i<100;i++)
{
if(s[i]=='b'&&s[i+1]=='e'&&s[i+2]=='g'&&s[i+3]=='i'&&s[i+4]=='n')
printf("1 , begin
");
else if(s[i]=='i'&&s[i+1]=='f')
printf("2 , if
");
else if(s[i]=='t'&&s[i+1]=='h'&&s[i+2]=='e'&&s[i+3]=='n')
printf("3 , then
");
else if(s[i]=='w'&&s[i+1]=='h'&&s[i+2]=='i'&&s[i+3]=='l'&&s[i+4]=='e')
printf("4 , while
");
else if(s[i]=='d'&&s[i+1]=='o')
printf("5 , do
");
else if(s[i]=='e'&&s[i+1]=='n'&&s[i+2]=='d')
printf("6 , end
");
else if(s[i]=='l'&&s[i+1]=='('&&s[i+2]=='l'&&s[i+3]=='|'&&s[i+3]=='d'&&s[i+3]==')'&&s[i+4]=='*')
printf("10 , l(l|d)*
");
else if(s[i]=='d'&&s[i+1]=='d'&&s[i+2]=='*')
printf("11 , dd*
");
else if(s[i]=='-')
printf("14 , -
");
else if(s[i]=='*')
printf("15 , *
");
else if(s[i]=='/')
printf("16 , /
");
else if(s[i]==':'&&s[i+1]!='=')
printf("17 , :
");
else if(s[i]==':'&&s[i+1]=='=')
printf("18 , :=
");
else if(s[i]=='<'&&s[i+1]!='='&&s[i+1]!='>')
printf("20 , <
");
else if(s[i]=='<'&&s[i+1]=='=')
printf("21 , <=
");
else if(s[i]=='<'&&s[i+1]=='>')
printf("22 , <>
");
else if(s[i]=='>'&&s[i+1]!='=')
printf("23 , >
");
else if(s[i]=='>'&&s[i+1]=='=')
printf("24 , >=
");
else if(s[i]=='=')
printf("25 , =
");
else if(s[i]==';')
printf("26 , ;
");
else if(s[i]=='(')
printf("27 , (
");
else if(s[i]==')')
printf("28 , )
");
else if(s[i]=='#')
printf("0 , #
");
}
}