title: Why yacc can not parse a second line of a grammar rule even when it parses correctly the first one?
body: <p>I want to parse lines as this one:</p>
  <pre><code>20191201 170003296,1.102290,1.102470,0
  </code></pre>
  <p>To do so, I have written the following basic yacc/lex grammar/lexer:</p>
  <p><strong>grammar.y</strong>:</p>
  <pre><code>%{
  
  #include &lt;time.h&gt;
  #include &lt;stdio.h&gt;
  
  %}
  
  %union {
  
          struct tm       datetime;               /* DATE TIME VALUES */
          double          float_number;           /* 8 BYTES DOUBLE VALUE */
          long            integer_number;         /* 8 BYTES INTEGER VALUE */
  
  }
  
  %token  &lt;datetime&gt;              DATETIME
  %token  &lt;float_number&gt;          FLOAT_NUMBER
  %token  &lt;integer_number&gt;        INTEGER_NUMBER
  
  %%
  
  lastbid_lastask:        DATETIME ',' FLOAT_NUMBER ',' FLOAT_NUMBER ',' INTEGER_NUMBER '\n' { printf(&quot;MATCH %lf %lf %ld\n&quot;, $3, $5, $7); }
                          ;
  
  %%
  
  int main(int argc, char *argv[]) {
  
          yyparse();
  
          return 0;
  
  }
  </code></pre>
  <p><strong>lexer.l</strong>:</p>
  <pre><code>%{
  
  #include &lt;time.h&gt;
  #include &quot;grammar.h&quot;
  
  void read_float_number(void);
  void read_integer_number(void);
  void read_date_YYYYMMDD_HHMMSSmmm(void);
  void yyerror(const char* msg);
  
  %}
  
  
  %%
  
                                                                                                  /* YYYYMMDD HHMMSSmmm DATE */
  [12][09][0-9][0-9][0-1][0-9][0-3][0-9][ ][0-2][0-9][0-5][0-9][0-5][0-9][0-9][0-9][0-9]          { read_date_YYYYMMDD_HHMMSSmmm(); return DATETIME; }
  
                                                                                                  /* FLOAT NUMBER */
  [0-9]+\.[0-9]+                                                                                  { read_float_number(); return FLOAT_NUMBER; }
  
                                                                                                  /* INTEGER NUMBER */
  [0-9]+                                                                                          { read_integer_number(); return INTEGER_NUMBER; }
  
                                                                                                  /* PASS ',' CHARACTER */
  ,                                                                                               { return ','; } 
  
                                                                                                  /* PASS '\n' CHARACTER */
  \n                                                                                              { return '\n'; } 
  
                                                                                                  /* PASS UNEXPECTED CHARACTER */
  .                                                                                               { return yytext[0]; }
  
  
  %%
  
  /* READ FLOAT NUMBER */
  void read_float_number(void) {
          printf(&quot;void read_float_number(void)\n&quot;);
          printf(&quot;#%s#\n&quot;, yytext);
          sscanf(yytext, &quot;%lf&quot;, &amp;yylval.float_number);
          printf(&quot;%lf\n&quot;, yylval.float_number);
  }
  
  /* READ INTEGER NUMBER */
  void read_integer_number(void) {
          printf(&quot;void read_integer_number(void)\n&quot;);
          printf(&quot;#%s#\n&quot;, yytext);
          sscanf(yytext, &quot;%ld&quot;, &amp;yylval.integer_number);
          printf(&quot;%ld\n&quot;, yylval.integer_number);
  }
  
  /* READ YYYYMMDD HHMMSSmmm DATE */
  void read_date_YYYYMMDD_HHMMSSmmm(void) {
  
          printf(&quot;void read_date_YYYYMMDD_HHMMSSmmm(void)\n&quot;);
          printf(&quot;#%s#\n&quot;, yytext);
  
          /*  DATETIME STRUCT TM */
          struct tm dt;
  
          /* READ VALUES */
          sscanf(yytext, &quot;%4d%2d%2d %2d%2d%2d&quot;, &amp;dt.tm_year, &amp;dt.tm_mon, &amp;dt.tm_mday, &amp;dt.tm_hour, &amp;dt.tm_min, &amp;dt.tm_sec);
  
          /* NORMALIZE VALUES */
          dt.tm_year = dt.tm_year - 1900;         /* NORMALIZE YEAR */
          dt.tm_mon = dt.tm_mon - 1;              /* NORMALIZE MONTH */
          dt.tm_isdst = -1;                       /* NO INFORMATION ABOUT DST */
          mktime(&amp;dt);                            /* NORMALIZE STRUCT TM */
  
          /* PRINT DATE TIME */
          char buffer[80];
          strftime(buffer, 80, &quot;%c %Z&quot;, &amp;dt);
          printf(&quot;%s\n&quot;, buffer);
  
          /* COPY STRUCT TM TO YACC RETURN VALUE */
          memcpy(&amp;yylval.datetime, &amp;dt, sizeof(dt));
  
  
  }
  
  /* YYERROR */
  void yyerror(const char* msg) {
          fprintf(stderr, &quot;yyerror %s\n&quot;, msg);
          exit(1);
  }
  </code></pre>
  <p><strong>makefile</strong>:</p>
  <pre><code>CCFLAGS = -std=c89 -c
  YFLAGS = -d     # Forces generation of y.tab.h
  OBJS = lexer.o grammar.o
  TARGET = readfile
  
  readfile:               $(OBJS)
                          cc $(OBJS) -std=c89 -ll -o $(TARGET)
  
  grammar.h grammar.o:    grammar.y
                          yacc $(YFLAGS) -ogrammar.c grammar.y
                          cc $(CCFLAGS) grammar.c
  
  lexer.o:                lexer.l grammar.h
                          lex -olexer.c lexer.l
                          cc $(CCFLAGS) lexer.c
  
  clean:
                          rm -f $(OBJS) grammar.[ch] lexer.c
  </code></pre>
  <p>When I test the program I get the following behaviour, first line is correctly parsed but second line causes an yyerror:</p>
  <pre><code>% ./readfile 
  20191201 170003296,1.102290,1.102470,0
  void read_date_YYYYMMDD_HHMMSSmmm(void)
  #20191201 170003296#
  Sun Dec  1 17:00:03 2019 CET
  void read_float_number(void)
  #1.102290#
  1.102290
  void read_float_number(void)
  #1.102470#
  1.102470
  void read_integer_number(void)
  #0#
  0
  MATCH 1.102290 1.102470 0
  20191201 170004413,1.102320,1.102470,0
  void read_date_YYYYMMDD_HHMMSSmmm(void)
  #20191201 170004413#
  Sun Dec  1 17:00:04 2019 CET
  yyerror syntax error
  </code></pre>
  <p><strong>Why does second line fail?</strong></p>