| author | Christian Urban <urbanc@in.tum.de> | 
| Wed, 20 Nov 2019 17:10:03 +0000 | |
| changeset 695 | a936b1717b1b | 
| parent 694 | f16459e2c490 | 
| child 696 | 2726f2afad67 | 
| permissions | -rw-r--r-- | 
| 609 | 1 | // A Small Compiler for the WHILE Language | 
| 694 | 2 | // - includes arrays and a small parser for | 
| 3 | // translated BF programs | |
| 609 | 4 | |
| 5 | // the abstract syntax trees | |
| 6 | abstract class Stmt | |
| 7 | abstract class AExp | |
| 8 | abstract class BExp | |
| 9 | type Block = List[Stmt] | |
| 10 | ||
| 11 | // statements | |
| 12 | case object Skip extends Stmt | |
| 694 | 13 | case class Array(s: String, n: Int) extends Stmt | 
| 609 | 14 | case class If(a: BExp, bl1: Block, bl2: Block) extends Stmt | 
| 15 | case class While(b: BExp, bl: Block) extends Stmt | |
| 16 | case class Assign(s: String, a: AExp) extends Stmt | |
| 612 | 17 | case class AssignA(s: String, a1: AExp, a2: AExp) extends Stmt | 
| 694 | 18 | case class Write(s: String) extends Stmt | 
| 19 | case class Read(s: String) extends Stmt | |
| 609 | 20 | |
| 21 | // arithmetic expressions | |
| 22 | case class Var(s: String) extends AExp | |
| 23 | case class Num(i: Int) extends AExp | |
| 24 | case class Aop(o: String, a1: AExp, a2: AExp) extends AExp | |
| 694 | 25 | case class Ref(s: String, a: AExp) extends AExp | 
| 609 | 26 | |
| 27 | // boolean expressions | |
| 28 | case object True extends BExp | |
| 29 | case object False extends BExp | |
| 30 | case class Bop(o: String, a1: AExp, a2: AExp) extends BExp | |
| 31 | ||
| 32 | ||
| 33 | // compiler headers needed for the JVM | |
| 34 | // (contains an init method, as well as methods for read and write) | |
| 35 | val beginning = """ | |
| 36 | .class public XXX.XXX | |
| 37 | .super java/lang/Object | |
| 38 | ||
| 39 | .method public static write(I)V | |
| 40 | .limit locals 1 | |
| 41 | .limit stack 2 | |
| 42 | getstatic java/lang/System/out Ljava/io/PrintStream; | |
| 43 | iload 0 | |
| 694 | 44 | i2c ; Int => Char | 
| 45 | invokevirtual java/io/PrintStream/print(C)V ; println(I)V => print(C)V | |
| 609 | 46 | return | 
| 47 | .end method | |
| 48 | ||
| 694 | 49 | .method public static read()I | 
| 50 | .limit locals 10 | |
| 51 | .limit stack 10 | |
| 52 | ||
| 53 | ldc 0 | |
| 54 | istore 1 ; this will hold our final integer | |
| 55 | Label1: | |
| 56 | getstatic java/lang/System/in Ljava/io/InputStream; | |
| 57 | invokevirtual java/io/InputStream/read()I | |
| 58 | istore 2 | |
| 59 | iload 2 | |
| 60 | ldc 10 ; the newline delimiter | |
| 61 | isub | |
| 62 | ifeq Label2 | |
| 63 | iload 2 | |
| 64 | ldc 32 ; the space delimiter | |
| 65 | isub | |
| 66 | ifeq Label2 | |
| 67 | ||
| 68 | iload 2 | |
| 69 | ldc 48 ; we have our digit in ASCII, have to subtract it from 48 | |
| 70 | isub | |
| 71 | ldc 10 | |
| 72 | iload 1 | |
| 73 | imul | |
| 74 | iadd | |
| 75 | istore 1 | |
| 76 | goto Label1 | |
| 77 | Label2: | |
| 78 | ;when we come here we have our integer computed in local variable 1 | |
| 79 | iload 1 | |
| 80 | ireturn | |
| 81 | .end method | |
| 82 | ||
| 609 | 83 | .method public static main([Ljava/lang/String;)V | 
| 84 | .limit locals 200 | |
| 85 | .limit stack 200 | |
| 86 | ||
| 87 | """ | |
| 88 | ||
| 89 | val ending = """ | |
| 90 | ||
| 91 | return | |
| 92 | ||
| 93 | .end method | |
| 94 | """ | |
| 95 | ||
| 694 | 96 | |
| 609 | 97 | |
| 98 | ||
| 99 | // for generating new labels | |
| 100 | var counter = -1 | |
| 101 | ||
| 102 | def Fresh(x: String) = {
 | |
| 103 | counter += 1 | |
| 104 | x ++ "_" ++ counter.toString() | |
| 105 | } | |
| 106 | ||
| 107 | // environments and instructions | |
| 694 | 108 | type Env = Map[String, Int] | 
| 109 | ||
| 110 | // convenient string interpolations | |
| 111 | // for instructions and labels | |
| 112 | import scala.language.implicitConversions | |
| 113 | import scala.language.reflectiveCalls | |
| 114 | ||
| 115 | implicit def sring_inters(sc: StringContext) = new {
 | |
| 116 | def i(args: Any*): String = " " ++ sc.s(args:_*) ++ "\n" | |
| 117 | def l(args: Any*): String = sc.s(args:_*) ++ ":\n" | |
| 118 | } | |
| 119 | ||
| 120 | def compile_op(op: String) = op match {
 | |
| 121 | case "+" => i"iadd" | |
| 122 | case "-" => i"isub" | |
| 123 | case "*" => i"imul" | |
| 124 | } | |
| 609 | 125 | |
| 126 | // arithmetic expression compilation | |
| 694 | 127 | def compile_aexp(a: AExp, env : Env) : String = a match {
 | 
| 128 | case Num(i) => i"ldc $i" | |
| 129 |   case Var(s) => i"iload ${env(s)} \t\t; $s"
 | |
| 130 | case Aop(op, a1, a2) => | |
| 131 | compile_aexp(a1, env) ++ compile_aexp(a2, env) ++ compile_op(op) | |
| 132 | case Ref(s, a) => | |
| 133 |     i"aload ${env(s)}" ++ compile_aexp(a, env) ++  i"iaload"
 | |
| 609 | 134 | } | 
| 135 | ||
| 136 | // boolean expression compilation | |
| 694 | 137 | def compile_bexp(b: BExp, env : Env, jmp: String) : String = b match {
 | 
| 138 | case True => "" | |
| 139 | case False => i"goto $jmp" | |
| 140 |   case Bop("==", a1, a2) => 
 | |
| 141 | compile_aexp(a1, env) ++ compile_aexp(a2, env) ++ i"if_icmpne $jmp" | |
| 609 | 142 |   case Bop("!=", a1, a2) => 
 | 
| 694 | 143 | compile_aexp(a1, env) ++ compile_aexp(a2, env) ++ i"if_icmpeq $jmp" | 
| 609 | 144 |   case Bop("<", a1, a2) => 
 | 
| 694 | 145 | compile_aexp(a1, env) ++ compile_aexp(a2, env) ++ i"if_icmpge $jmp" | 
| 609 | 146 | } | 
| 147 | ||
| 148 | // statement compilation | |
| 694 | 149 | def compile_stmt(s: Stmt, env: Env) : (String, Env) = s match {
 | 
| 150 |   case Skip => ("", env)
 | |
| 609 | 151 |   case Assign(x, a) => {
 | 
| 694 | 152 | val index = env.getOrElse(x, env.keys.size) | 
| 153 | (compile_aexp(a, env) ++ i"istore $index \t\t; $x", env + (x -> index)) | |
| 609 | 154 | } | 
| 155 |   case If(b, bl1, bl2) => {
 | |
| 156 |     val if_else = Fresh("If_else")
 | |
| 157 |     val if_end = Fresh("If_end")
 | |
| 158 | val (instrs1, env1) = compile_block(bl1, env) | |
| 159 | val (instrs2, env2) = compile_block(bl2, env1) | |
| 160 | (compile_bexp(b, env, if_else) ++ | |
| 161 | instrs1 ++ | |
| 694 | 162 | i"goto $if_end" ++ | 
| 163 | l"$if_else" ++ | |
| 609 | 164 | instrs2 ++ | 
| 694 | 165 | l"$if_end", env2) | 
| 609 | 166 | } | 
| 167 |   case While(b, bl) => {
 | |
| 168 |     val loop_begin = Fresh("Loop_begin")
 | |
| 169 |     val loop_end = Fresh("Loop_end")
 | |
| 170 | val (instrs1, env1) = compile_block(bl, env) | |
| 694 | 171 | (l"$loop_begin" ++ | 
| 609 | 172 | compile_bexp(b, env, loop_end) ++ | 
| 173 | instrs1 ++ | |
| 694 | 174 | i"goto $loop_begin" ++ | 
| 175 | l"$loop_end", env1) | |
| 609 | 176 | } | 
| 177 | case Write(x) => | |
| 694 | 178 |     (i"iload ${env(x)} \t\t; $x" ++ 
 | 
| 179 | i"invokestatic XXX/XXX/write(I)V", env) | |
| 180 |   case Read(x) => {
 | |
| 181 | val index = env.getOrElse(x, env.keys.size) | |
| 182 | (i"invokestatic XXX/XXX/read()I" ++ | |
| 183 | i"istore $index \t\t; $x", env + (x -> index)) | |
| 184 | } | |
| 185 |   case Array(s: String, n: Int) => {
 | |
| 186 |     val index = if (env.isDefinedAt(s)) throw new Exception("array def error") else 
 | |
| 187 | env.keys.size | |
| 188 | (i"ldc $n" ++ | |
| 189 | i"newarray int" ++ | |
| 190 | i"astore $index", env + (s -> index)) | |
| 191 | } | |
| 612 | 192 |   case AssignA(s, a1, a2) => {
 | 
| 193 | val index = if (env.isDefinedAt(s)) env(s) else | |
| 694 | 194 |                     throw new Exception("array not defined")
 | 
| 195 |     (i"aload ${env(s)}" ++
 | |
| 612 | 196 | compile_aexp(a1, env) ++ | 
| 197 | compile_aexp(a2, env) ++ | |
| 694 | 198 | i"iastore", env) | 
| 612 | 199 | } | 
| 609 | 200 | } | 
| 201 | ||
| 202 | // compilation of a block (i.e. list of instructions) | |
| 694 | 203 | def compile_block(bl: Block, env: Env) : (String, Env) = bl match {
 | 
| 204 |   case Nil => ("", env)
 | |
| 609 | 205 |   case s::bl => {
 | 
| 206 | val (instrs1, env1) = compile_stmt(s, env) | |
| 207 | val (instrs2, env2) = compile_block(bl, env1) | |
| 208 | (instrs1 ++ instrs2, env2) | |
| 209 | } | |
| 210 | } | |
| 211 | ||
| 694 | 212 | |
| 609 | 213 | // main compilation function for blocks | 
| 214 | def compile(bl: Block, class_name: String) : String = {
 | |
| 215 | val instructions = compile_block(bl, Map.empty)._1 | |
| 216 |   (beginning ++ instructions.mkString ++ ending).replaceAllLiterally("XXX", class_name)
 | |
| 217 | } | |
| 218 | ||
| 219 | ||
| 694 | 220 | // Fibonacci numbers as a test-case | 
| 221 | val fib_test = | |
| 222 |   List(Read("n"),                       //  read n;                     
 | |
| 223 |        Assign("minus1",Num(0)),         //  minus1 := 0;
 | |
| 224 |        Assign("minus2",Num(1)),         //  minus2 := 1;
 | |
| 225 |        Assign("temp",Num(0)),           //  temp := 0;
 | |
| 226 |        While(Bop("<",Num(0),Var("n")),  //  while n > 0 do  {
 | |
| 227 |           List(Assign("temp",Var("minus2")),    //  temp := minus2;
 | |
| 228 |                Assign("minus2",Aop("+",Var("minus1"),Var("minus2"))), 
 | |
| 229 | // minus2 := minus1 + minus2; | |
| 230 |                Assign("minus1",Var("temp")), //  minus1 := temp;
 | |
| 231 |                Assign("n",Aop("-",Var("n"),Num(1))))), //  n := n - 1 };
 | |
| 232 |        Write("minus1"))                 //  write minus1
 | |
