title: How to read multiple lines of input in lex and yacc?
body: <p>I want the output as:</p>
  <pre><code>a=3   mov a,3
  a=fs  mov b,fs
  b=32  mov b,32
  </code></pre>
  <p>Program for 3 address intermediate code generation -
  the lex file written for lexical analysis reads the input from command line and passes tokens:</p>
  <pre><code>%{
  #include &quot;y.tab.h&quot;
  #include &quot;string.h&quot;
  #include &lt;math.h&gt;
  %}
  %%
  [a-zA-Z]+ { yylval.var=(char *)malloc(sizeof(char *));
            strcpy(yylval.var,yytext);
           return ID;}
  &quot;=&quot;       return EQUALS;
  [0-9]+    {yylval.num=atoi(yytext);return DIGIT;}
  
  
  %%
  </code></pre>
  <p>The corresponding yacc file:</p>
  <pre><code>%{
  
  #include &quot;stdio.h&quot;
  
  #include &quot;string.h&quot;
  
  int yywrap()
  {
  return 1;
  }
  %}
  
  
  %union
  {char *var;
   int num;
  }
  
  
  %token &lt;var&gt; ID 
  %token &lt;num&gt; EQUALS DIGIT
  
  
  
  
  %%
  start : line 
  
  line : ID EQUALS DIGIT {printf(&quot;MOV %s, %d\n&quot;,$1, $3);}
       | ID EQUALS ID    {printf(&quot;MOV %s, %s\n&quot;,$1, $3);}
       ;
  
  
  %%
  
  main()
  
  {
  
  yyparse();
  
  return 0;
  
  }
  
  int yyerror(char *s)
  
  {
  fprintf(stderr,&quot;%s\n&quot;,s);
  
  }
  </code></pre>
  <p>The output of running the above code (after linking between lex and yacc):</p>
  <pre><code>dsa=32                
  MOV dsa, 32                // 3 address code generated
  
  ds=342                     // but does not parse this line why??
  syntax error
  </code></pre>
  <p>How do I get the output in the desired format?</p>