progs/comb2.scala
changeset 684 1ee523c4f098
parent 683 c6c79d21f8a8
child 685 75d9f9e5906f
equal deleted inserted replaced
683:c6c79d21f8a8 684:1ee523c4f098
   113    IdParser ==> Var || 
   113    IdParser ==> Var || 
   114    NumParser ==> Num
   114    NumParser ==> Num
   115 
   115 
   116 // boolean expressions with some simple nesting
   116 // boolean expressions with some simple nesting
   117 lazy val BExp: Parser[String, BExp] = 
   117 lazy val BExp: Parser[String, BExp] = 
   118    (AExp ~ "==" ~ AExp) ==> { case x ~ y ~ z => Bop("==", x, z): BExp } || 
   118    (AExp ~ "==" ~ AExp) ==> { case x ~ _ ~ z => Bop("==", x, z): BExp } || 
   119    (AExp ~ "!=" ~ AExp) ==> { case x ~ y ~ z => Bop("!=", x, z): BExp } || 
   119    (AExp ~ "!=" ~ AExp) ==> { case x ~ _ ~ z => Bop("!=", x, z): BExp } || 
   120    (AExp ~ "<" ~ AExp) ==> { case x ~ y ~ z => Bop("<", x, z): BExp } || 
   120    (AExp ~ "<" ~ AExp) ==> { case x ~ _ ~ z => Bop("<", x, z): BExp } || 
   121    (AExp ~ ">" ~ AExp) ==> { case x ~ y ~ z => Bop(">", x, z): BExp } ||
   121    (AExp ~ ">" ~ AExp) ==> { case x ~ _ ~ z => Bop(">", x, z): BExp } ||
   122    ("(" ~ BExp ~ ")" ~ "&&" ~ BExp) ==> { case x ~ y ~ z ~ u ~ v => And(y, v): BExp } ||
   122    ("(" ~ BExp ~ ")" ~ "&&" ~ BExp) ==> { case x ~ y ~ z ~ u ~ v => And(y, v): BExp } ||
   123    ("(" ~ BExp ~ ")" ~ "||" ~ BExp) ==> { case x ~ y ~ z ~ u ~ v => Or(y, v): BExp } ||
   123    ("(" ~ BExp ~ ")" ~ "||" ~ BExp) ==> { case x ~ y ~ z ~ u ~ v => Or(y, v): BExp } ||
   124    ("true" ==> (_ => True: BExp )) || 
   124    ("true" ==> (_ => True: BExp )) || 
   125    ("false" ==> (_ => False: BExp )) ||
   125    ("false" ==> (_ => False: BExp )) ||
   126    ("(" ~ BExp ~ ")") ==> { case _ ~ x ~ _ => x }
   126    ("(" ~ BExp ~ ")") ==> { case _ ~ x ~ _ => x }