| 233 | ||
| 234 | // prints out the JVM-assembly program | |
| 235 | ||
| 236 | // println(compile(fib_test, "fib")) | |
| 237 | ||
| 238 | // can be assembled with | |
| 609 | 239 | // | 
| 240 | // java -jar jvm/jasmin-2.4/jasmin.jar fib.j | |
| 241 | // | |
| 242 | // and started with | |
| 243 | // | |
| 244 | // java fib/fib | |
| 245 | ||
| 246 | import scala.util._ | |
| 247 | import scala.sys.process._ | |
| 248 | import scala.io | |
| 249 | ||
| 250 | def compile_tofile(bl: Block, class_name: String) = {
 | |
| 251 | val output = compile(bl, class_name) | |
| 252 | val fw = new java.io.FileWriter(class_name + ".j") | |
| 253 | fw.write(output) | |
| 254 | fw.close() | |
| 255 | } | |
| 256 | ||
| 257 | def compile_all(bl: Block, class_name: String) : Unit = {
 | |
| 258 | compile_tofile(bl, class_name) | |
| 259 |   println("compiled ")
 | |
| 260 |   val test = ("java -jar jvm/jasmin-2.4/jasmin.jar " + class_name + ".j").!!
 | |
| 261 |   println("assembled ")
 | |
| 262 | } | |
| 263 | ||
| 264 | def time_needed[T](i: Int, code: => T) = {
 | |
| 265 | val start = System.nanoTime() | |
| 266 | for (j <- 1 to i) code | |
| 267 | val end = System.nanoTime() | |
| 268 | (end - start)/(i * 1.0e9) | |
| 269 | } | |
| 270 | ||
| 271 | ||
| 272 | def compile_run(bl: Block, class_name: String) : Unit = {
 | |
| 273 |   println("Start compilation")
 | |
| 274 | compile_all(bl, class_name) | |
| 275 |   println("Time: " + time_needed(1, ("java " + class_name + "/" + class_name).!))
 | |
| 276 | } | |
| 277 | ||
| 278 | ||
| 694 | 279 | |
| 280 | val arr_test = | |
| 281 |   List(Array("a", 10),
 | |
| 282 |        Array("b", 2),
 | |
| 283 |        AssignA("a", Num(0), Num(10)),
 | |
| 284 |        Assign("x", Ref("a", Num(0))),
 | |
| 285 |        Write("x"),
 | |
| 286 |        AssignA("b", Num(1), Num(5)),
 | |
| 287 |        Assign("x", Ref("b", Num(1))),
 | |
| 288 |        Write("x"))       
 | |
