1 -- This module demonstrates a bug in the original 1.11 release of Happy. 2 3 { 4 module Main where 5 import System.IO 6 import Control.Exception as Exception 7 } 8 9 %name parse 10 11 %tokentype { Tok } 12 %token 13 '+' { Plus } 14 '/' { Divide } 15 int { Num $$ } 16 17 %left '+' 18 %left '*' 19 %nonassoc '/' 20 21 %% 22 E : E '+' E { Plus' $1 $3 } 23 | E '/' E { Divide' $1 $3 } 24 | int { Num' $1 } 25 26 { 27 happyError :: [Tok] -> a 28 happyError s = error (concatMap show s) 29 30 data Tok = Plus | Divide | Num Int deriving Show 31 32 data Syn = Plus' Syn Syn | Divide' Syn Syn | Num' Int deriving Show 33 34 -- due to a bug in conflict resolution, this caused a parse error: 35 tokens1 = [Num 6, Divide, Num 7, Plus, Num 8] 36 37 main = print (parse tokens1) 38 } 39