109 case Some(s) => Set(sb.splitAt(s.length)) |
109 case Some(s) => Set(sb.splitAt(s.length)) |
110 } |
110 } |
111 } |
111 } |
112 |
112 |
113 lazy val AExp: Parser[String, AExp] = |
113 lazy val AExp: Parser[String, AExp] = |
114 ((Te ~ "+" ~ AExp) ==> { case ((x, y), z) => Aop("+", x, z): AExp } || |
114 ((Te ~ "+" ~ AExp) ==> { case ((x, y), z) => Aop("+", x, z):AExp } || |
115 (Te ~ "-" ~ AExp) ==> { case ((x, y), z) => Aop("-", x, z): AExp } || Te) |
115 (Te ~ "-" ~ AExp) ==> { case ((x, y), z) => Aop("-", x, z):AExp } || Te) |
116 lazy val Te: Parser[String, AExp] = |
116 lazy val Te: Parser[String, AExp] = |
117 (Fa ~ "*" ~ Te) ==> { case ((x, y), z) => Aop("*", x, z): AExp } || Fa |
117 (Fa ~ "*" ~ Te) ==> { case ((x, y), z) => Aop("*", x, z):AExp } || Fa |
118 lazy val Fa: Parser[String, AExp] = |
118 lazy val Fa: Parser[String, AExp] = |
119 (("(" ~ AExp ~ ")") ==> { case ((x, y), z) => y } || |
119 (("(" ~ AExp ~ ")") ==> { case ((x, y), z) => y } || |
120 IdParser ==> ((s:String) => Var(s) :AExp) || |
120 IdParser ==> Var || |
121 NumParser ==> ((i:Int) => Num(i) :AExp)) |
121 NumParser ==> Num) |
122 |
122 |
123 // boolean expressions |
123 // boolean expressions |
124 lazy val BExp: Parser[String, BExp] = |
124 lazy val BExp: Parser[String, BExp] = |
125 ((AExp ~ "=" ~ AExp) ==> { case ((x, y), z) => Bop("=", x, z): BExp } || |
125 ((AExp ~ "=" ~ AExp) ==> { case ((x, y), z) => Bop("=", x, z): BExp } || |
126 (AExp ~ "!=" ~ AExp) ==> { case ((x, y), z) => Bop("!=", x, z): BExp } || |
126 (AExp ~ "!=" ~ AExp) ==> { case ((x, y), z) => Bop("!=", x, z): BExp } || |