Advertisement
Guest User

Untitled

a guest
Jun 25th, 2018
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.33 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. char *x = "";
  4.  
  5. int parse();
  6. int convert();
  7. int calc();
  8. int uInt();
  9. int equalSign();
  10. int sign();
  11. int term();
  12.  
  13. int main()
  14. {
  15.     if(parse())
  16.     {
  17.         std::cout << "successful";
  18.     }
  19.     else
  20.         std::cout << "unsuccessful";
  21. }
  22. int parse()
  23. {
  24.     if(uInt())
  25.     {
  26.         if(sign())
  27.         {
  28.             if(uInt())
  29.             {
  30.                 if(equalSign())
  31.                 {
  32.                     return 1;
  33.                 }
  34.                 else{
  35.                     std::cout << "Equal sign expected\n";
  36.                     return 0;
  37.                     }
  38.             }
  39.             else
  40.             {
  41.                 std::cout << "Expected digit\n";
  42.                 return 0;
  43.             }
  44.         }
  45.         else
  46.         {
  47.             std::cout << "Operation sign expected\n";
  48.             return 0;
  49.         }
  50.     }
  51.     else
  52.     {
  53.         std::cout << "Expected digit\n";
  54.         return 0;
  55.     }
  56. }
  57.  
  58.  
  59. int uInt()
  60. {
  61.     if(*x>='0' && *x<='9')
  62.     {
  63.         x++;
  64.         uInt();
  65.         return 1;
  66.     }
  67. }
  68.  
  69. int sign()
  70. {
  71.     if(*x=='+' || *x=='/' || *x=='*' ||*x=='-')
  72.     {
  73.         x++;
  74.         return 1;
  75.     }
  76.     else
  77.     {
  78.  
  79.         return 0;
  80.     }
  81. }
  82.  
  83. int equalSign()
  84. {
  85.     if (*x == '=')
  86.     {
  87.         return 1;
  88.     }
  89.     else
  90.         return 0;
  91. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement