Advertisement
Guest User

Untitled

a guest
May 24th, 2017
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.03 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int c; // текущий анализируемый символ void A ();
  5.  
  6. void A ();
  7. void B ();
  8.  
  9. void gc (){
  10.     cin >> c; // считать очередной символ
  11.     }
  12.  
  13. void S () {
  14.     cout << "S-->ABd, "; // применяемое правило вывода
  15.     A();
  16.     B();
  17.     if ( c != 'd' )
  18.         throw c;
  19.     gc ();
  20. }
  21.  
  22. void A () {
  23.     if ( c =='a' ) {
  24.         cout << "A-->a, ";
  25.         gc ();
  26.     }
  27.     else if ( c =='c' ) {
  28.         cout << "A-->cA, ";
  29.         gc ();
  30.         A ();
  31.     }
  32.     else {
  33.         throw c;
  34.     }
  35. }
  36.  
  37. void B () {
  38.     if ( c =='b' ) {
  39.         cout << "B-->bA, ";
  40.         gc ();
  41.         A ();
  42.     } else {
  43.         throw c;
  44.     }
  45. }
  46.  
  47. int main () {
  48.     try {
  49.         gc ();
  50.        
  51.         S ();
  52.         if ( c != '/' )
  53.             throw c;
  54.         cout << "SUCCESS !!!" << endl;
  55.         return 0;
  56.     }
  57.     catch ( int c ) {
  58.         cout << "ERROR on lexeme " << c << endl;
  59.         return 1; }
  60. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement