title: Parsec: Predictive parsing
body: <p>I have only a few skills with haskell and I need help how to implement predictive parsing (LL*) with parsec.</p>
  
  <p>I have context free grammar:</p>
  
  <pre><code>&lt;a&gt; ::= identifier | identifier '(' &lt;args&gt; ')'
  </code></pre>
  
  <p>Based on <a href="http://research.microsoft.com/en-us/um/people/daan/download/parsec/parsec.pdf" rel="nofollow">http://research.microsoft.com/en-us/um/people/daan/download/parsec/parsec.pdf</a> (chapter predictive parsers) I wrote this code:</p>
  
  <pre><code>term =  do{ x &lt;- m_identifier
      ; try( char '(' )
      ; b &lt;- argsparser
      ; char ')'
      ; return (FncCall x b)
      }
  &lt;|&gt; do { x &lt;- m_identifier
      ; return (VarId x)
      }
  </code></pre>
  
  <p>I expected that this code try to match '(' and if not parser will continue and match only identifier. This code works only for matching identifier '(' args ')'.</p>
  
  <p>With calling it only on identifier "a" it throws:</p>
  
  <pre><code>parse error at (line 1, column 2):
  unexpected end of input
  expecting letter or digit or "("
  </code></pre>