File: precedence001.ly

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 (61 lines) | stat: -rw-r--r-- 1,599 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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
This module demonstrates a Happy bug (in version <= 1.10).

> {
> module Main where
> import System.IO
> import Control.Exception as Exception
> }
> 
> %name parse
> 
> %tokentype { Tok }
> %token
>       '+'  { Plus }
>       '-'  { Minus }
>       int  { Num $$ }
> 
> %nonassoc '+' '-'
> 
> %%

Ambiguos grammar.

> E    : E '+' E  { Plus' $1 $3 }
>      | E '-' E  { Minus' $1 $3 }
>      | int      { Num' $1 }

> {
> happyError :: [Tok] -> a
> happyError s = error (concatMap show s)
> 
> data Tok = Plus | Minus | Num Int deriving Show
> 
> data Syn = Plus' Syn Syn | Minus' Syn Syn | Num' Int deriving Show

All the examples below should fail. None of them does so
under Happy v1.8, and only the first one under Happy v1.9
and v1.10.

> test1 = parse tokens1
> test2 = parse tokens2
> test3 = parse tokens3
> 
> tokens1 = [Num 6, Plus, Num 7, Plus, Num 8]
> tokens2 = [Num 6, Plus, Num 7, Minus, Num 8]
> tokens3 = [Num 6, Minus, Num 7, Minus, Num 8]

The generated info files seem correct, so there is probably
something wrong with the table generation.

These errors only show up when one uses Happy with the -a
flag (and only that flag). I know that it's no point in
using just that flag, but I happened to be doing so while
trying the code out with Hugs. (Hugs didn't like the code
generated with GHC extensions, -gac.)

> main = do
>   Exception.try (print test1 >> fail "Test failed.") :: IO (Either ErrorCall ())
>   Exception.try (print test2 >> fail "Test failed.") :: IO (Either ErrorCall ())
>   Exception.try (print test3 >> fail "Test failed.") :: IO (Either ErrorCall ())

> }