title: How do I handle newlines in a Bison Grammar, without allowing all characters?
body: <p>I've gone right back to basics to try and understand how the parser can match an input line such as "asdf", or any other jumble of characters, where there is no rule defined for this.</p>
  
  <p>My lexer:</p>
  
  <pre><code>%{
      #include
  %}
  %%
  "\n" {return NEWLINE; }
  </code></pre>
  
  <p>My Parser:</p>
  
  <pre><code>%{
      #include &lt;stdlib.h&gt;
  %}
  % token NEWLINE
  
  %%
  
  program:
  | program line
  ;
  line: NEWLINE
  ;
  
  %%
  
  #include &lt;stdio.h&gt;
  int yyerror(char *s)
  {
      printf("%s\n", s);
      return(0);
  }
  int main(void)
  {
      yyparse();
      exit(0);
  }
  </code></pre>
  
  <p>It is my understanding that this, when compiled and run should accept nothing more than empty blank lines, but it will also allow any strings to be input without a syntax error. </p>
  
  <p>What am I missing?</p>
  
  <p>Thanks</p>