| 609 | 289 | |
| 290 | ||
| 694 | 291 | //compile_run(arr_test, "a") | 
| 616 | 292 | |
| 293 | //==================== | |
| 294 | // Parser Combinators | |
| 295 | //==================== | |
| 296 | ||
| 297 | import scala.language.implicitConversions | |
| 298 | import scala.language.reflectiveCalls | |
| 299 | ||
| 694 | 300 | type IsSeq[A] = A => Seq[_] | 
| 616 | 301 | |
| 694 | 302 | abstract class Parser[I : IsSeq, T] {
 | 
| 616 | 303 | def parse(ts: I): Set[(T, I)] | 
| 304 | ||
| 305 | def parse_all(ts: I) : Set[T] = | |
| 306 | for ((head, tail) <- parse(ts); if (tail.isEmpty)) yield head | |
| 307 | } | |
| 308 | ||
| 694 | 309 | class SeqParser[I : IsSeq, T, S](p: => Parser[I, T], q: => Parser[I, S]) extends Parser[I, (T, S)] {
 | 
| 616 | 310 | def parse(sb: I) = | 
| 311 | for ((head1, tail1) <- p.parse(sb); | |
| 312 | (head2, tail2) <- q.parse(tail1)) yield ((head1, head2), tail2) | |
| 313 | } | |
| 314 | ||
| 694 | 315 | class AltParser[I : IsSeq, T](p: => Parser[I, T], q: => Parser[I, T]) extends Parser[I, T] {
 | 
| 616 | 316 | def parse(sb: I) = p.parse(sb) ++ q.parse(sb) | 
| 317 | } | |
| 318 | ||
| 694 | 319 | class FunParser[I : IsSeq, T, S](p: => Parser[I, T], f: T => S) extends Parser[I, S] {
 | 
| 616 | 320 | def parse(sb: I) = | 
| 321 | for ((head, tail) <- p.parse(sb)) yield (f(head), tail) | |
| 322 | } | |
| 323 | ||
| 324 | ||
| 325 | import scala.util.matching.Regex | |
| 326 | case class RegexParser(reg: Regex) extends Parser[String, String] {
 | |
| 327 |   def parse(sb: String) = reg.findPrefixMatchOf(sb) match {
 | |
| 328 | case None => Set() | |
| 329 | case Some(m) => Set((m.matched, m.after.toString)) | |
| 330 | } | |
| 331 | } | |
| 332 | ||
| 333 | def StringParser(s: String) = RegexParser(Regex.quote(s).r) | |
| 334 | ||
| 335 | ||
| 336 | implicit def string2parser(s : String) = StringParser(s) | |
| 337 | ||
| 694 | 338 | implicit def ParserOps[I : IsSeq, T](p: Parser[I, T]) = new {
 | 
| 616 | 339 | def | (q : => Parser[I, T]) = new AltParser[I, T](p, q) | 
| 340 | def ==>[S] (f: => T => S) = new FunParser[I, T, S](p, f) | |
| 341 | def ~[S] (q : => Parser[I, S]) = new SeqParser[I, T, S](p, q) | |
| 342 | } | |
| 343 | ||
| 344 | implicit def StringOps(s: String) = new {
 | |
| 345 | def | (q : => Parser[String, String]) = new AltParser[String, String](s, q) | |
| 346 | def | (r: String) = new AltParser[String, String](s, r) | |
| 347 | def ==>[S] (f: => String => S) = new FunParser[String, String, S](s, f) | |
| 348 | def ~[S](q : => Parser[String, S]) = | |
| 349 | new SeqParser[String, String, S](s, q) | |
| 350 | def ~ (r: String) = | |
| 351 | new SeqParser[String, String, String](s, r) | |
| 352 | } | |
| 353 | ||
| 354 | ||
| 355 | val NumParser = RegexParser("[0-9]+".r) ==> (s => s.toInt : Int)
 | |
