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 "--") }
27 '<=' { PT _ (TS "<=") }
29 '>=' { PT _ (TS ">=") }
30 '==' { PT _ (TS "==") }
31 '!=' { PT _ (TS "!=") }
35 'bool' { PT _ (TS "bool") }
36 'else' { PT _ (TS "else") }
37 'false' { PT _ (TS "false") }
38 'if' { PT _ (TS "if") }
39 'int' { PT _ (TS "int") }
40 'print' { PT _ (TS "print") }
41 'readBool' { PT _ (TS "readBool") }
42 'readInt' { PT _ (TS "readInt") }
43 'true' { PT _ (TS "true") }
44 'while' { PT _ (TS "while") }
46 L_ident { PT _ (TV $$) }
47 L_integ { PT _ (TI $$) }
53 Ident :: { Ident } : L_ident { Ident $1 }
54 Integer :: { Integer } : L_integ { (read $1) :: Integer }
57 Bool : 'true' { True }
62 Stm : Type Ident '=' Exp ';' { SDecl $1 $2 $4 }
63 | Type Ident ';' { decl_ $1 $2 }
65 | '{' ListStm '}' { SBlock (reverse $2) }
66 | 'if' '(' Exp ')' Stm { if_ $3 $5 }
67 | 'if' '(' Exp ')' Stm 'else' Stm { SIf $3 $5 $7 }
68 | 'while' '(' Exp ')' Stm { SWhile $3 $5 }
69 | 'print' Exp ';' { SPrint $2 }
74 Exp : Exp1 BOp Exp1 { BExp $1 $2 $3 }
79 Exp1 : Exp1 Op1 Exp2 { op1_ $1 $2 $3 }
84 Exp2 : Exp2 Op2 Exp3 { op2_ $1 $2 $3 }
89 Exp3 : Ident '++' { postIncr_ $1 }
90 | Ident '--' { postDecr_ $1 }
92 | Ident '=' Exp { EAss $1 $3 }
94 | '-' Exp3 { ENeg $2 }
96 | 'readInt' { EReadI }
97 | 'readBool' { EReadB }
102 ListStm : {- empty -} { [] }
103 | ListStm Stm { flip (:) $1 $2 }
107 Stms : ListStm { Program (reverse $1) }
135 Type : 'int' { TInt }
142 returnM :: a -> Err a
145 thenM :: Err a -> (a -> Err b) -> Err b
148 happyError :: [Token] -> Err a
150 Bad $ "syntax error at " ++ tokenPos ts ++ if null ts then [] else (" before " ++ unwords (map prToken (take 4 ts)))
153 decl_ t_ v_ = SDecl t_ v_ EDefault
154 if_ e_ s_ = SIf e_ s_ SNoop
155 op1_ e1_ o_ e2_ = OpExp e1_ o_ e2_
156 op2_ e1_ o_ e2_ = OpExp e1_ o_ e2_
157 postIncr_ i_ = EPost i_ Plus
158 postDecr_ i_ = EPost i_ Minus