1#include <stdio.h>2#include <string.h>3 Charstr[Ten];4 intindex=0;5 voidE ();//e->tx;6 voidX ();//x->+tx|-tx| e7 voidT ();//T->fy8 voidY ();//y->*fy |/fy| e9 voidF ();//f-> (E) | IDTen intID ();//ID One intMain () A { - intLen; - intm; the -printf"Please enter an arithmetic expression:"); -scanf"%s", str); -len=strlen (str); +str[len]='#'; -str[len+1]=' /'; + E (); Aprintf"Correct Statement! \ n"); atstrcpy (str,""); -index=0; - - return 0; - } - voidE () in { - T (); to X (); + } - voidX () the { * if(str[index]=='+') $ {Panax Notoginsengindex++; - T (); the X (); + } A Else if(str[index]=='-') the { +index++; - T (); $ X (); $ } - } - voidT () the { - F ();Wuyi Y (); the } - voidY () Wu { - if(str[index]=='*') About { $index++; - F (); - Y (); - } A Else if(str[index]=='/') + { theindex++; - F (); $ Y (); the } the } the voidF () the { - if(ID ()) in { theindex++; the } About Else if(str[index]=='(') the { theindex++; the E (); + if(str[index]==')') - { theindex++; Bayi}Else{ theprintf"\ nthe parse failed!\n"); theExit (0); - } - } the Else{ theprintf"Analysis Failure!\n"); theExit0); the } - } the intID () the { the if(str[index]>='0'&&str[index]<='9')94 { the while(str[index+1]>='0'&&str[index+1]<='9' ) the { theindex++;98 } About if(str[index+1]>='a'&&str[index+1]<='Z' ) - return 0;101 102 return 1;103 }104 Else if(str[index]>='a'&&str[index]<='Z' ) the {106 return 1;107 }108 Else 109 return 0; the 111}
12.30 Recursive descent analysis