| 356 | val IdParser = RegexParser("[a-z][a-z,0-9]*".r)
 | |
| 357 | ||
| 358 | ||
| 359 | ||
| 360 | // Grammar Rules | |
| 361 | ||
| 362 | lazy val AExp: Parser[String, AExp] = | |
| 363 |   (Te ~ "+" ~ AExp) ==> { case ((x, _), z) => Aop("+", x, z):AExp } |
 | |
| 364 |   (Te ~ "-" ~ AExp) ==> { case ((x, _), z) => Aop("-", x, z):AExp } | Te
 | |
| 365 | lazy val Te: Parser[String, AExp] = | |
| 366 |   (Fa ~ "*" ~ Te) ==> { case ((x, _), z) => Aop("*", x, z):AExp } | Fa
 | |
| 367 | lazy val Fa: Parser[String, AExp] = | |
| 368 |    ("(" ~ AExp ~ ")") ==> { case ((_, y), _) => y } | 
 | |
| 369 |    (IdParser ~ "[" ~ AExp ~ "]") ==> { case (((x, _), y), _) => Ref(x, y) } |
 | |
| 370 | IdParser ==> Var | | |
| 371 | NumParser ==> Num | |
| 372 | ||
| 373 | // boolean expressions | |
| 374 | lazy val BExp: Parser[String, BExp] = | |
| 375 |    (AExp ~ "=" ~ AExp) ==> { case ((x, y), z) => Bop("=", x, z):BExp } | 
 | |
