4
#define IBOX(n) (I# (n))
6
#define LT(n,m) (n <# m)
7
#define GTE(n,m) (n >=# m)
8
#define EQ(n,m) (n ==# m)
9
#define PLUS(n,m) (n +# m)
10
#define MINUS(n,m) (n -# m)
11
#define TIMES(n,m) (n *# m)
12
#define NEGATE(n) (negateInt# (n))
18
#define LT(n,m) (n < m)
19
#define GTE(n,m) (n >= m)
20
#define EQ(n,m) (n == m)
21
#define PLUS(n,m) (n + m)
22
#define MINUS(n,m) (n - m)
23
#define TIMES(n,m) (n * m)
24
#define NEGATE(n) (negate (n))
28
#if defined(HAPPY_ARRAY)
29
data Happy_IntList = HappyCons FAST_INT Happy_IntList
30
#define CONS(h,t) (HappyCons (h) (t))
32
#define CONS(h,t) ((h):(t))
35
#if defined(HAPPY_ARRAY)
36
#define ERROR_TOK ILIT(0)
37
#define DO_ACTION(state,i,tk,sts,stk) happyDoAction i tk state sts (stk)
38
#define HAPPYSTATE(i) (i)
39
#define GOTO(action) happyGoto
40
#define IF_ARRAYS(x) (x)
42
#define ERROR_TOK ILIT(1)
43
#define DO_ACTION(state,i,tk,sts,stk) state i i tk HAPPYSTATE(state) sts (stk)
44
#define HAPPYSTATE(i) (HappyState (i))
45
#define GOTO(action) action
49
#if defined(HAPPY_COERCE)
50
#define GET_ERROR_TOKEN(x) (case unsafeCoerce# x of { IBOX(i) -> i })
51
#define MK_ERROR_TOKEN(i) (unsafeCoerce# IBOX(i))
52
#define MK_TOKEN(x) (happyInTok (x))
54
#define GET_ERROR_TOKEN(x) (case x of { HappyErrorToken IBOX(i) -> i })
55
#define MK_ERROR_TOKEN(i) (HappyErrorToken IBOX(i))
56
#define MK_TOKEN(x) (HappyTerminal (x))
59
#if defined(HAPPY_DEBUG)
60
#define DEBUG_TRACE(s) (happyTrace (s)) $
61
happyTrace string expr = unsafePerformIO $ do
65
#define DEBUG_TRACE(s) {- nothing -}
69
data HappyStk a = HappyStk a (HappyStk a)
71
-----------------------------------------------------------------------------
73
happyParse start_state = happyNewToken start_state notHappyAtAll notHappyAtAll
75
-----------------------------------------------------------------------------
77
happyAccept ERROR_TOK tk st sts (_ `HappyStk` ans `HappyStk` _) =
79
happyAccept j tk st sts (HappyStk ans _) =
80
IF_GHC(happyTcHack j IF_ARRAYS(happyTcHack st)) (happyReturn1 ans)
82
-----------------------------------------------------------------------------
84
#if defined(HAPPY_ARRAY)
87
= DEBUG_TRACE("state: " ++ show IBOX(st) ++
88
",\ttoken: " ++ show IBOX(i) ++
91
ILIT(0) -> DEBUG_TRACE("fail.\n")
93
ILIT(-1) -> DEBUG_TRACE("accept.\n")
95
n | LT(n,(ILIT(0) :: FAST_INT)) -> DEBUG_TRACE("reduce (rule " ++ show rule
97
(happyReduceArr ! rule) i tk st
98
where rule = IBOX(NEGATE(PLUS(n,(ILIT(1) :: FAST_INT))))
99
n -> DEBUG_TRACE("shift, enter state "
100
++ show IBOX(new_state)
102
happyShift new_state i tk st
103
where new_state = MINUS(n,(ILIT(1) :: FAST_INT))
104
where off = indexShortOffAddr happyActOffsets st
106
check = if GTE(off_i,(ILIT(0) :: FAST_INT))
107
then EQ(indexShortOffAddr happyCheck off_i, i)
109
action | check = indexShortOffAddr happyTable off_i
110
| otherwise = indexShortOffAddr happyDefActions st
113
#undef __GLASGOW_HASKELL__
114
#define HAPPY_IF_GHC_GT_500 #if __GLASGOW_HASKELL__ > 500
115
#define HAPPY_IF_GHC_GE_503 #if __GLASGOW_HASKELL__ >= 503
116
#define HAPPY_ELIF_GHC_500 #elif __GLASGOW_HASKELL__ == 500
117
#define HAPPY_ELSE #else
118
#define HAPPY_ENDIF #endif
122
indexShortOffAddr (HappyA# arr) off =
128
(i `iShiftL#` 16#) `iShiftRA#` 16#
132
i = word2Int# ((high `uncheckedShiftL#` 8#) `or#` low)
134
i = word2Int# ((high `shiftL#` 8#) `or#` low)
136
high = int2Word# (ord# (indexCharOffAddr# arr (off' +# 1#)))
137
low = int2Word# (ord# (indexCharOffAddr# arr off'))
140
indexShortOffAddr arr off = arr ! off
144
data HappyAddr = HappyA# Addr#
147
#endif /* HAPPY_ARRAY */
149
-----------------------------------------------------------------------------
151
#if !defined(HAPPY_ARRAY)
153
newtype HappyState b c = HappyState
154
(FAST_INT -> -- token number
155
FAST_INT -> -- token number (yes, again)
156
b -> -- token semantic value
157
HappyState b c -> -- current state
158
[HappyState b c] -> -- state stack
163
-----------------------------------------------------------------------------
165
happyShift new_state ERROR_TOK tk st sts stk@(x `HappyStk` _) =
166
let i = GET_ERROR_TOKEN(x) in
167
DO_ACTION(new_state,i,tk,CONS(st,sts),stk)
169
happyShift new_state i tk st sts stk =
170
happyNewToken new_state CONS(st,sts) (MK_TOKEN(tk)`HappyStk`stk)
173
happySpecReduce_0 i fn ERROR_TOK tk st sts stk
174
= happyFail ERROR_TOK tk st sts stk
175
happySpecReduce_0 nt fn j tk st@(HAPPYSTATE(action)) sts stk
176
= GOTO(action) nt j tk st CONS(st,sts) (fn `HappyStk` stk)
178
happySpecReduce_1 i fn ERROR_TOK tk st sts stk
179
= happyFail ERROR_TOK tk st sts stk
180
happySpecReduce_1 nt fn j tk _ sts@(CONS(st@HAPPYSTATE(action),_)) (v1`HappyStk`stk')
182
happySeq r (GOTO(action) nt j tk st sts (r `HappyStk` stk'))
184
happySpecReduce_2 i fn ERROR_TOK tk st sts stk
185
= happyFail ERROR_TOK tk st sts stk
186
happySpecReduce_2 nt fn j tk _ CONS(_,sts@(CONS(st@HAPPYSTATE(action),_))) (v1`HappyStk`v2`HappyStk`stk')
187
= let r = fn v1 v2 in
188
happySeq r (GOTO(action) nt j tk st sts (r `HappyStk` stk'))
190
happySpecReduce_3 i fn ERROR_TOK tk st sts stk
191
= happyFail ERROR_TOK tk st sts stk
192
happySpecReduce_3 nt fn j tk _ CONS(_,CONS(_,sts@(CONS(st@HAPPYSTATE(action),_)))) (v1`HappyStk`v2`HappyStk`v3`HappyStk`stk')
193
= let r = fn v1 v2 v3 in
194
happySeq r (GOTO(action) nt j tk st sts (r `HappyStk` stk'))
196
happyReduce k i fn ERROR_TOK tk st sts stk
197
= happyFail ERROR_TOK tk st sts stk
198
happyReduce k nt fn j tk st sts stk
199
= case happyDrop MINUS(k,(ILIT(1) :: FAST_INT)) sts of
200
sts1@(CONS(st1@HAPPYSTATE(action),_)) ->
201
let r = fn stk in -- it doesn't hurt to always seq here...
202
happyDoSeq r (GOTO(action) nt j tk st1 sts1 r)
204
happyMonadReduce k nt fn ERROR_TOK tk st sts stk
205
= happyFail ERROR_TOK tk st sts stk
206
happyMonadReduce k nt fn j tk st sts stk =
207
happyThen1 (fn stk) (\r -> GOTO(action) nt j tk st1 sts1 (r `HappyStk` drop_stk))
208
where sts1@(CONS(st1@HAPPYSTATE(action),_)) = happyDrop k CONS(st,sts)
209
drop_stk = happyDropStk k stk
211
happyDrop ILIT(0) l = l
212
happyDrop n CONS(_,t) = happyDrop MINUS(n,(ILIT(1) :: FAST_INT)) t
214
happyDropStk ILIT(0) l = l
215
happyDropStk n (x `HappyStk` xs) = happyDropStk MINUS(n,(ILIT(1)::FAST_INT)) xs
217
-----------------------------------------------------------------------------
219
#if defined(HAPPY_ARRAY)
220
happyGoto nt j tk st =
221
DEBUG_TRACE(", goto state " ++ show IBOX(new_state) ++ "\n")
222
happyDoAction j tk new_state
223
where off = indexShortOffAddr happyGotoOffsets st
225
new_state = indexShortOffAddr happyTable off_i
227
happyGoto action j tk st = action j j tk (HappyState action)
230
-----------------------------------------------------------------------------
232
happyFail ERROR_TOK tk old_st _ stk =
236
{- We don't need state discarding for our restricted implementation of
237
"error". In fact, it can cause some bogus parses, so I've disabled it
240
happyFail ERROR_TOK tk old_st CONS(HAPPYSTATE(action),sts)
241
(saved_tok `HappyStk` _ `HappyStk` stk) =
242
-- trace ("discarding state, depth " ++ show (length stk)) $
243
DO_ACTION(action,ERROR_TOK,tk,sts,(saved_tok`HappyStk`stk))
246
happyFail i tk HAPPYSTATE(action) sts stk =
247
DO_ACTION(action,ERROR_TOK,tk,sts, MK_ERROR_TOKEN(i) `HappyStk` stk)
250
notHappyAtAll = error "Internal Happy error\n"
252
-----------------------------------------------------------------------------
254
#if defined(HAPPY_GHC)
255
happyTcHack :: Int# -> a -> a
257
{-# INLINE happyTcHack #-}
260
-----------------------------------------------------------------------------
261
-- happySeq = happyDoSeq
263
happyDoSeq, happyDontSeq :: a -> b -> b
264
happyDoSeq a b = a `seq` b
267
-----------------------------------------------------------------------------
269
#if defined(HAPPY_ARRAY)
270
{-# NOINLINE happyDoAction #-}
271
{-# NOINLINE happyTable #-}
272
{-# NOINLINE happyCheck #-}
273
{-# NOINLINE happyActOffsets #-}
274
{-# NOINLINE happyGotoOffsets #-}
275
{-# NOINLINE happyDefActions #-}
277
{-# NOINLINE happyShift #-}
278
{-# NOINLINE happySpecReduce_0 #-}
279
{-# NOINLINE happySpecReduce_1 #-}
280
{-# NOINLINE happySpecReduce_2 #-}
281
{-# NOINLINE happySpecReduce_3 #-}
282
{-# NOINLINE happyReduce #-}
283
{-# NOINLINE happyMonadReduce #-}
284
{-# NOINLINE happyGoto #-}
285
{-# NOINLINE happyFail #-}