title: Bison Multi-line Grammar
body: <p>Using the following <code>flex</code> and <code>bison</code> code, I can print the text <code>hello</code> when the command <code>print "Hello"</code> is inputted:</p>
  
  <p><code>flex file:</code></p>
  
  <pre><code>%{
  #include &lt;iostream&gt;
  using namespace std;
  #define YY_DECL extern "C" int yylex()
  #include "gbison.tab.h"
  %}
  %%
  [ \t\n]            ;
  [a-zA-Z0-9]+       { yylval.sval = strdup(yytext); return STRING; }
  \"(\\.|[^"])*\"    { yylval.sval = strdup(yytext); return QUOTED_STRING; }
  %%
  </code></pre>
  
  <p><code>bison file:</code></p>
  
  <pre><code>%{
  #include &lt;cstdio&gt; 
  #include &lt;cstring&gt;
  #include &lt;iostream&gt;
  using namespace std;
  
  extern "C" int yylex();
  extern "C" int yyparse();
  extern "C" FILE* yyin;
  
  void yyerror (const char* s);
  %}
  
  %union {
    char* sval;
  }
  
  %token &lt;sval&gt; STRING
  %token &lt;sval&gt; QUOTED_STRING
  %%
  
  str:
      STRING QUOTED_STRING
      {
         if (strcmp($1, "print") == 0)
         {
             cout &lt;&lt; $2 &lt;&lt; flush;
         }
         if (strcmp($1, "println") == 0)
         {
             cout &lt;&lt; $3 &lt;&lt; endl; 
         }
      }
      ;
  %%
  
  main(int argc, char* argv[])
  {
     FILE* input = fopen(argv[1], "r");
     if (!input)
     {
        cout &lt;&lt; "Bad input. Nonexistant file" &lt;&lt; endl; 
        return -1;
     } 
  
     yyin = input;
  
     do 
     {
         yyparse();
     } while (!feof(yyin));
  
  }
  void yyerror(const char* s)
  {
     cout &lt;&lt; "Error. " &lt;&lt; s &lt;&lt; endl; 
     exit(-1);   
  }
  </code></pre>
  
  <p>How would I change the <code>Bison grammar</code> so that it would not have a <em>syntax error</em> if there is more than one print or println command?</p>