| 376 |    (AExp ~ "!=" ~ AExp) ==> { case ((x, y), z) => Bop("!=", x, z):BExp } | 
 | |
| 377 |    (AExp ~ "<" ~ AExp) ==> { case ((x, y), z) => Bop("<", x, z):BExp } | 
 | |
| 378 |    (AExp ~ ">" ~ AExp) ==> { case ((x, y), z) => Bop("<", z, x):BExp } | 
 | |
| 379 |    ("true" ==> ((_) => True:BExp )) | 
 | |
| 380 |    ("false" ==> ((_) => False:BExp )) |
 | |
| 381 |    ("(" ~ BExp ~ ")") ==> { case ((x, y), z) => y}
 | |
| 382 | ||
| 383 | lazy val Stmt: Parser[String, Stmt] = | |
| 384 |    ("skip" ==> (_ => Skip: Stmt)) |
 | |
| 385 |    (IdParser ~ ":=" ~ AExp) ==> { case ((x, y), z) => Assign(x, z): Stmt } |
 | |
| 386 |    (IdParser ~ "[" ~ AExp ~ "]" ~ ":=" ~ AExp) ==> { 
 | |
| 387 | case (((((x, y), z), v), w), u) => AssignA(x, z, u): Stmt } | | |
| 388 |    ("if" ~ BExp ~ "then" ~ Block ~ "else" ~ Block) ==>
 | |
