X-Git-Url: https://ruin.nu/git/?a=blobdiff_plain;f=Parsyntax.y;h=461c967b366f8bf473c2b90877643b884aac1490;hb=4f21d932178a490040cf5e054f3ba9d006579368;hp=8bf7c6812d4ca3074be5f2e493c57b5359353263;hpb=33370917adde77f98b0955843b3222d9838a3fe8;p=proglang.git diff --git a/Parsyntax.y b/Parsyntax.y index 8bf7c68..461c967 100644 --- a/Parsyntax.y +++ b/Parsyntax.y @@ -23,6 +23,7 @@ import ErrM '++' { PT _ (TS "++") } '--' { PT _ (TS "--") } '-' { PT _ (TS "-") } + '!' { PT _ (TS "!") } '<' { PT _ (TS "<") } '<=' { PT _ (TS "<=") } '>' { PT _ (TS ">") } @@ -70,8 +71,8 @@ Stm : Type Ident '=' Exp ';' { SDecl $1 $2 $4 } Exp :: { Exp } -Exp : Exp1 BOp Exp1 { BExp $1 $2 $3 } - | Ident '=' Exp { EAss $1 $3 } +Exp : Ident '=' Exp { EAss $1 $3 } + | Exp1 Op0 Exp1 { compExp_ $1 $2 $3 } | Exp1 { $1 } @@ -91,14 +92,11 @@ Exp3 : Ident '++' { postIncr_ $1 } | Ident { EVar $1 } | Integer { EInt $1 } | '-' Exp3 { ENeg $2 } + | '!' Exp3 { ENot $2 } | Bool { EBool $1 } | 'readInt' { EReadI } | 'readBool' { EReadB } - | Exp4 { $1 } - - -Exp4 :: { Exp } -Exp4 : '(' Exp ')' { $2 } + | '(' Exp ')' { $2 } ListStm :: { [Stm] } @@ -110,8 +108,8 @@ Stms :: { Stms } Stms : ListStm { Program (reverse $1) } -BOp :: { BOp } -BOp : '<' { Lt } +Op0 :: { Op } +Op0 : '<' { Lt } | '<=' { ELt } | '>' { Gt } | '>=' { EGt } @@ -132,6 +130,7 @@ Op2 : '*' { Times } Op :: { Op } Op : Op1 { $1 } | Op2 { $1 } + | Op0 { $1 } Type :: { Type } @@ -155,8 +154,9 @@ happyError ts = myLexer = tokens decl_ t_ v_ = SDecl t_ v_ EDefault if_ e_ s_ = SIf e_ s_ SNoop -op1_ e1_ o_ e2_ = OpExp e1_ o_ e2_ -op2_ e1_ o_ e2_ = OpExp e1_ o_ e2_ +compExp_ e1_ o_ e2_ = BiOpExp e1_ o_ e2_ +op1_ e1_ o_ e2_ = BiOpExp e1_ o_ e2_ +op2_ e1_ o_ e2_ = BiOpExp e1_ o_ e2_ postIncr_ i_ = EPost i_ Plus postDecr_ i_ = EPost i_ Minus }