--- a/progs/parser-combinators/comb2-simple.sc Sat Nov 09 06:23:35 2024 +0000
+++ b/progs/parser-combinators/comb2-simple.sc Sat Nov 09 06:31:45 2024 +0000
@@ -8,6 +8,7 @@
// amm comb2-simple.sc
+// to make sure the input has an empty-method
trait IsSeq[I] {
extension (i: I) def isEmpty: Boolean
}
@@ -186,8 +187,7 @@
// an interpreter for the WHILE language
type Env = Map[String, Int]
-def eval_aexp(a: AExp, env: Env) : Int =
- a match {
+def eval_aexp(a: AExp, env: Env) : Int = a match {
case Num(i) => i
case Var(s) => env(s)
case Aop("+", a1, a2) => eval_aexp(a1, env) + eval_aexp(a2, env)
@@ -196,8 +196,7 @@
case Aop("/", a1, a2) => eval_aexp(a1, env) / eval_aexp(a2, env)
}
-def eval_bexp(b: BExp, env: Env) : Boolean =
- b match {
+def eval_bexp(b: BExp, env: Env) : Boolean = b match {
case True => true
case False => false
case Bop("==", a1, a2) => eval_aexp(a1, env) == eval_aexp(a2, env)
@@ -208,8 +207,7 @@
case Or(b1, b2) => eval_bexp(b1, env) || eval_bexp(b2, env)
}
-def eval_stmt(s: Stmt, env: Env) : Env =
- s match {
+def eval_stmt(s: Stmt, env: Env) : Env = s match {
case Skip => env
case Assign(x, a) => env + (x -> eval_aexp(a, env))
case If(b, bl1, bl2) => if (eval_bexp(b, env)) eval_bl(bl1, env) else eval_bl(bl2, env)
@@ -218,8 +216,7 @@
else env
case Write(x) => { println(env(x)) ; env }
}
-def eval_bl(bl: Block, env: Env) : Env =
- bl match {
+def eval_bl(bl: Block, env: Env) : Env = bl match {
case Nil => env
case s::bl => eval_bl(bl, eval_stmt(s, env))
}
--- a/progs/parser-combinators/comb2.sc Sat Nov 09 06:23:35 2024 +0000
+++ b/progs/parser-combinators/comb2.sc Sat Nov 09 06:31:45 2024 +0000
@@ -16,7 +16,7 @@
case class ~[+A, +B](x: A, y: B)
-
+// to make sure the input has an empty-method
trait IsSeq[I] {
extension (i: I) def isEmpty: Boolean
}
@@ -191,8 +191,7 @@
case Aop("/", a1, a2) => eval_aexp(a1, env) / eval_aexp(a2, env)
}
-def eval_bexp(b: BExp, env: Env) : Boolean =
- b match {
+def eval_bexp(b: BExp, env: Env) : Boolean = b match {
case True => true
case False => false
case Bop("==", a1, a2) => eval_aexp(a1, env) == eval_aexp(a2, env)
@@ -203,8 +202,7 @@
case Or(b1, b2) => eval_bexp(b1, env) || eval_bexp(b2, env)
}
-def eval_stmt(s: Stmt, env: Env) : Env =
- s match {
+def eval_stmt(s: Stmt, env: Env) : Env = s match {
case Skip => env
case Assign(x, a) => env + (x -> eval_aexp(a, env))
case If(b, bl1, bl2) => if (eval_bexp(b, env)) eval_bl(bl1, env) else eval_bl(bl2, env)
@@ -213,8 +211,7 @@
else env
case Write(x) => { println(env(x)) ; env }
}
-def eval_bl(bl: Block, env: Env) : Env =
- bl match {
+def eval_bl(bl: Block, env: Env) : Env = bl match {
case Nil => env
case s::bl => eval_bl(bl, eval_stmt(s, env))
}