| 389 |     { case (((((x,y),z),u),v),w) => If(y, u, w): Stmt } |
 | |
| 390 |    ("while" ~ BExp ~ "do" ~ Block) ==> { case (((x, y), z), w) => While(y, w) } |
 | |
| 391 |    ("new" ~ IdParser ~ "[" ~ NumParser ~ "]") ==> { case ((((x, y), z), u), v) => Array(y, u) } |
 | |
| 392 |    ("write" ~ IdParser) ==> { case (_, y) => Write(y) } 
 | |
| 393 | ||
| 394 | lazy val Stmts: Parser[String, Block] = | |
| 395 |   (Stmt ~ ";" ~ Stmts) ==> { case ((x, y), z) => x :: z : Block } |
 | |
| 396 | (Stmt ==> ((s) => List(s) : Block)) | |
| 611 | 397 | |
| 616 | 398 | |
| 399 | lazy val Block: Parser[String, Block] = | |
| 400 |    ("{" ~ Stmts ~ "}") ==> { case ((x, y), z) => y} | 
 | |
| 401 | (Stmt ==> (s => List(s))) | |
| 402 | ||
| 694 | 403 | //Stmts.parse_all("x2:=5+a")
 | 
| 404 | //Stmts.parse_all("x2:=5+a[3+a]")
 | |
| 405 | //Stmts.parse_all("a[x2+3]:=5+a[3+a]")
 | |
| 406 | //Block.parse_all("{x:=5;y:=8}")
 | |
| 407 | //Block.parse_all("if(false)then{x:=5}else{x:=10}")
 | |
| 616 | 408 | |
| 409 | ||
| 410 | ||
| 411 | val fib = """ | |
| 412 | n := 10; | |
| 413 | minus1 := 0; | |
| 414 | minus2 := 1; | |
| 415 | temp:=0; | |
| 416 |    while (n > 0) do {
 | |
| 417 | temp := minus2; | |
| 418 | minus2 := minus1 + minus2; | |
| 419 | minus1 := temp; | |
| 420 | n := n - 1}; | |
| 421 | result := minus2; | |
| 422 | write result | |
| 423 |    """.replaceAll("\\s+", "")
 | |
