title: Defining a left-to-right parser for arithmetic expressions
body: <p>I'm having a hard time defining a left-to-right arithmetic expression parser in Haskell. What I have done so far is defining a right-to-left parser, following the "G. Hutton, Programming in Haskell" book.</p>
  
  <pre><code>-- the aexpr integer parser
  aexpr_int :: Parser Int
  aexpr_int = do
                a1 &lt;- aterm_int
                s &lt;- sign -- return 1 for "+" and -1 for "-"
                a2 &lt;- aexpr_int
                return (a1 + (s * a2))
              &lt;|&gt;
              aterm_int
  
  -- the aterm integer parser
  aterm_int :: Parser Int
  aterm_int = do
                a1 &lt;- aterm_int
                char '*'
                a2 &lt;- afactor_int
                return (a1 * a2);
              &lt;|&gt;
              do
                a1 &lt;- afactor_int
                char '/'
                a2 &lt;- aterm_int
                return (div a1 a2)
              &lt;|&gt;
              afactor_int
  
  -- afactor_int
  afactor_int :: Parser Int
  afactor_int = do
                  token (char '(')
                  e &lt;- aexpr_int
                  token (char ')')
                  return e
                &lt;|&gt; 
                do
                  s &lt;- sign 
                  ic &lt;- aexpr_int 
                  return (s * ic)
                &lt;|&gt;  
                token int_const   
  </code></pre>
  
  <p>So this parses <code>1 - 2 - 3 - 4</code> as <code>1 - (2 - (3 - 4))</code>, but I want it to parse as <code>((1 - 2) - 3) - 4</code>. How can I reach this result?</p>