#include#include char str[10]; //记录要分析的字符串int x=0; //记录第一个字符void E(); void X(); void T(); void Y(); void F(); int main(){ int len; printf("请输入算数表达式:"); scanf("%s",str); len=strlen(str); str[len]='#'; str[len+1]='\0'; E(); printf("\n是正确的表达式!"); strcpy(str,""); x=0; return 0;}void E(){ T(); X();}void X(){ if(str[x]=='+'||str[x]=='-') { x++; T(); X(); } }void T(){ F(); Y();}void Y(){ if(str[x]=='*'||str[x]=='/') { x++; F(); Y(); }}void F(){ if(str[x]>='a'&&str[x]<='z') { x++; } else if(str[x]>=0&&str[x]<=9) { x++; } else if (str[x]=='(') { x++; E(); if(str[x]==')') { x++; } else { printf("\n有语法错误!"); exit(0); } } else { printf("\n有语法错误!"); exit(0); } }