| 424 | ||
| 425 | val fib_prog = Stmts.parse_all(fib).toList | |
| 426 | //compile_run(fib_prog.head, "fib") | |
| 427 | ||
| 428 | ||
| 429 | // BF | |
| 430 | ||
| 431 | // simple instructions | |
| 432 | def instr(c: Char) : String = c match {
 | |
| 433 | case '>' => "ptr := ptr + 1;" | |
| 434 | case '<' => "ptr := ptr - 1;" | |
| 435 | case '+' => "field[ptr] := field[ptr] + 1;" | |
| 436 | case '-' => "field[ptr] := field[ptr] - 1;" | |
| 437 | case '.' => "x := field[ptr]; write x;" | |
| 438 | //case ',' => "XXX" // "ptr = getchar();\n" | |
| 439 |   case '['  => "while (field[ptr] != 0) do {"
 | |
| 440 | case ']' => "skip};" | |
| 441 | case _ => "" | |
| 442 | } | |
| 443 | ||
| 444 | def instrs(prog: String) : String = | |
| 445 | prog.toList.map(instr).mkString | |
| 446 | ||
| 447 | ||
| 448 | def splice(cs: List[Char], acc: List[(Char, Int)]) : List[(Char, Int)] = (cs, acc) match {
 | |
| 449 | case (Nil, acc) => acc | |
| 450 | case (c :: cs, Nil) => splice(cs, List((c, 1))) | |
| 451 | case (c :: cs, (d, n) :: acc) => | |
| 452 | if (c == d) splice(cs, (c, n + 1) :: acc) | |
| 453 | else splice(cs, (c, 1) :: (d, n) :: acc) | |
| 454 | } | |
| 455 | ||
| 456 | def spl(s: String) = splice(s.toList, Nil).reverse | |
| 457 | ||
| 458 | def instr2(c: Char, n: Int) : String = c match {
 | |
| 459 | case '>' => "ptr := ptr + " + n.toString + ";" | |
| 460 | case '<' => "ptr := ptr - " + n.toString + ";" | |
| 461 | case '+' => "field[ptr] := field[ptr] + " + n.toString + ";" | |
| 462 | case '-' => "field[ptr] := field[ptr] - " + n.toString + ";" | |
| 463 | case '.' => "x := field[ptr]; write x;" //* n | |
| 464 | //case ',' => "*ptr = getchar();\n" * n | |
| 465 |   case '['  => "while (field[ptr] != 0) do {" * n 
 | |
| 466 | case ']' => "skip};" * n | |
| 467 | case _ => "" | |
| 468 | } | |
| 469 | ||
| 470 | def instrs2(prog: String) : String = | |
| 471 |   spl(prog).map{ case (c, n) => instr2(c, n) }.mkString
 | |
| 472 | ||
| 473 | ||
| 474 | def bf_str(prog: String) : String = {
 | |
| 475 | "\n" ++ | |
| 476 | //"new field[30000];\n" ++ | |
| 477 | "ptr := 15000;" ++ | |
| 694 | 478 | instrs(prog) ++ | 
| 616 | 479 | "skip" | 
| 480 | } | |
| 481 | ||
| 482 | def bf_run(prog: String, name: String) = {
 | |
| 483 |   println("BF processing start")
 | |
| 484 |   val bf_string = bf_str(prog).replaceAll("\\s", "")
 | |
| 694 | 485 | |
| 616 | 486 |   println(s"BF parsing start (string length ${bf_string.length})")
 | 
| 487 | val bf_prog = Stmts.parse_all(bf_string).toList.head | |
| 694 | 488 |   println(s"BF Compile start ${bf_string.toList.length} characters")
 | 
| 616 | 489 |   compile_run(Array("field", 30000) :: bf_prog, name)
 | 
| 490 | } | |
| 491 | ||
| 694 | 492 | // a benchmark program (counts down from 'Z' to 'A') | 
| 493 | val bf0 = """>++[<+++++++++++++>-]<[[>+>+<<-]>[<+>-]++++++++ | |
| 494 | [>++++++++<-]>.[-]<<>++++++++++[>++++++++++[>++ | |
| 495 | ++++++++[>++++++++++[>++++++++++[>++++++++++[>+ | |
| 496 | +++++++++[-]<-]<-]<-]<-]<-]<-]<-]++++++++++.""" | |
| 497 | ||
| 498 | bf_run(bf0, "bench") | |
| 499 | ||
| 616 | 500 | |
| 501 | ||
| 502 | val bf1 = """++++++++[>+>++++<<-]>++>>+<[-[>>+<<-]+>>]>+[-<<<[ | |
| 503 | ->[+[-]+>++>>>-<<]<[<]>>++++++[<<+++++>>-]+<<++.[-]<< | |
| 504 | ]>.>+[>>]>+]""" | |
| 505 | ||
| 506 | bf_run(bf1, "sier") | |
| 507 | ||
| 508 | bf_run("""++++++++[>++++[>++>+++>+++>+<<<<-]>+>+>->>+[<]<-]>>.>---.+++++++
 | |
| 509 | ..+++.>>.<-.<.+++.------.--------.>>+.>++.""", "hello") | |
| 510 | ||
| 694 | 511 | |
| 512 | val bf2 = """+++++++++++ | |
| 616 | 513 | >+>>>>++++++++++++++++++++++++++++++++++++++++++++ | 
| 514 | >++++++++++++++++++++++++++++++++<<<<<<[>[>>>>>>+> | |
| 515 | +<<<<<<<-]>>>>>>>[<<<<<<<+>>>>>>>-]<[>++++++++++[- | |
| 516 | <-[>>+>+<<<-]>>>[<<<+>>>-]+<[>[-]<[-]]>[<<[>>>+<<< | |
| 517 | -]>>[-]]<<]>>>[>>+>+<<<-]>>>[<<<+>>>-]+<[>[-]<[-]] | |
| 518 | >[<<+>>[-]]<<<<<<<]>>>>>[+++++++++++++++++++++++++ | |
| 519 | +++++++++++++++++++++++.[-]]++++++++++<[->-<]>++++ | |
| 520 | ++++++++++++++++++++++++++++++++++++++++++++.[-]<< | |
| 521 | <<<<<<<<<<[>>>+>+<<<<-]>>>>[<<<<+>>>>-]<-[>>.>.<<< | |
| 694 | 522 | [-]]<<[>>+>+<<<-]>>>[<<<+>>>-]<<[<+>-]>[<+>-]<<<-]""" | 
| 523 | ||
| 524 | bf_run(bf2, "fibs") | |
| 525 | ||
| 695 
a936b1717b1b
deleted init function from boilerplate code
 Christian Urban <urbanc@in.tum.de> parents: 
