Stm :: { Stm }
Stm : Exp ';' { SExp $1 }
| '{' ListStm '}' { SBlock (reverse $2) }
- | 'int' Ident '=' Exp ';' { declIntE_ $2 $4 }
- | 'bool' Ident '=' Exp ';' { declBoolE_ $2 $4 }
- | 'int' Ident ';' { declInt_ $2 }
- | 'bool' Ident ';' { declBool_ $2 }
+ | Type Ident '=' Exp ';' { SDecl $1 $2 $4 }
+ | Type Ident ';' { SDeclD $1 $2 }
| 'while' '(' Exp ')' Stm { SWhile $3 $5 }
| 'if' '(' Exp ')' Stm 'else' Stm { SIf $3 $5 $7 }
| 'if' '(' Exp ')' Stm { if_ $3 $5 }
Bad $ "syntax error at " ++ tokenPos ts ++ if null ts then [] else (" before " ++ unwords (map prToken (take 4 ts)))
myLexer = tokens
-declIntE_ x_ e_ = SDecl TInt x_ e_
-declBoolE_ x_ e_ = SDecl TBool x_ e_
-declInt_ x_ = SDecl TInt x_ (EInt 0)
-declBool_ x_ = SDecl TBool x_ (EBool False)
if_ e_ s_ = SIf e_ s_ SNoop
compExp_ e1_ o_ e2_ = BiOpExp e1_ o_ e2_
op1_ e1_ o_ e2_ = BiOpExp e1_ o_ e2_