]> ruin.nu Git - proglang.git/blobdiff - Parsyntax.y
added constructor for declaration with default value
[proglang.git] / Parsyntax.y
index 02e94b0bc4803b1a1ac5ca5f525de11cc3e348f1..6613fa351325648a0f3cd8bff19ae301e6fbc25b 100644 (file)
@@ -71,10 +71,8 @@ Stms : ListStm { Program (reverse $1) }
 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 }
@@ -154,10 +152,6 @@ happyError ts =
   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_