title: Parse a string by Lexing.from_string
body: <p>I have implemented <a href="http://caml.inria.fr/pub/docs/manual-ocaml/manual026.html#toc110" rel="nofollow">this example</a>, and it works well.</p>
  
  <p>Now, I want to read from a string instead of reading from <code>stdin</code>, so I change the <code>calc.ml</code>:</p>
  
  <pre><code>let _ =
    try
      let lexbuf = Lexing.from_string "1+3" in
      let result = Parser.main Lexer.token lexbuf in
      print_int result
    with Lexer.Eof -&gt;
      print_string "Lexer.Eof";
      exit 0
  </code></pre>
  
  <p>And oddly, it returns <code>Lexer.Eof</code> as result. If I remove <code>| eof { raise Eof }</code> from <code>lexer.mll</code> and , it tells <code>Fatal error: exception Failure("lexing: empty token")</code>. I guess something is wrong around <code>end-of-input</code> condition... Does anyone know how to change the lexer so that it could lex a string?</p>