X-Git-Url: https://ruin.nu/git/?p=proglang.git;a=blobdiff_plain;f=Parsyntax.y;h=6613fa351325648a0f3cd8bff19ae301e6fbc25b;hp=02e94b0bc4803b1a1ac5ca5f525de11cc3e348f1;hb=fd3bc0ef4542783846af4e2c4f986e94f96c74ff;hpb=fe6d5e0ac088e6b648a5029b101402c017fd04de diff --git a/Parsyntax.y b/Parsyntax.y index 02e94b0..6613fa3 100644 --- a/Parsyntax.y +++ b/Parsyntax.y @@ -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_