694diff
changeset | 526 | /* | 
| 
a936b1717b1b
deleted init function from boilerplate code
 Christian Urban <urbanc@in.tum.de> parents: 
694diff
changeset | 527 | |
| 694 | 528 | |
| 529 | bf_run("""      A mandelbrot set fractal viewer in brainf*** written by Erik Bosman
 | |
| 530 | +++++++++++++[->++>>>+++++>++>+<<<<<<]>>>>>++++++>--->>>>>>>>>>+++++++++++++++[[ | |
| 531 | >>>>>>>>>]+[<<<<<<<<<]>>>>>>>>>-]+[>>>>>>>>[-]>]<<<<<<<<<[<<<<<<<<<]>>>>>>>>[-]+ | |
| 532 | <<<<<<<+++++[-[->>>>>>>>>+<<<<<<<<<]>>>>>>>>>]>>>>>>>+>>>>>>>>>>>>>>>>>>>>>>>>>> | |
| 533 | >+<<<<<<<<<<<<<<<<<[<<<<<<<<<]>>>[-]+[>>>>>>[>>>>>>>[-]>>]<<<<<<<<<[<<<<<<<<<]>> | |
| 534 | >>>>>[-]+<<<<<<++++[-[->>>>>>>>>+<<<<<<<<<]>>>>>>>>>]>>>>>>+<<<<<<+++++++[-[->>> | |
| 535 | >>>>>>+<<<<<<<<<]>>>>>>>>>]>>>>>>+<<<<<<<<<<<<<<<<[<<<<<<<<<]>>>[[-]>>>>>>[>>>>> | |
| 536 | >>[-<<<<<<+>>>>>>]<<<<<<[->>>>>>+<<+<<<+<]>>>>>>>>]<<<<<<<<<[<<<<<<<<<]>>>>>>>>> | |
| 537 | [>>>>>>>>[-<<<<<<<+>>>>>>>]<<<<<<<[->>>>>>>+<<+<<<+<<]>>>>>>>>]<<<<<<<<<[<<<<<<< | |
| 538 | <<]>>>>>>>[-<<<<<<<+>>>>>>>]<<<<<<<[->>>>>>>+<<+<<<<<]>>>>>>>>>+++++++++++++++[[ | |
| 539 | >>>>>>>>>]+>[-]>[-]>[-]>[-]>[-]>[-]>[-]>[-]>[-]<<<<<<<<<[<<<<<<<<<]>>>>>>>>>-]+[ | |
| 540 | >+>>>>>>>>]<<<<<<<<<[<<<<<<<<<]>>>>>>>>>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 | |
| 672 | +[-[->>>>>>>>>+<<<<<<<<<]>>>>>>>>>]>>>>>->>>>>>>>>>>>>>>>>>>>>>>>>>>-<<<<<<[<<<< | |
| 673 | <<<<<]]>>>]""", "mand") | |
| 674 | ||
| 695 
a936b1717b1b
deleted init function from boilerplate code
 Christian Urban <urbanc@in.tum.de> parents: 
694diff
changeset | 675 | */ |