title: Unified parser + predictive input with yacc
body: <p>I'm going to write a parser for a small language, which will have a built-in editor, and I'm wondering if it's possible to use yacc/lex both for the parser and for adding predictive input capabilities to the editor.</p>
  <p>Right now, I know how to create the yacc/lex files for parsing the language.</p>
  <p>But, for example, I want that if the user is using the built-in editor, and is creating a program like this:</p>
  <pre><code>LET A = 10
  INPUT B
  LET A = A + B
  IF A &lt; 100 THEN &lt;current cursor position&gt;
  </code></pre>
  <p>Now, I want the user to be able to ask the editor what syntax is supported at the current cursor position. The reply from the editor could be either allowed productions from the language grammar, or possible tokens, etc... it's not that important at this point what's the format for that hint to the user.</p>
  <p>Both the parser and the predictive syntax capability need to know the grammar, so, ideally, I'd prefer to avoid having to define the grammar twice (one for yacc, another for the predictive syntax feature).</p>
  <p>Can I use yacc for both things? Or maybe can I define the grammar using some format that can be used by both yacc and by the predictive syntax code?</p>
  <p>As a brute-force alternative, I'm thinking in the possibility of just invoking the parser on every key press, and just show the error message when the user hovers the mouse over detected errors. This is not predictive syntax, but almost, because the shown error could be &quot;expected a statement&quot;.</p>