12.30 Recursive descent analysis

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.