/usr/share/doc/happy/examples/glr/highly-ambiguous/Expr.y is in happy 1.19.0-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 | {
-- only list imports here
import Char
}
%tokentype { Token }
%lexer { lexer } { TokenEOF }
%token
'b' { Sym _ }
%%
-- grammar taken from
-- "Generalised LR Parsing in Haskell"
-- Joao Fernandes, Joao Saraiva, and Joost Visser
-- Universidade do Minho, Braga, Portugal
-- submitted to AFP'04 summer school
-- (Original source of grammar not identified by them)
S : T {}
T : A 'b' {} | T T T {}
A : T 'b' A A A {} | T T 'b' {} | {}
{
data Token
= TokenEOF
| Sym Char
| AnInt Int
deriving (Show,Eq, Ord)
lexer :: String -> [Token]
lexer [] = []
lexer (' ':cs) = lexer cs
lexer (c:cs) | c `elem` "+*-()"
= Sym c : lexer cs
lexer (c:cs) | isDigit c
= let (yes,no) = span isDigit cs in AnInt (read $ c:yes) : lexer no
}
|