|
Note that "not special" matches every token except the special curly
braces "%{" and "}%".
Declaration.
|
Terminal declaration.
|
Nonterminal declaration.
|
Fixity declaration.
|
Type signature.
|
Productions.
|
Nonterminal symbols (expr0 is a variant of expr lacking the embedded Haskell production).
|
Terminal symbols.
|
Embedded Haskell (types, patterns, and expressions).
|
Note that "not brace" matches every token except the curly braces
"{" and "}".
|
Arity one.
|
|
Arity one.
|
|
Arity one.
|
TODO: also versions where sep has arity one.
|
Arity one.
|
> module Paren where > import Result > > {- frown :-( -} > > data Stack = Empty | T_1 State Stack > > data State = S_1 | S_2 | S_3 | S_4 | S_5 | S_6 > > data Nonterminal = Paren > > paren tr = parse_1 tr Empty >>= (\ Paren -> return ()) > > parse_1 ts st = reduce_2 ts S_1 st > > parse_2 tr@[] st = parse_3 tr (T_1 S_2 st) > parse_2 ('(' : tr) st = parse_5 tr (T_1 S_2 st) > parse_2 ts st = frown ts > > parse_3 ts st = reduce_1 ts st > > parse_4 ('(' : tr) st = parse_5 tr (T_1 S_4 st) > parse_4 (')' : tr) st = parse_6 tr (T_1 S_4 st) > parse_4 ts st = frown ts > > parse_5 ts st = reduce_2 ts S_5 st > > parse_6 ts st = reduce_3 ts st > > reduce_1 ts (T_1 _ (T_1 s st)) = return Paren > > reduce_2 ts s st = goto_5 s ts (T_1 s st) > > reduce_3 ts (T_1 _ (T_1 _ (T_1 _ (T_1 s st)))) > = goto_5 s ts (T_1 s st) > > goto_5 S_1 = parse_2 > goto_5 S_5 = parse_4 > > {- )-: frown -} > > frown _ = fail "syntax error"
> module Paren where > import Result > > {- frown :-( -} > > paren tr = state_1 (\ _ -> return ()) tr > > state_1 k_1_0 ts = let { goto_paren = state_2 k_1_0 (reduce_3 goto_paren) } > in reduce_2 goto_paren ts > > state_2 k_1_1 k_3_1 ts = case ts of { tr@[] -> state_3 k_1_1 tr; > '(' : tr -> state_5 k_3_1 tr; > _ -> frown ts } > > state_3 k_1_2 ts = k_1_2 ts > > state_4 k_3_1 k_3_3 ts = case ts of { '(' : tr -> state_5 k_3_1 tr; > ')' : tr -> state_6 k_3_3 tr; > _ -> frown ts } > > state_5 k_3_2 ts = let { goto_paren = state_4 (reduce_3 goto_paren) k_3_2 } > in reduce_2 goto_paren ts > > state_6 k_3_4 ts = k_3_4 ts > > reduce_2 g ts = g ts > > reduce_3 g ts = g ts > > {- )-: frown -} > > frown _ = fail "syntax error"
> module Paren where > import Result > > {- frown :-( -} > > data Nonterminal = Paren' | Paren > > type Parser = [Terminal] -> Result Nonterminal > > type VStack vs v = ((vs, Nonterminal -> Parser), v) > > paren tr = state_1 () tr >>= (\ Paren' -> return ()) > > state_1 :: vs -> Parser > state_1 = state action_1 goto_1 > action_1 t = reduce_2 > goto_1 Paren = goto state_2 () > > > state_2 :: VStack vs () -> Parser > state_2 = state action_2 undefined > action_2 t = case t of { '(' -> shift state_5 (); > '$' -> shift state_3 (); > _ -> error } > > state_3 :: VStack (VStack vs ()) () -> Parser > state_3 = state action_3 undefined > action_3 t = reduce_1 > > state_4 :: VStack (VStack (VStack vs ()) ()) () -> Parser > state_4 = state action_4 undefined > action_4 t = case t of { '(' -> shift state_5 (); > ')' -> shift state_6 (); > _ -> error } > > state_5 :: VStack (VStack vs ()) () -> Parser > state_5 = state action_5 goto_5 > action_5 t = reduce_2 > goto_5 Paren = goto state_4 () > > state_6 :: VStack (VStack (VStack (VStack vs ()) ()) ()) () -> Parser > state_6 = state action_6 undefined > action_6 t = reduce_3 > > > reduce_1 (((((_, g), ()), _), ()), _) ts > = accept Paren' ts > > reduce_2 (_, g) ts = g Paren ts > > reduce_3 (((((((((_, g), ()), _), ()), _), ()), _), ()), _) ts > = g Paren ts > > state action goto vs ts = let { gs = (vs, g); g v = goto v gs } in action (head ts) gs ts > > shift state v vs ts = state (vs, v) (tail ts) > > shift' state v vs ts = state (vs, v) ts > > accept v _ = return v > > goto state v vs = state (vs, v) > > error gs ts = frown ts > > {- )-: frown -} > > frown _ = fail "syntax error"