title: Parser Help Program Not Working
body: <p> --> 
   ---> a | b
   ---> 1 | 1 </p>
  
  <p><strong>It's suppose to start will a or b and 1 afterward. it doesn't matter how many 1's are after a or b. for example: a1, b1, b111111, a111
  everything I type in is invalid but this is supposed to be valid:  a1, b1, b111111, a111</strong> </p>
  
  <pre><code>/*
  &lt;S&gt; --&gt; &lt;A&gt;&lt;B&gt;
  &lt;A&gt; ---&gt;  a | b
  &lt;B&gt; ---&gt;  1 | 1 &lt;B&gt;
  
  It suppose to be vaild for example: a1, b1, b111111, a111
  */
  #include &lt;iostream&gt;
  #include&lt;stdlib.h&gt;  // for the exit(1) function
  using namespace std;
  
  char text[100];
  char ToBeChecked;
  
  char lexical(); //identify the characters
  void SProd();
  void AProd();
  void BProd();
  
  
  int main()
  {
      cout&lt;&lt;"Enter a string(max. 100 characters"&lt;&lt;endl;
      cin&gt;&gt;text;
  
      ToBeChecked = lexical(); //identify the character; find the first letter and give it to ToBeChecked
      SProd();
  
      if(ToBeChecked = '\0')
          cout&lt;&lt;"Valid"&lt;&lt;endl;
          else
          cout&lt;&lt;"Invalid"&lt;&lt;endl;
      cin.get();
      return 0;
  }
  
  char lexical()
  {
      static int index = -1;   //a memory box named index with a value of -1; is static so it won't change.
                              //is -1 because -1 to 1 is 0; everytime move on to next one
      index++; //update index
      return text[index]; //return the value of index
  }
  
  //&lt;S&gt; --&gt; &lt;A&gt; &lt;B&gt;
  void SProd()
  {
      AProd();
      BProd();
  }
  
  //&lt;A&gt; ---&gt;  a | b
  void AProd()
  {
     if(ToBeChecked == 'a'){
         ToBeChecked = lexical();
     }
     else
     {
         if(ToBeChecked == 'b'){
             ToBeChecked = lexical();
         }
      }
   }
  
   //&lt;B&gt; ---&gt;  1 | 1 &lt;B&gt;
   void BProd()
   {
       if(ToBeChecked != '1')
       {
           cout&lt;&lt;"Invalid"&lt;&lt;endl;
           exit(1);
       }
       else
           while (ToBeChecked == '1')
               ToBeChecked = lexical();
   }
  </code></pre>