Hello,
Greeting everybody.
I am a beginner of Haskell. I am trying out the happy.
When I compiled the happy grammar file for the ABCParser given at http://www.haskell.org/happy/doc/html/sec-AttributeGrammarExample.html
I did get a Haskell source file.
Then I loaded this file, named "abc.hs" into ghci.
There is a function called "parse" available to us.
GHCi shows its type to be
parse :: [Char] -> [Char]

But no matter whatever input I give to the parse function, it always gives the following error:
"*** Exception: parse error

Here are some sample inputs on the GHCi shell:
*ABCParser> parse "abc"
"*** Exception: parse error
*ABCParser> parse "a"
"*** Exception: parse error
*ABCParser> parse ""
"*** Exception: parse error
*ABCParser> parse "aabbcc"
"*** Exception: parse error

What is the problem?

The happy grammar is here:
{
module ABCParser (parse) where
}

%tokentype { Char }

%token a { 'a' }
%token b { 'b' }
%token c { 'c' }
%token newline { '\n' }

%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) "blist wrong length" 
        }

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

{
happyError = error "parse error"
failUnless b msg = if b then () else error msg
}