]> ruin.nu Git - proglang.git/blobdiff - Parsyntax.y
streamlined the binary operators
[proglang.git] / Parsyntax.y
index 8bf7c6812d4ca3074be5f2e493c57b5359353263..dbd776705fe7fbb566e77bf45bda1e20787638ef 100644 (file)
@@ -70,8 +70,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 }
 
 
@@ -94,11 +94,7 @@ Exp3 : Ident '++' { postIncr_ $1 }
   | Bool { EBool $1 }
   | 'readInt' { EReadI }
   | 'readBool' { EReadB }
-  | Exp4 { $1 }
-
-
-Exp4 :: { Exp }
-Exp4 : '(' Exp ')' { $2 } 
+  | '(' Exp ')' { $2 }
 
 
 ListStm :: { [Stm] }
@@ -110,8 +106,8 @@ Stms :: { Stms }
 Stms : ListStm { Program (reverse $1) } 
 
 
-BOp :: { BOp }
-BOp : '<' { Lt } 
+Op0 :: { Op }
+Op0 : '<' { Lt } 
   | '<=' { ELt }
   | '>' { Gt }
   | '>=' { EGt }
@@ -132,6 +128,7 @@ Op2 : '*' { Times }
 Op :: { Op }
 Op : Op1 { $1 } 
   | Op2 { $1 }
+  | Op0 { $1 }
 
 
 Type :: { Type }
@@ -155,8 +152,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
 }