title: YACC&LEX, Getting syntax error at the end of line and can't figure out why
body: <p>I'm trying to build my compile in lex and yacc for my work
  I try for a long time but still get a syntax error in output
  this is my yacc</p>
  <pre><code>%token &lt;ival&gt; DIGIT
  %token LOAD
  %token ADD
  %token MOD
  %token SUB
  %token MUL
  %token INC
  %token DEC
  %token WS
  %token EOL
  
  %%
  line :LOAD WS DIGIT EOL{ printf(&quot;load_cmd :%d\n&quot;,$3);  }
       | ADD EOL{ printf(&quot;add!\n&quot;);  }
       | MOD EOL{ printf(&quot;mod!\n&quot;);  }
       | SUB EOL{ printf(&quot;sub!\n&quot;);  }
       | MUL EOL{ printf(&quot;mul!\n&quot;);  }
       | INC EOL{ printf(&quot;inc!\n&quot;);  }
       | DEC EOL{ printf(&quot;dec!\n&quot;);  }
       ;
  
  
  %%
  </code></pre>
  <p>this is lex:</p>
  <pre><code>load [l][o][a][d]
  add [a][d][d]
  sub [s][u][b]
  mul [m][u][l]
  mod [m][o][d]
  
  inc [i][n][c]
  dec [d][e][c]
  
  digit [0-9]+
  
  
  character [a-zA-Z]
  
  
  
  
  eol [\n\r]
  
  %%
  
  {eol} {return(EOL);}
  [\t]+        {return(WS);}
  [ ]+        {return(WS);}
  {digit}       {yylval.ival = atoi(yytext);return(DIGIT);}
  {load}  { return(LOAD); }
  {add}  { return(ADD); }
  {sub}  { return(SUB); }
  {mul}  { return(MUL); }
  {mod}  { return(MOD); }
  {inc}  { return(INC); }
  {dec}  { return(DEC); }
  
  
  .            {return(yytext[0]);}
  %%
  </code></pre>
  <p>the input is :</p>
  <pre><code>load 1
  load 2
  sub
  load 5
  mod
  </code></pre>
  <p>and the out put is</p>
  <pre><code>load_cmd :1
  syntax error
  </code></pre>
  <p>I have already define EOF， but still get a syntax error at end of line, why ?
  I cannot figure out why I am getting these results.</p>
  <p>there a only one line of output &quot;load_cmd :1&quot;, so it may be a EOF problem? or not?</p>