File: precedence002.y

package info (click to toggle)
happy 1.18.9-1
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 1,024 kB
  • sloc: haskell: 6,327; xml: 3,388; yacc: 809; makefile: 263
file content (38 lines) | stat: -rw-r--r-- 721 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
-- This module demonstrates a bug in the original 1.11 release of Happy.

{
module Main where
import System.IO
import Control.Exception as Exception
}

%name parse

%tokentype { Tok }
%token
      '+'  { Plus }
      '/'  { Divide }
      int  { Num $$ }

%left '+'
%left '*'
%nonassoc '/'

%%
E    : E '+' E  { Plus' $1 $3 }
     | E '/' E  { Divide' $1 $3 }
     | int      { Num' $1 }

{
happyError :: [Tok] -> a
happyError s = error (concatMap show s)

data Tok = Plus | Divide | Num Int deriving Show

data Syn = Plus' Syn Syn | Divide' Syn Syn | Num' Int deriving Show

-- due to a bug in conflict resolution, this caused a parse error:
tokens1 = [Num 6, Divide, Num 7, Plus, Num 8]

main = print (parse tokens1)
}