--- a/progs/comb2.scala Wed Nov 06 23:27:19 2019 +0000
+++ b/progs/comb2.scala Thu Nov 07 00:07:16 2019 +0000
@@ -103,13 +103,13 @@
}
lazy val AExp: Parser[String, AExp] =
- (Te ~ "+" ~ AExp) ==> { case x ~ y ~ z => Aop("+", x, z): AExp } ||
- (Te ~ "-" ~ AExp) ==> { case x ~ y ~ z => Aop("-", x, z): AExp } || Te
+ (Te ~ "+" ~ AExp) ==> { case x ~ _ ~ z => Aop("+", x, z): AExp } ||
+ (Te ~ "-" ~ AExp) ==> { case x ~ _ ~ z => Aop("-", x, z): AExp } || Te
lazy val Te: Parser[String, AExp] =
- (Fa ~ "*" ~ Te) ==> { case x ~ y ~ z => Aop("*", x, z): AExp } ||
- (Fa ~ "/" ~ Te) ==> { case x ~ y ~ z => Aop("/", x, z): AExp } || Fa
+ (Fa ~ "*" ~ Te) ==> { case x ~ _ ~ z => Aop("*", x, z): AExp } ||
+ (Fa ~ "/" ~ Te) ==> { case x ~ _ ~ z => Aop("/", x, z): AExp } || Fa
lazy val Fa: Parser[String, AExp] =
- ("(" ~ AExp ~ ")") ==> { case x ~ y ~ z => y } ||
+ ("(" ~ AExp ~ ")") ==> { case _ ~ y ~ _ => y } ||
IdParser ==> Var ||
NumParser ==> Num
@@ -119,8 +119,8 @@
(AExp ~ "!=" ~ AExp) ==> { case x ~ _ ~ z => Bop("!=", x, z): BExp } ||
(AExp ~ "<" ~ AExp) ==> { case x ~ _ ~ z => Bop("<", x, z): BExp } ||
(AExp ~ ">" ~ AExp) ==> { case x ~ _ ~ z => Bop(">", x, z): BExp } ||
- ("(" ~ BExp ~ ")" ~ "&&" ~ BExp) ==> { case x ~ y ~ z ~ u ~ v => And(y, v): BExp } ||
- ("(" ~ BExp ~ ")" ~ "||" ~ BExp) ==> { case x ~ y ~ z ~ u ~ v => Or(y, v): BExp } ||
+ ("(" ~ BExp ~ ")" ~ "&&" ~ BExp) ==> { case _ ~ y ~ _ ~ _ ~ v => And(y, v): BExp } ||
+ ("(" ~ BExp ~ ")" ~ "||" ~ BExp) ==> { case _ ~ y ~ _ ~ _ ~ v => Or(y, v): BExp } ||
("true" ==> (_ => True: BExp )) ||
("false" ==> (_ => False: BExp )) ||
("(" ~ BExp ~ ")") ==> { case _ ~ x ~ _ => x }
@@ -128,14 +128,14 @@
// statement / statements
lazy val Stmt: Parser[String, Stmt] =
(("skip" ==> (_ => Skip: Stmt)) ||
- (IdParser ~ ":=" ~ AExp) ==> { case x ~ y ~ z => Assign(x, z): Stmt } ||
- ("write(" ~ IdParser ~ ")") ==> { case x ~y ~ z => Write(y): Stmt } ||
+ (IdParser ~ ":=" ~ AExp) ==> { case x ~ _ ~ z => Assign(x, z): Stmt } ||
+ ("write(" ~ IdParser ~ ")") ==> { case _ ~ y ~ _ => Write(y): Stmt } ||
("if" ~ BExp ~ "then" ~ Block ~ "else" ~ Block) ==>
- { case x ~ y ~ z ~ u ~ v ~ w => If(y, u, w): Stmt } ||
- ("while" ~ BExp ~ "do" ~ Block) ==> { case x ~ y ~ z ~ w => While(y, w) })
+ { case _ ~ y ~ _ ~ u ~ _ ~ w => If(y, u, w): Stmt } ||
+ ("while" ~ BExp ~ "do" ~ Block) ==> { case _ ~ y ~ _ ~ w => While(y, w) })
lazy val Stmts: Parser[String, Block] =
- (Stmt ~ ";" ~ Stmts) ==> { case x ~ y ~ z => x :: z : Block } ||
+ (Stmt ~ ";" ~ Stmts) ==> { case x ~ _ ~ z => x :: z : Block } ||
(Stmt ==> ( s => List(s) : Block))
// blocks (enclosed in curly braces)