Hello,<br>Greeting everybody.<br>I am a beginner of Haskell. I am trying out the happy.<br>When I compiled the happy grammar file for the ABCParser given at <a href="http://www.haskell.org/happy/doc/html/sec-AttributeGrammarExample.html">http://www.haskell.org/happy/doc/html/sec-AttributeGrammarExample.html</a><br>
I did get a Haskell source file.<br>Then I loaded this file, named &quot;abc.hs&quot; into ghci.<br>There is a function called &quot;parse&quot; available to us.<br>GHCi shows its type to be <br><span style="font-family:courier new,monospace">parse :: [Char] -&gt; [Char]</span><br>
<br>But no matter whatever input I give to the parse function, it always gives the following error:<br><span style="font-family:courier new,monospace">&quot;*** Exception: parse error</span><br><br>Here are some sample inputs on the GHCi shell:<br>
<span style="font-family:courier new,monospace">*ABCParser&gt; parse &quot;abc&quot;</span><br style="font-family:courier new,monospace"><span style="font-family:courier new,monospace">&quot;*** Exception: parse error</span><br style="font-family:courier new,monospace">
<span style="font-family:courier new,monospace">*ABCParser&gt; parse &quot;a&quot;</span><br style="font-family:courier new,monospace"><span style="font-family:courier new,monospace">&quot;*** Exception: parse error</span><br style="font-family:courier new,monospace">
<span style="font-family:courier new,monospace">*ABCParser&gt; parse &quot;&quot;</span><br style="font-family:courier new,monospace"><span style="font-family:courier new,monospace">&quot;*** Exception: parse error</span><br style="font-family:courier new,monospace">
<span style="font-family:courier new,monospace">*ABCParser&gt; parse &quot;aabbcc&quot;</span><br style="font-family:courier new,monospace"><span style="font-family:courier new,monospace">&quot;*** Exception: parse error</span><br style="font-family:courier new,monospace">
<br>What is the problem?<br><br>The happy grammar is here:<br><pre class="programlisting">{
module ABCParser (parse) where
}

%tokentype { Char }

%token a { &#39;a&#39; }
%token b { &#39;b&#39; }
%token c { &#39;c&#39; }
%token newline { &#39;\n&#39; }

%attributetype { Attrs a }
%attribute value { a }
%attribute len   { Int }

%name parse abcstring

%%

abcstring 
   : alist blist clist newline
        { $$ = $1 ++ $2 ++ $3
        ; $2.len = $1.len
        ; $3.len = $1.len
        }

alist 
   : a alist 
        { $$ = $1 : $2
        ; $$.len = $2.len + 1
        }
   |    { $$ = []; $$.len = 0 }

blist 
   : b blist
        { $$ = $1 : $2
        ; $2.len = $$.len - 1
        }
   |    { $$ = []
        ; where failUnless ($$.len == 0) &quot;blist wrong length&quot; 
        }

clist
   : c clist
        { $$ = $1 : $2
        ; $2.len = $$.len - 1
        }
   |    { $$ = []
        ; where failUnless ($$.len == 0) &quot;clist wrong length&quot; 
        }

{
happyError = error &quot;parse error&quot;
failUnless b msg = if b then () else error msg
}</pre><br>