1 #include <stdio.h> 2 #include <string.h> 3 char prog[80], token[8]; 4 char ch; 5 int syn, p, m, n, sum, k=0; 6 char *rwtab[6]={"begin", "if", "then", "while", "do", "end"}; 7 void scaner(); 8 void E(); 9 void Y(); 10 void T(); 11 void B(); 12 void C(); 13 void A(); 14 void main() 15 { 16 17 18 p=0; 19 printf("请输入表达式:"); 20 do 21 { 22 scanf("%c", &ch); 23 prog[p++]=ch; 24 }while(ch!='#'); 25 p=0; 26 scaner(); 27 E(); 28 } 29 void scaner() 30 { 31 for(n=0; n<8; n++) 32 token[n]=NULL; 33 ch=prog[p++]; 34 while(ch==' '||ch==' ') ch=prog[p++]; 35 m=0; 36 if((ch>='A'&&ch<='Z') || (ch>='a'&&ch<='z')) 37 { 38 while((ch>='A'&&ch<='Z') || (ch>='a'&&ch<='z')||(ch>='0'&&ch<='9')) 39 { 40 token[m++]=ch; 41 ch=prog[p++]; // 将prog数组的字母复制到ch数组中 42 } 43 token[m++]='