1 -- This Happy file was machine-generated by the BNF converter
12 -- no lexer declaration
13 %monad { Err } { thenM } { returnM }
23 '++' { PT _ (TS "++") }
24 '--' { PT _ (TS "--") }
28 '<=' { PT _ (TS "<=") }
30 '>=' { PT _ (TS ">=") }
31 '==' { PT _ (TS "==") }
32 '!=' { PT _ (TS "!=") }
36 'bool' { PT _ (TS "bool") }
37 'else' { PT _ (TS "else") }
38 'false' { PT _ (TS "false") }
39 'if' { PT _ (TS "if") }
40 'int' { PT _ (TS "int") }
41 'print' { PT _ (TS "print") }
42 'readBool' { PT _ (TS "readBool") }
43 'readInt' { PT _ (TS "readInt") }
44 'true' { PT _ (TS "true") }
45 'while' { PT _ (TS "while") }
47 L_ident { PT _ (TV $$) }
48 L_integ { PT _ (TI $$) }
54 Ident :: { Ident } : L_ident { Ident $1 }
55 Integer :: { Integer } : L_integ { (read $1) :: Integer }
58 Bool : 'true' { True }
63 Stm : Type Ident '=' Exp ';' { SDecl $1 $2 $4 }
64 | Type Ident ';' { decl_ $1 $2 }
66 | '{' ListStm '}' { SBlock (reverse $2) }
67 | 'if' '(' Exp ')' Stm { if_ $3 $5 }
68 | 'if' '(' Exp ')' Stm 'else' Stm { SIf $3 $5 $7 }
69 | 'while' '(' Exp ')' Stm { SWhile $3 $5 }
70 | 'print' Exp ';' { SPrint $2 }
74 Exp : Ident '=' Exp { EAss $1 $3 }
75 | Exp1 Op0 Exp1 { compExp_ $1 $2 $3 }
80 Exp1 : Exp1 Op1 Exp2 { op1_ $1 $2 $3 }
85 Exp2 : Exp2 Op2 Exp3 { op2_ $1 $2 $3 }
90 Exp3 : Ident '++' { postIncr_ $1 }
91 | Ident '--' { postDecr_ $1 }
94 | '-' Exp3 { ENeg $2 }
95 | '!' Exp3 { ENot $2 }
97 | 'readInt' { EReadI }
98 | 'readBool' { EReadB }
103 ListStm : {- empty -} { [] }
104 | ListStm Stm { flip (:) $1 $2 }
108 Stms : ListStm { Program (reverse $1) }
137 Type : 'int' { TInt }
144 returnM :: a -> Err a
147 thenM :: Err a -> (a -> Err b) -> Err b
150 happyError :: [Token] -> Err a
152 Bad $ "syntax error at " ++ tokenPos ts ++ if null ts then [] else (" before " ++ unwords (map prToken (take 4 ts)))
155 decl_ t_ v_ = SDecl t_ v_ EDefault
156 if_ e_ s_ = SIf e_ s_ SNoop
157 compExp_ e1_ o_ e2_ = BiOpExp e1_ o_ e2_
158 op1_ e1_ o_ e2_ = BiOpExp e1_ o_ e2_
159 op2_ e1_ o_ e2_ = BiOpExp e1_ o_ e2_
160 postIncr_ i_ = EPost i_ Plus
161 postDecr_ i_ = EPost i_ Minus