progs/compile_arr3.scala
author Christian Urban <urbanc@in.tum.de>
Fri, 07 Feb 2020 11:32:47 +0000
changeset 712 e71eb9ce2373
parent 710 progs/compile_arr2.scala@183663740fb7
child 713 0ea14d84efe3
permissions -rw-r--r--
updated
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
609
e33545bb2eba updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     1
// A Small Compiler for the WHILE Language
707
2fcd7c2da729 updated
Christian Urban <urbanc@in.tum.de>
parents: 696
diff changeset
     2
//
694
b6ed836ce59b updated
Christian Urban <urbanc@in.tum.de>
parents: 616
diff changeset
     3
//  - includes arrays and a small parser for
707
2fcd7c2da729 updated
Christian Urban <urbanc@in.tum.de>
parents: 696
diff changeset
     4
//    WHILE programs
2fcd7c2da729 updated
Christian Urban <urbanc@in.tum.de>
parents: 696
diff changeset
     5
//
2fcd7c2da729 updated
Christian Urban <urbanc@in.tum.de>
parents: 696
diff changeset
     6
//  - transpiles BF programs into WHILE programs
2fcd7c2da729 updated
Christian Urban <urbanc@in.tum.de>
parents: 696
diff changeset
     7
//    and compiles and runs them
2fcd7c2da729 updated
Christian Urban <urbanc@in.tum.de>
parents: 696
diff changeset
     8
//
2fcd7c2da729 updated
Christian Urban <urbanc@in.tum.de>
parents: 696
diff changeset
     9
// Call with
2fcd7c2da729 updated
Christian Urban <urbanc@in.tum.de>
parents: 696
diff changeset
    10
//
710
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
    11
// scala compile_arr.scala
707
2fcd7c2da729 updated
Christian Urban <urbanc@in.tum.de>
parents: 696
diff changeset
    12
710
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
    13
// Mandelbrot
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
    14
// mand.j size       232266
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
    15
// mand.class size   21787
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
    16
// running time      16 secs
609
e33545bb2eba updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    17
e33545bb2eba updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    18
// the abstract syntax trees
e33545bb2eba updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    19
abstract class Stmt
e33545bb2eba updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    20
abstract class AExp
e33545bb2eba updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    21
abstract class BExp 
e33545bb2eba updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    22
type Block = List[Stmt]
e33545bb2eba updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    23
e33545bb2eba updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    24
// statements
e33545bb2eba updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    25
case object Skip extends Stmt
707
2fcd7c2da729 updated
Christian Urban <urbanc@in.tum.de>
parents: 696
diff changeset
    26
case class ArrayDef(s: String, n: Int) extends Stmt
609
e33545bb2eba updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    27
case class If(a: BExp, bl1: Block, bl2: Block) extends Stmt
e33545bb2eba updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    28
case class While(b: BExp, bl: Block) extends Stmt
707
2fcd7c2da729 updated
Christian Urban <urbanc@in.tum.de>
parents: 696
diff changeset
    29
case class Assign(s: String, a: AExp) extends Stmt             // var := exp
2fcd7c2da729 updated
Christian Urban <urbanc@in.tum.de>
parents: 696
diff changeset
    30
case class AssignA(s: String, a1: AExp, a2: AExp) extends Stmt // arr[exp1] := exp2
694
b6ed836ce59b updated
Christian Urban <urbanc@in.tum.de>
parents: 616
diff changeset
    31
case class Write(s: String) extends Stmt
b6ed836ce59b updated
Christian Urban <urbanc@in.tum.de>
parents: 616
diff changeset
    32
case class Read(s: String) extends Stmt
609
e33545bb2eba updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    33
e33545bb2eba updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    34
// arithmetic expressions
e33545bb2eba updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    35
case class Var(s: String) extends AExp
e33545bb2eba updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    36
case class Num(i: Int) extends AExp
e33545bb2eba updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    37
case class Aop(o: String, a1: AExp, a2: AExp) extends AExp
694
b6ed836ce59b updated
Christian Urban <urbanc@in.tum.de>
parents: 616
diff changeset
    38
case class Ref(s: String, a: AExp) extends AExp
609
e33545bb2eba updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    39
e33545bb2eba updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    40
// boolean expressions
e33545bb2eba updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    41
case object True extends BExp
e33545bb2eba updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    42
case object False extends BExp
e33545bb2eba updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    43
case class Bop(o: String, a1: AExp, a2: AExp) extends BExp
e33545bb2eba updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    44
e33545bb2eba updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    45
e33545bb2eba updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    46
// compiler headers needed for the JVM
e33545bb2eba updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    47
// (contains an init method, as well as methods for read and write)
e33545bb2eba updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    48
val beginning = """
e33545bb2eba updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    49
.class public XXX.XXX
e33545bb2eba updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    50
.super java/lang/Object
e33545bb2eba updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    51
e33545bb2eba updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    52
.method public static write(I)V 
e33545bb2eba updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    53
    .limit locals 1 
e33545bb2eba updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    54
    .limit stack 2 
e33545bb2eba updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    55
    getstatic java/lang/System/out Ljava/io/PrintStream; 
e33545bb2eba updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    56
    iload 0
694
b6ed836ce59b updated
Christian Urban <urbanc@in.tum.de>
parents: 616
diff changeset
    57
    i2c       ; Int => Char
b6ed836ce59b updated
Christian Urban <urbanc@in.tum.de>
parents: 616
diff changeset
    58
    invokevirtual java/io/PrintStream/print(C)V   ; println(I)V => print(C)V    
609
e33545bb2eba updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    59
    return 
e33545bb2eba updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    60
.end method
e33545bb2eba updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    61
e33545bb2eba updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    62
.method public static main([Ljava/lang/String;)V
e33545bb2eba updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    63
   .limit locals 200
e33545bb2eba updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    64
   .limit stack 200
e33545bb2eba updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    65
708
4980f421b3b0 updated
Christian Urban <urbanc@in.tum.de>
parents: 707
diff changeset
    66
; COMPILED CODE STARTS   
4980f421b3b0 updated
Christian Urban <urbanc@in.tum.de>
parents: 707
diff changeset
    67
609
e33545bb2eba updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    68
"""
e33545bb2eba updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    69
e33545bb2eba updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    70
val ending = """
708
4980f421b3b0 updated
Christian Urban <urbanc@in.tum.de>
parents: 707
diff changeset
    71
; COMPILED CODE ENDS
609
e33545bb2eba updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    72
   return
e33545bb2eba updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    73
e33545bb2eba updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    74
.end method
e33545bb2eba updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    75
"""
e33545bb2eba updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    76
694
b6ed836ce59b updated
Christian Urban <urbanc@in.tum.de>
parents: 616
diff changeset
    77
609
e33545bb2eba updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    78
e33545bb2eba updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    79
e33545bb2eba updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    80
// for generating new labels
e33545bb2eba updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    81
var counter = -1
e33545bb2eba updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    82
e33545bb2eba updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    83
def Fresh(x: String) = {
e33545bb2eba updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    84
  counter += 1
e33545bb2eba updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    85
  x ++ "_" ++ counter.toString()
e33545bb2eba updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    86
}
e33545bb2eba updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    87
e33545bb2eba updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    88
// environments and instructions
694
b6ed836ce59b updated
Christian Urban <urbanc@in.tum.de>
parents: 616
diff changeset
    89
type Env = Map[String, Int]
b6ed836ce59b updated
Christian Urban <urbanc@in.tum.de>
parents: 616
diff changeset
    90
b6ed836ce59b updated
Christian Urban <urbanc@in.tum.de>
parents: 616
diff changeset
    91
// convenient string interpolations 
b6ed836ce59b updated
Christian Urban <urbanc@in.tum.de>
parents: 616
diff changeset
    92
// for instructions and labels
b6ed836ce59b updated
Christian Urban <urbanc@in.tum.de>
parents: 616
diff changeset
    93
import scala.language.implicitConversions
b6ed836ce59b updated
Christian Urban <urbanc@in.tum.de>
parents: 616
diff changeset
    94
import scala.language.reflectiveCalls
b6ed836ce59b updated
Christian Urban <urbanc@in.tum.de>
parents: 616
diff changeset
    95
b6ed836ce59b updated
Christian Urban <urbanc@in.tum.de>
parents: 616
diff changeset
    96
implicit def sring_inters(sc: StringContext) = new {
b6ed836ce59b updated
Christian Urban <urbanc@in.tum.de>
parents: 616
diff changeset
    97
    def i(args: Any*): String = "   " ++ sc.s(args:_*) ++ "\n"
b6ed836ce59b updated
Christian Urban <urbanc@in.tum.de>
parents: 616
diff changeset
    98
    def l(args: Any*): String = sc.s(args:_*) ++ ":\n"
b6ed836ce59b updated
Christian Urban <urbanc@in.tum.de>
parents: 616
diff changeset
    99
}
b6ed836ce59b updated
Christian Urban <urbanc@in.tum.de>
parents: 616
diff changeset
   100
b6ed836ce59b updated
Christian Urban <urbanc@in.tum.de>
parents: 616
diff changeset
   101
def compile_op(op: String) = op match {
b6ed836ce59b updated
Christian Urban <urbanc@in.tum.de>
parents: 616
diff changeset
   102
  case "+" => i"iadd"
b6ed836ce59b updated
Christian Urban <urbanc@in.tum.de>
parents: 616
diff changeset
   103
  case "-" => i"isub"
b6ed836ce59b updated
Christian Urban <urbanc@in.tum.de>
parents: 616
diff changeset
   104
  case "*" => i"imul"
b6ed836ce59b updated
Christian Urban <urbanc@in.tum.de>
parents: 616
diff changeset
   105
}
609
e33545bb2eba updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   106
710
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   107
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   108
def compile_num(i: Int) = 
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   109
  if (0 <= i && i <= 5) i"iconst_$i" else 
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   110
  if (-128 <= i && i <= 127) i"bipush $i" else i"ldc $i"
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   111
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   112
def compile_aload(i: Int) = 
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   113
  if (0 <= i && i <= 3) i"aload_$i" else i"aload $i"
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   114
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   115
def compile_iload(i: Int) = 
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   116
  if (0 <= i && i <= 3) i"iload_$i" else i"iload $i"
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   117
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   118
def compile_istore(i: Int) = 
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   119
  if (0 <= i && i <= 3) i"istore_$i" else i"istore $i"
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   120
609
e33545bb2eba updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   121
// arithmetic expression compilation
694
b6ed836ce59b updated
Christian Urban <urbanc@in.tum.de>
parents: 616
diff changeset
   122
def compile_aexp(a: AExp, env : Env) : String = a match {
710
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   123
  case Num(i) => compile_num(i)
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   124
  case Var(s) => compile_iload(env(s))
694
b6ed836ce59b updated
Christian Urban <urbanc@in.tum.de>
parents: 616
diff changeset
   125
  case Aop(op, a1, a2) => 
b6ed836ce59b updated
Christian Urban <urbanc@in.tum.de>
parents: 616
diff changeset
   126
    compile_aexp(a1, env) ++ compile_aexp(a2, env) ++ compile_op(op)
712
e71eb9ce2373 updated
Christian Urban <urbanc@in.tum.de>
parents: 710
diff changeset
   127
  case Ref(s, a) => {
e71eb9ce2373 updated
Christian Urban <urbanc@in.tum.de>
parents: 710
diff changeset
   128
    val arr_safe = Fresh("Arr_safe")
e71eb9ce2373 updated
Christian Urban <urbanc@in.tum.de>
parents: 710
diff changeset
   129
    val arr_end = Fresh("Arr_end_")
e71eb9ce2373 updated
Christian Urban <urbanc@in.tum.de>
parents: 710
diff changeset
   130
    compile_aexp(a, env) ++
e71eb9ce2373 updated
Christian Urban <urbanc@in.tum.de>
parents: 710
diff changeset
   131
    compile_aload(env(s)) ++
e71eb9ce2373 updated
Christian Urban <urbanc@in.tum.de>
parents: 710
diff changeset
   132
    i"dup2" ++
e71eb9ce2373 updated
Christian Urban <urbanc@in.tum.de>
parents: 710
diff changeset
   133
    i"arraylength" ++
e71eb9ce2373 updated
Christian Urban <urbanc@in.tum.de>
parents: 710
diff changeset
   134
    i"if_icmple $arr_safe" ++
e71eb9ce2373 updated
Christian Urban <urbanc@in.tum.de>
parents: 710
diff changeset
   135
    i"pop2" ++
e71eb9ce2373 updated
Christian Urban <urbanc@in.tum.de>
parents: 710
diff changeset
   136
    i"iconst_0" ++
e71eb9ce2373 updated
Christian Urban <urbanc@in.tum.de>
parents: 710
diff changeset
   137
    i"goto $arr_end" ++
e71eb9ce2373 updated
Christian Urban <urbanc@in.tum.de>
parents: 710
diff changeset
   138
    l"$arr_safe" ++
e71eb9ce2373 updated
Christian Urban <urbanc@in.tum.de>
parents: 710
diff changeset
   139
    i"swap" ++
e71eb9ce2373 updated
Christian Urban <urbanc@in.tum.de>
parents: 710
diff changeset
   140
    i"iaload" ++
e71eb9ce2373 updated
Christian Urban <urbanc@in.tum.de>
parents: 710
diff changeset
   141
    l"$arr_end"
e71eb9ce2373 updated
Christian Urban <urbanc@in.tum.de>
parents: 710
diff changeset
   142
  }
609
e33545bb2eba updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   143
}
e33545bb2eba updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   144
708
4980f421b3b0 updated
Christian Urban <urbanc@in.tum.de>
parents: 707
diff changeset
   145
def compile_bop(op: String, jmp: String) = op match {
4980f421b3b0 updated
Christian Urban <urbanc@in.tum.de>
parents: 707
diff changeset
   146
  case "==" => i"if_icmpne $jmp"
4980f421b3b0 updated
Christian Urban <urbanc@in.tum.de>
parents: 707
diff changeset
   147
  case "!=" => i"if_icmpeq $jmp"
4980f421b3b0 updated
Christian Urban <urbanc@in.tum.de>
parents: 707
diff changeset
   148
  case "<"  => i"if_icmpge $jmp"
4980f421b3b0 updated
Christian Urban <urbanc@in.tum.de>
parents: 707
diff changeset
   149
}
4980f421b3b0 updated
Christian Urban <urbanc@in.tum.de>
parents: 707
diff changeset
   150
710
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   151
609
e33545bb2eba updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   152
// boolean expression compilation
694
b6ed836ce59b updated
Christian Urban <urbanc@in.tum.de>
parents: 616
diff changeset
   153
def compile_bexp(b: BExp, env : Env, jmp: String) : String = b match {
707
2fcd7c2da729 updated
Christian Urban <urbanc@in.tum.de>
parents: 696
diff changeset
   154
  case True => ""
694
b6ed836ce59b updated
Christian Urban <urbanc@in.tum.de>
parents: 616
diff changeset
   155
  case False => i"goto $jmp"
708
4980f421b3b0 updated
Christian Urban <urbanc@in.tum.de>
parents: 707
diff changeset
   156
  case Bop(op, a1, a2) => 
4980f421b3b0 updated
Christian Urban <urbanc@in.tum.de>
parents: 707
diff changeset
   157
    compile_aexp(a1, env) ++ compile_aexp(a2, env) ++ compile_bop(op, jmp)
609
e33545bb2eba updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   158
}
e33545bb2eba updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   159
e33545bb2eba updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   160
// statement compilation
694
b6ed836ce59b updated
Christian Urban <urbanc@in.tum.de>
parents: 616
diff changeset
   161
def compile_stmt(s: Stmt, env: Env) : (String, Env) = s match {
b6ed836ce59b updated
Christian Urban <urbanc@in.tum.de>
parents: 616
diff changeset
   162
  case Skip => ("", env)
609
e33545bb2eba updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   163
  case Assign(x, a) => {
710
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   164
     val index = env.getOrElse(x, env.keys.size) //
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   165
    (compile_aexp(a, env) ++ compile_istore(index), env + (x -> index)) 
609
e33545bb2eba updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   166
  } 
e33545bb2eba updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   167
  case If(b, bl1, bl2) => {
e33545bb2eba updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   168
    val if_else = Fresh("If_else")
e33545bb2eba updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   169
    val if_end = Fresh("If_end")
e33545bb2eba updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   170
    val (instrs1, env1) = compile_block(bl1, env)
e33545bb2eba updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   171
    val (instrs2, env2) = compile_block(bl2, env1)
e33545bb2eba updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   172
    (compile_bexp(b, env, if_else) ++
e33545bb2eba updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   173
     instrs1 ++
694
b6ed836ce59b updated
Christian Urban <urbanc@in.tum.de>
parents: 616
diff changeset
   174
     i"goto $if_end" ++
b6ed836ce59b updated
Christian Urban <urbanc@in.tum.de>
parents: 616
diff changeset
   175
     l"$if_else" ++
609
e33545bb2eba updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   176
     instrs2 ++
694
b6ed836ce59b updated
Christian Urban <urbanc@in.tum.de>
parents: 616
diff changeset
   177
     l"$if_end", env2)
609
e33545bb2eba updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   178
  }
e33545bb2eba updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   179
  case While(b, bl) => {
e33545bb2eba updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   180
    val loop_begin = Fresh("Loop_begin")
e33545bb2eba updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   181
    val loop_end = Fresh("Loop_end")
e33545bb2eba updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   182
    val (instrs1, env1) = compile_block(bl, env)
694
b6ed836ce59b updated
Christian Urban <urbanc@in.tum.de>
parents: 616
diff changeset
   183
    (l"$loop_begin" ++
609
e33545bb2eba updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   184
     compile_bexp(b, env, loop_end) ++
e33545bb2eba updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   185
     instrs1 ++
694
b6ed836ce59b updated
Christian Urban <urbanc@in.tum.de>
parents: 616
diff changeset
   186
     i"goto $loop_begin" ++
b6ed836ce59b updated
Christian Urban <urbanc@in.tum.de>
parents: 616
diff changeset
   187
     l"$loop_end", env1)
609
e33545bb2eba updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   188
  }
e33545bb2eba updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   189
  case Write(x) => 
710
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   190
    (compile_iload(env(x)) ++
694
b6ed836ce59b updated
Christian Urban <urbanc@in.tum.de>
parents: 616
diff changeset
   191
     i"invokestatic XXX/XXX/write(I)V", env)
b6ed836ce59b updated
Christian Urban <urbanc@in.tum.de>
parents: 616
diff changeset
   192
  case Read(x) => {
b6ed836ce59b updated
Christian Urban <urbanc@in.tum.de>
parents: 616
diff changeset
   193
    val index = env.getOrElse(x, env.keys.size) 
710
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   194
    (i"invokestatic XXX/XXX/read()I" ++     
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   195
     compile_istore(index), env + (x -> index))
694
b6ed836ce59b updated
Christian Urban <urbanc@in.tum.de>
parents: 616
diff changeset
   196
  }
707
2fcd7c2da729 updated
Christian Urban <urbanc@in.tum.de>
parents: 696
diff changeset
   197
  case ArrayDef(s: String, n: Int) => {
694
b6ed836ce59b updated
Christian Urban <urbanc@in.tum.de>
parents: 616
diff changeset
   198
    val index = if (env.isDefinedAt(s)) throw new Exception("array def error") else 
b6ed836ce59b updated
Christian Urban <urbanc@in.tum.de>
parents: 616
diff changeset
   199
                    env.keys.size
b6ed836ce59b updated
Christian Urban <urbanc@in.tum.de>
parents: 616
diff changeset
   200
    (i"ldc $n" ++
b6ed836ce59b updated
Christian Urban <urbanc@in.tum.de>
parents: 616
diff changeset
   201
     i"newarray int" ++
b6ed836ce59b updated
Christian Urban <urbanc@in.tum.de>
parents: 616
diff changeset
   202
     i"astore $index", env + (s -> index))
b6ed836ce59b updated
Christian Urban <urbanc@in.tum.de>
parents: 616
diff changeset
   203
  }
612
7a12053567d4 updated
Christian Urban <urbanc@in.tum.de>
parents: 611
diff changeset
   204
  case AssignA(s, a1, a2) => {
712
e71eb9ce2373 updated
Christian Urban <urbanc@in.tum.de>
parents: 710
diff changeset
   205
    val arr_safe = Fresh("Arr_safe")
e71eb9ce2373 updated
Christian Urban <urbanc@in.tum.de>
parents: 710
diff changeset
   206
    val arr_end = Fresh("Arr_end_")
612
7a12053567d4 updated
Christian Urban <urbanc@in.tum.de>
parents: 611
diff changeset
   207
    val index = if (env.isDefinedAt(s)) env(s) else 
694
b6ed836ce59b updated
Christian Urban <urbanc@in.tum.de>
parents: 616
diff changeset
   208
                    throw new Exception("array not defined")
712
e71eb9ce2373 updated
Christian Urban <urbanc@in.tum.de>
parents: 710
diff changeset
   209
    (compile_aexp(a1, env) ++
e71eb9ce2373 updated
Christian Urban <urbanc@in.tum.de>
parents: 710
diff changeset
   210
     compile_aload(env(s)) ++
e71eb9ce2373 updated
Christian Urban <urbanc@in.tum.de>
parents: 710
diff changeset
   211
     i"dup2" ++
e71eb9ce2373 updated
Christian Urban <urbanc@in.tum.de>
parents: 710
diff changeset
   212
     i"arraylength" ++
e71eb9ce2373 updated
Christian Urban <urbanc@in.tum.de>
parents: 710
diff changeset
   213
     i"if_icmple $arr_safe" ++
e71eb9ce2373 updated
Christian Urban <urbanc@in.tum.de>
parents: 710
diff changeset
   214
     i"pop2" ++
e71eb9ce2373 updated
Christian Urban <urbanc@in.tum.de>
parents: 710
diff changeset
   215
     i"goto $arr_end" ++
e71eb9ce2373 updated
Christian Urban <urbanc@in.tum.de>
parents: 710
diff changeset
   216
     l"$arr_safe" ++
e71eb9ce2373 updated
Christian Urban <urbanc@in.tum.de>
parents: 710
diff changeset
   217
     i"swap" ++
612
7a12053567d4 updated
Christian Urban <urbanc@in.tum.de>
parents: 611
diff changeset
   218
     compile_aexp(a2, env) ++
712
e71eb9ce2373 updated
Christian Urban <urbanc@in.tum.de>
parents: 710
diff changeset
   219
     i"iastore" ++
e71eb9ce2373 updated
Christian Urban <urbanc@in.tum.de>
parents: 710
diff changeset
   220
     l"$arr_end", env)
612
7a12053567d4 updated
Christian Urban <urbanc@in.tum.de>
parents: 611
diff changeset
   221
  } 
609
e33545bb2eba updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   222
}
e33545bb2eba updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   223
707
2fcd7c2da729 updated
Christian Urban <urbanc@in.tum.de>
parents: 696
diff changeset
   224
// compilation of a block (i.e. list of statements)
694
b6ed836ce59b updated
Christian Urban <urbanc@in.tum.de>
parents: 616
diff changeset
   225
def compile_block(bl: Block, env: Env) : (String, Env) = bl match {
b6ed836ce59b updated
Christian Urban <urbanc@in.tum.de>
parents: 616
diff changeset
   226
  case Nil => ("", env)
609
e33545bb2eba updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   227
  case s::bl => {
e33545bb2eba updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   228
    val (instrs1, env1) = compile_stmt(s, env)
e33545bb2eba updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   229
    val (instrs2, env2) = compile_block(bl, env1)
e33545bb2eba updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   230
    (instrs1 ++ instrs2, env2)
e33545bb2eba updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   231
  }
e33545bb2eba updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   232
}
e33545bb2eba updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   233
694
b6ed836ce59b updated
Christian Urban <urbanc@in.tum.de>
parents: 616
diff changeset
   234
609
e33545bb2eba updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   235
// main compilation function for blocks
e33545bb2eba updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   236
def compile(bl: Block, class_name: String) : String = {
707
2fcd7c2da729 updated
Christian Urban <urbanc@in.tum.de>
parents: 696
diff changeset
   237
  val instructions = compile_block(bl, Map())._1
2fcd7c2da729 updated
Christian Urban <urbanc@in.tum.de>
parents: 696
diff changeset
   238
  (beginning ++ instructions ++ ending).replaceAllLiterally("XXX", class_name)
609
e33545bb2eba updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   239
}
e33545bb2eba updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   240
e33545bb2eba updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   241
710
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   242
// Fibonacci numbers as a test-case
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   243
val fib_test = 
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   244
  List(Read("n"),                       //  read n;                     
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   245
       Assign("minus1",Num(0)),         //  minus1 := 0;
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   246
       Assign("minus2",Num(1)),         //  minus2 := 1;
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   247
       Assign("temp",Num(0)),           //  temp := 0;
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   248
       While(Bop("<",Num(0),Var("n")),  //  while n > 0 do  {
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   249
          List(Assign("temp",Var("minus2")),    //  temp := minus2;
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   250
               Assign("minus2",Aop("+",Var("minus1"),Var("minus2"))), 
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   251
                                        //  minus2 := minus1 + minus2;
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   252
               Assign("minus1",Var("temp")), //  minus1 := temp;
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   253
               Assign("n",Aop("-",Var("n"),Num(1))))), //  n := n - 1 };
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   254
       Write("minus1"))                 //  write minus1
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   255
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   256
// prints out the JVM-assembly instructions for fib
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   257
//
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   258
// println(compile(fib_test, "fib"))
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   259
//
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   260
// can be assembled by hand with 
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   261
//
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   262
//    java -jar jvm/jasmin-2.4/jasmin.jar fib.j
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   263
//
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   264
// and started with
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   265
//
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   266
//    java fib/fib
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   267
609
e33545bb2eba updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   268
import scala.util._
e33545bb2eba updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   269
import scala.sys.process._
e33545bb2eba updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   270
e33545bb2eba updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   271
def time_needed[T](i: Int, code: => T) = {
e33545bb2eba updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   272
  val start = System.nanoTime()
707
2fcd7c2da729 updated
Christian Urban <urbanc@in.tum.de>
parents: 696
diff changeset
   273
  for (j <- 2 to i) code
2fcd7c2da729 updated
Christian Urban <urbanc@in.tum.de>
parents: 696
diff changeset
   274
  val result = code
609
e33545bb2eba updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   275
  val end = System.nanoTime()
707
2fcd7c2da729 updated
Christian Urban <urbanc@in.tum.de>
parents: 696
diff changeset
   276
  ((end - start) / (i * 1.0e9), result)
2fcd7c2da729 updated
Christian Urban <urbanc@in.tum.de>
parents: 696
diff changeset
   277
}
2fcd7c2da729 updated
Christian Urban <urbanc@in.tum.de>
parents: 696
diff changeset
   278
2fcd7c2da729 updated
Christian Urban <urbanc@in.tum.de>
parents: 696
diff changeset
   279
def compile_to_file(bl: Block, class_name: String) : Unit = 
2fcd7c2da729 updated
Christian Urban <urbanc@in.tum.de>
parents: 696
diff changeset
   280
  Using(new java.io.FileWriter(class_name + ".j")) {
2fcd7c2da729 updated
Christian Urban <urbanc@in.tum.de>
parents: 696
diff changeset
   281
    _.write(compile(bl, class_name))
2fcd7c2da729 updated
Christian Urban <urbanc@in.tum.de>
parents: 696
diff changeset
   282
  }
2fcd7c2da729 updated
Christian Urban <urbanc@in.tum.de>
parents: 696
diff changeset
   283
2fcd7c2da729 updated
Christian Urban <urbanc@in.tum.de>
parents: 696
diff changeset
   284
def compile_and_run(bl: Block, class_name: String) : Unit = {
2fcd7c2da729 updated
Christian Urban <urbanc@in.tum.de>
parents: 696
diff changeset
   285
  println(s"Start compilation of $class_name")
2fcd7c2da729 updated
Christian Urban <urbanc@in.tum.de>
parents: 696
diff changeset
   286
  compile_to_file(bl, class_name)
2fcd7c2da729 updated
Christian Urban <urbanc@in.tum.de>
parents: 696
diff changeset
   287
  println("generated .j file")
2fcd7c2da729 updated
Christian Urban <urbanc@in.tum.de>
parents: 696
diff changeset
   288
  (s"java -jar jvm/jasmin-2.4/jasmin.jar ${class_name}.j").!!
2fcd7c2da729 updated
Christian Urban <urbanc@in.tum.de>
parents: 696
diff changeset
   289
  println("generated .class file ")
710
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   290
  println("Time: " + time_needed(3, (s"java ${class_name}/${class_name}").!)._1)
609
e33545bb2eba updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   291
}
e33545bb2eba updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   292
e33545bb2eba updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   293
694
b6ed836ce59b updated
Christian Urban <urbanc@in.tum.de>
parents: 616
diff changeset
   294
val arr_test = 
710
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   295
  List(ArrayDef("a", 10),
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   296
       ArrayDef("b", 2),
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   297
       AssignA("a", Num(0), Num(10)),
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   298
       Assign("x", Ref("a", Num(0))),
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   299
       Write("x"),
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   300
       AssignA("b", Num(1), Num(5)),
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   301
       Assign("x", Ref("b", Num(1))),
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   302
       Write("x"))       
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   303
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   304
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   305
//compile_and_run(arr_test, "a")
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   306
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   307
//====================
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   308
// Parser Combinators
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   309
//====================
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   310
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   311
import scala.language.implicitConversions
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   312
import scala.language.reflectiveCalls
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   313
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   314
// more convenience for the semantic actions later on
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   315
case class ~[+A, +B](_1: A, _2: B)
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   316
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   317
type IsSeq[A] = A => Seq[_]
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   318
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   319
abstract class Parser[I : IsSeq, T] {
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   320
  def parse(ts: I): Set[(T, I)]
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   321
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   322
  def parse_all(ts: I) : Set[T] =
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   323
    for ((head, tail) <- parse(ts); if (tail.isEmpty)) yield head
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   324
}
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   325
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   326
class SeqParser[I : IsSeq, T, S](p: => Parser[I, T], q: => Parser[I, S]) extends Parser[I, ~[T, S]] {
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   327
  def parse(sb: I) = 
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   328
    for ((head1, tail1) <- p.parse(sb); 
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   329
         (head2, tail2) <- q.parse(tail1)) yield (new ~(head1, head2), tail2)
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   330
}
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   331
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   332
class AltParser[I : IsSeq, T](p: => Parser[I, T], q: => Parser[I, T]) extends Parser[I, T] {
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   333
  def parse(sb: I) = p.parse(sb) ++ q.parse(sb)   
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   334
}
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   335
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   336
class FunParser[I : IsSeq, T, S](p: => Parser[I, T], f: T => S) extends Parser[I, S] {
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   337
  def parse(sb: I) = 
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   338
    for ((head, tail) <- p.parse(sb)) yield (f(head), tail)
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   339
}
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   340
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   341
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   342
import scala.util.matching.Regex
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   343
case class RegexParser(reg: Regex) extends Parser[String, String] {
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   344
  def parse(sb: String) = reg.findPrefixMatchOf(sb) match {
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   345
    case None => Set()
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   346
    case Some(m) => Set((m.matched, m.after.toString))  
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   347
  }
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   348
}
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   349
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   350
def StringParser(s: String) = RegexParser(Regex.quote(s).r)
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   351
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   352
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   353
implicit def string2parser(s : String) = StringParser(s)
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   354
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   355
implicit def ParserOps[I : IsSeq, T](p: Parser[I, T]) = new {
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   356
  def | (q : => Parser[I, T]) = new AltParser[I, T](p, q)
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   357
  def ==>[S] (f: => T => S) = new FunParser[I, T, S](p, f)
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   358
  def ~[S] (q : => Parser[I, S]) = new SeqParser[I, T, S](p, q)
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   359
}
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   360
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   361
implicit def StringOps(s: String) = new {
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   362
  def | (q : => Parser[String, String]) = new AltParser[String, String](s, q)
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   363
  def | (r: String) = new AltParser[String, String](s, r)
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   364
  def ==>[S] (f: => String => S) = new FunParser[String, String, S](s, f)
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   365
  def ~[S](q : => Parser[String, S]) = 
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   366
    new SeqParser[String, String, S](s, q)
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   367
  def ~ (r: String) = 
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   368
    new SeqParser[String, String, String](s, r)
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   369
}
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   370
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   371
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   372
val NumParser = RegexParser("[0-9]+".r) ==> (s => s.toInt : Int)
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   373
val IdParser = RegexParser("[a-z][a-z,0-9]*".r)
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   374
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   375
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   376
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   377
// Grammar Rules for WHILE with arrays
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   378
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   379
lazy val AExp: Parser[String, AExp] = 
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   380
  (Te ~ "+" ~ AExp) ==> { case x ~ _ ~ z => Aop("+", x, z):AExp } |
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   381
  (Te ~ "-" ~ AExp) ==> { case x ~ _ ~ z => Aop("-", x, z):AExp } | Te
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   382
lazy val Te: Parser[String, AExp] = 
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   383
  (Fa ~ "*" ~ Te) ==> { case x ~ _ ~ z => Aop("*", x, z):AExp } | Fa
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   384
lazy val Fa: Parser[String, AExp] = 
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   385
   ("(" ~ AExp ~ ")") ==> { case _ ~ y ~ _ => y } | 
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   386
   (IdParser ~ "[" ~ AExp ~ "]") ==> { case x ~ _ ~ y ~ _ => Ref(x, y) } |
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   387
   IdParser ==> Var | 
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   388
   NumParser ==> Num
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   389
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   390
// boolean expressions
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   391
lazy val BExp: Parser[String, BExp] = 
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   392
   (AExp ~ "=" ~ AExp) ==> { case x ~ y ~ z => Bop("=", x, z):BExp } | 
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   393
   (AExp ~ "!=" ~ AExp) ==> { case x ~ y ~ z => Bop("!=", x, z):BExp } | 
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   394
   (AExp ~ "<" ~ AExp) ==> { case x ~ y ~ z => Bop("<", x, z):BExp } | 
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   395
   (AExp ~ ">" ~ AExp) ==> { case x ~ y ~ z => Bop("<", z, x):BExp } | 
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   396
   ("true" ==> ((_) => True:BExp )) | 
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   397
   ("false" ==> ((_) => False:BExp )) |
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   398
   ("(" ~ BExp ~ ")") ==> { case x ~ y ~ z => y}
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   399
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   400
lazy val Stmt: Parser[String, Stmt] =
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   401
   ("skip" ==> (_ => Skip: Stmt)) |
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   402
   (IdParser ~ ":=" ~ AExp) ==> { case x ~ y ~z => Assign(x, z): Stmt } |
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   403
   (IdParser ~ "[" ~ AExp ~ "]" ~ ":=" ~ AExp) ==> { 
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   404
     case x ~ _ ~ z ~ _ ~ _ ~ u => AssignA(x, z, u): Stmt } |
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   405
   ("if" ~ BExp ~ "then" ~ Block ~ "else" ~ Block) ==>
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   406
    { case _ ~ y ~ _ ~ u ~ _ ~w => If(y, u, w): Stmt } |
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   407
   ("while" ~ BExp ~ "do" ~ Block) ==> { case _ ~ y ~ _ ~ w => While(y, w) } |
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   408
   ("new(" ~ IdParser ~ "[" ~ NumParser ~ "])") ==> { 
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   409
    case _ ~ y ~ _ ~ u ~ _ => ArrayDef(y, u) } |
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   410
   ("write" ~ IdParser) ==> { case _ ~ y => Write(y) } 
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   411
 
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   412
lazy val Stmts: Parser[String, Block] =
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   413
  (Stmt ~ ";" ~ Stmts) ==> { case x ~ _ ~ z => x :: z : Block } |
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   414
  (Stmt ==> ((s) => List(s) : Block)) 
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   415
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   416
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   417
lazy val Block: Parser[String, Block] =
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   418
   ("{" ~ Stmts ~ "}") ==> { case _ ~ y ~ _ => y} | 
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   419
   (Stmt ==> (s => List(s)))
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   420
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   421
//Stmts.parse_all("x2:=5+a")
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   422
//Stmts.parse_all("x2:=5+a[3+a]")
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   423
//Stmts.parse_all("a[x2+3]:=5+a[3+a]")
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   424
//Block.parse_all("{x:=5;y:=8}")
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   425
//Block.parse_all("if(false)then{x:=5}else{x:=10}")
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   426
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   427
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   428
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   429
val fib = """
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   430
   n := 10;
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   431
   minus1 := 0;
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   432
   minus2 := 1;
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   433
   temp:=0;
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   434
   while (n > 0) do {
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   435
     temp := minus2; 
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   436
     minus2 := minus1 + minus2;
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   437
     minus1 := temp;
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   438
     n := n - 1};
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   439
   result := minus2;
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   440
   write result
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   441
   """.replaceAll("\\s+", "")
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   442
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   443
val fib_prog = Stmts.parse_all(fib).toList
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   444
//compile_and_run(fib_prog.head, "fib")
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   445
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   446
//======================================
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   447
// BF transpiler into WHILE with arrays
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   448
//======================================
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   449
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   450
// simple BF instructions translation
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   451
def instr(c: Char) : String = c match {
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   452
  case '>' => "ptr := ptr + 1;"
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   453
  case '<' => "ptr := ptr - 1;"
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   454
  case '+' => "mem[ptr] := mem[ptr] + 1;"
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   455
  case '-' => "mem[ptr] := mem[ptr] - 1;"
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   456
  case '.' => "x := mem[ptr]; write x;"
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   457
  //case ',' => "XXX" // "ptr = getchar();\n"
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   458
  case '['  => "while (mem[ptr] != 0) do {"
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   459
  case ']'  => "skip};"
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   460
  case _ => ""
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   461
}
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   462
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   463
def instrs(prog: String) : String =
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   464
  prog.toList.map(instr).mkString
616
24bbe4e4b37b updated
Christian Urban <urbanc@in.tum.de>
parents: 612
diff changeset
   465
24bbe4e4b37b updated
Christian Urban <urbanc@in.tum.de>
parents: 612
diff changeset
   466
710
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   467
// Note: the mandelbrot.bf program is so large that
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   468
// it does not fit inside the limitations of what the
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   469
// JVM imposes on methods (only 64K of instructions).
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   470
// Therefore some optimisations are first applied to 
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   471
// BF programs before WHILE programs are created. The
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   472
// optimisations are 
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   473
//  
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   474
//  - replacing BF-loops of the form [-] 
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   475
//  - combining single increment/decrement instructions
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   476
//
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   477
// The size of the resulting .j-file is 270K.
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   478
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   479
def splice(cs: List[Char], acc: List[(Char, Int)]) : List[(Char, Int)] = (cs, acc) match {
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   480
  case (Nil, acc) => acc
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   481
  case (c :: cs, Nil) => splice(cs, List((c, 1)))
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   482
  case (c :: cs, (d, n) :: acc) => 
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   483
    if (c == d) splice(cs, (c, n + 1) :: acc)
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   484
    else splice(cs, (c, 1) :: (d, n) :: acc)
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   485
}
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   486
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   487
def spl(s: String) = splice(s.toList, Nil).reverse
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   488
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   489
def instr2(c: Char, n: Int) : String = c match {
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   490
  case '>' => s"ptr := ptr + $n;"
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   491
  case '<' => s"ptr := ptr - $n;"
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   492
  case '0' => s"mem[ptr] := 0;"
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   493
  case '+' => s"mem[ptr] := mem[ptr] + $n;"
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   494
  case '-' => s"mem[ptr] := mem[ptr] - $n;"
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   495
  case '.' => s"x := mem[ptr]; write x;" 
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   496
  case '['  => "while (mem[ptr] != 0) do {" * n 
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   497
  case ']'  => "skip};" * n
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   498
  case _ => ""
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   499
}
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   500
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   501
def instrs2(prog: String) : String =
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   502
  spl(prog.replaceAll("""\[-\]""", "0")).map{ case (c, n) => instr2(c, n) }.mkString
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   503
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   504
def bf_str(prog: String) : String = {
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   505
  "new(mem[30000]);" ++
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   506
  "ptr := 15000;" ++
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   507
  instrs2(prog) ++
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   508
  "skip"
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   509
}
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   510
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   511
def bf_run(prog: String, name: String) = {
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   512
  println(s"BF pre-processing of $name")
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   513
  val bf_string = bf_str(prog).replaceAll("\\s", "")
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   514
  println(s"BF parsing (program length ${bf_string.length} characters)")
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   515
  val (time, bf_prog) = time_needed(1, Stmts.parse_all(bf_string).toList.head)
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   516
  println(s"BF generated WHILE program (needed $time for parsing)")
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   517
  compile_and_run(bf_prog, name)
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   518
}
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   519
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   520
// a benchmark program (counts down from 'Z' to 'A')
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   521
val bf0 = """>++[<+++++++++++++>-]<[[>+>+<<-]>[<+>-]++++++++
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   522
            [>++++++++<-]>.[-]<<>++++++++++[>++++++++++[>++
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   523
            ++++++++[>++++++++++[>++++++++++[>++++++++++[>+
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   524
            +++++++++[-]<-]<-]<-]<-]<-]<-]<-]++++++++++."""
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   525
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   526
bf_run(bf0, "bench")
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   527
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   528
// Sierpinski triangle
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   529
val bf1 = """++++++++[>+>++++<<-]>++>>+<[-[>>+<<-]+>>]>+[-<<<[
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   530
      ->[+[-]+>++>>>-<<]<[<]>>++++++[<<+++++>>-]+<<++.[-]<<
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   531
      ]>.>+[>>]>+]"""
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   532
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   533
bf_run(bf1, "sier")
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   534
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   535
// Helo World!
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   536
bf_run("""++++++++[>++++[>++>+++>+++>+<<<<-]>+>+>->>+[<]<-]>>.>---.+++++++
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   537
       ..+++.>>.<-.<.+++.------.--------.>>+.>++.""", "hello")
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   538
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   539
// Fibonacci 
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   540
val bf2 = """+++++++++++
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   541
      >+>>>>++++++++++++++++++++++++++++++++++++++++++++
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   542
      >++++++++++++++++++++++++++++++++<<<<<<[>[>>>>>>+>
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   543
      +<<<<<<<-]>>>>>>>[<<<<<<<+>>>>>>>-]<[>++++++++++[-
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   544
      <-[>>+>+<<<-]>>>[<<<+>>>-]+<[>[-]<[-]]>[<<[>>>+<<<
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   545
      -]>>[-]]<<]>>>[>>+>+<<<-]>>>[<<<+>>>-]+<[>[-]<[-]]
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   546
      >[<<+>>[-]]<<<<<<<]>>>>>[+++++++++++++++++++++++++
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   547
      +++++++++++++++++++++++.[-]]++++++++++<[->-<]>++++
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   548
      ++++++++++++++++++++++++++++++++++++++++++++.[-]<<
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   549
      <<<<<<<<<<[>>>+>+<<<<-]>>>>[<<<<+>>>>-]<-[>>.>.<<<
712
e71eb9ce2373 updated
Christian Urban <urbanc@in.tum.de>
parents: 710
diff changeset
   550
      [-]]<<[>>+>+<<<-]>>>[<<<+>>>-]<<[<+>-]>[<+>-]<<<-]
e71eb9ce2373 updated
Christian Urban <urbanc@in.tum.de>
parents: 710
diff changeset
   551
      [-]++++++++++."""
710
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   552
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   553
bf_run(bf2, "fibs")
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   554
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   555
// Mandelbrot Set
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   556
//----------------
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   557
//
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   558
// Note: Parsing of the generated WHILE program (around 60K in size)
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   559
// takes approximately 10 minutes
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   560
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   561
694
b6ed836ce59b updated
Christian Urban <urbanc@in.tum.de>
parents: 616
diff changeset
   562
710
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   563
bf_run("""A mandelbrot set fractal viewer in brainf*** written by Erik Bosman
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   564
+++++++++++++[->++>>>+++++>++>+<<<<<<]>>>>>++++++>--->>>>>>>>>>+++++++++++++++[[
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   565
>>>>>>>>>]+[<<<<<<<<<]>>>>>>>>>-]+[>>>>>>>>[-]>]<<<<<<<<<[<<<<<<<<<]>>>>>>>>[-]+
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   566
<<<<<<<+++++[-[->>>>>>>>>+<<<<<<<<<]>>>>>>>>>]>>>>>>>+>>>>>>>>>>>>>>>>>>>>>>>>>>
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   567
>+<<<<<<<<<<<<<<<<<[<<<<<<<<<]>>>[-]+[>>>>>>[>>>>>>>[-]>>]<<<<<<<<<[<<<<<<<<<]>>
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   568
>>>>>[-]+<<<<<<++++[-[->>>>>>>>>+<<<<<<<<<]>>>>>>>>>]>>>>>>+<<<<<<+++++++[-[->>>
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   569
>>>>>>+<<<<<<<<<]>>>>>>>>>]>>>>>>+<<<<<<<<<<<<<<<<[<<<<<<<<<]>>>[[-]>>>>>>[>>>>>
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   570
>>[-<<<<<<+>>>>>>]<<<<<<[->>>>>>+<<+<<<+<]>>>>>>>>]<<<<<<<<<[<<<<<<<<<]>>>>>>>>>
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   571
[>>>>>>>>[-<<<<<<<+>>>>>>>]<<<<<<<[->>>>>>>+<<+<<<+<<]>>>>>>>>]<<<<<<<<<[<<<<<<<
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   572
<<]>>>>>>>[-<<<<<<<+>>>>>>>]<<<<<<<[->>>>>>>+<<+<<<<<]>>>>>>>>>+++++++++++++++[[
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   573
>>>>>>>>>]+>[-]>[-]>[-]>[-]>[-]>[-]>[-]>[-]>[-]<<<<<<<<<[<<<<<<<<<]>>>>>>>>>-]+[
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   574
>+>>>>>>>>]<<<<<<<<<[<<<<<<<<<]>>>>>>>>>[>->>>>[-<<<<+>>>>]<<<<[->>>>+<<<<<[->>[
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   575
-<<+>>]<<[->>+>>+<<<<]+>>>>>>>>>]<<<<<<<<[<<<<<<<<<]]>>>>>>>>>[>>>>>>>>>]<<<<<<<
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   576
<<[>[->>>>>>>>>+<<<<<<<<<]<<<<<<<<<<]>[->>>>>>>>>+<<<<<<<<<]<+>>>>>>>>]<<<<<<<<<
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   577
[>[-]<->>>>[-<<<<+>[<->-<<<<<<+>>>>>>]<[->+<]>>>>]<<<[->>>+<<<]<+<<<<<<<<<]>>>>>
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   578
>>>>[>+>>>>>>>>]<<<<<<<<<[<<<<<<<<<]>>>>>>>>>[>->>>>>[-<<<<<+>>>>>]<<<<<[->>>>>+
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   579
<<<<<<[->>>[-<<<+>>>]<<<[->>>+>+<<<<]+>>>>>>>>>]<<<<<<<<[<<<<<<<<<]]>>>>>>>>>[>>
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   580
>>>>>>>]<<<<<<<<<[>>[->>>>>>>>>+<<<<<<<<<]<<<<<<<<<<<]>>[->>>>>>>>>+<<<<<<<<<]<<
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   581
+>>>>>>>>]<<<<<<<<<[>[-]<->>>>[-<<<<+>[<->-<<<<<<+>>>>>>]<[->+<]>>>>]<<<[->>>+<<
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   582
<]<+<<<<<<<<<]>>>>>>>>>[>>>>[-<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<+>>>>>>>>>>>>>
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   583
>>>>>>>>>>>>>>>>>>>>>>>]>>>>>]<<<<<<<<<[<<<<<<<<<]>>>>>>>>>+++++++++++++++[[>>>>
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   584
>>>>>]<<<<<<<<<-<<<<<<<<<[<<<<<<<<<]>>>>>>>>>-]+>>>>>>>>>>>>>>>>>>>>>+<<<[<<<<<<
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   585
<<<]>>>>>>>>>[>>>[-<<<->>>]+<<<[->>>->[-<<<<+>>>>]<<<<[->>>>+<<<<<<<<<<<<<[<<<<<
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   586
<<<<]>>>>[-]+>>>>>[>>>>>>>>>]>+<]]+>>>>[-<<<<->>>>]+<<<<[->>>>-<[-<<<+>>>]<<<[->
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   587
>>+<<<<<<<<<<<<[<<<<<<<<<]>>>[-]+>>>>>>[>>>>>>>>>]>[-]+<]]+>[-<[>>>>>>>>>]<<<<<<
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   588
<<]>>>>>>>>]<<<<<<<<<[<<<<<<<<<]<<<<<<<[->+>>>-<<<<]>>>>>>>>>+++++++++++++++++++
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   589
+++++++>>[-<<<<+>>>>]<<<<[->>>>+<<[-]<<]>>[<<<<<<<+<[-<+>>>>+<<[-]]>[-<<[->+>>>-
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   590
<<<<]>>>]>>>>>>>>>>>>>[>>[-]>[-]>[-]>>>>>]<<<<<<<<<[<<<<<<<<<]>>>[-]>>>>>>[>>>>>
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   591
[-<<<<+>>>>]<<<<[->>>>+<<<+<]>>>>>>>>]<<<<<<<<<[<<<<<<<<<]>>>>>>>>>[>>[-<<<<<<<<
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   592
<+>>>>>>>>>]>>>>>>>]<<<<<<<<<[<<<<<<<<<]>>>>>>>>>+++++++++++++++[[>>>>>>>>>]+>[-
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   593
]>[-]>[-]>[-]>[-]>[-]>[-]>[-]>[-]<<<<<<<<<[<<<<<<<<<]>>>>>>>>>-]+[>+>>>>>>>>]<<<
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   594
<<<<<<[<<<<<<<<<]>>>>>>>>>[>->>>>>[-<<<<<+>>>>>]<<<<<[->>>>>+<<<<<<[->>[-<<+>>]<
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   595
<[->>+>+<<<]+>>>>>>>>>]<<<<<<<<[<<<<<<<<<]]>>>>>>>>>[>>>>>>>>>]<<<<<<<<<[>[->>>>
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   596
>>>>>+<<<<<<<<<]<<<<<<<<<<]>[->>>>>>>>>+<<<<<<<<<]<+>>>>>>>>]<<<<<<<<<[>[-]<->>>
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   597
[-<<<+>[<->-<<<<<<<+>>>>>>>]<[->+<]>>>]<<[->>+<<]<+<<<<<<<<<]>>>>>>>>>[>>>>>>[-<
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   598
<<<<+>>>>>]<<<<<[->>>>>+<<<<+<]>>>>>>>>]<<<<<<<<<[<<<<<<<<<]>>>>>>>>>[>+>>>>>>>>
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   599
]<<<<<<<<<[<<<<<<<<<]>>>>>>>>>[>->>>>>[-<<<<<+>>>>>]<<<<<[->>>>>+<<<<<<[->>[-<<+
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   600
>>]<<[->>+>>+<<<<]+>>>>>>>>>]<<<<<<<<[<<<<<<<<<]]>>>>>>>>>[>>>>>>>>>]<<<<<<<<<[>
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   601
[->>>>>>>>>+<<<<<<<<<]<<<<<<<<<<]>[->>>>>>>>>+<<<<<<<<<]<+>>>>>>>>]<<<<<<<<<[>[-
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   602
]<->>>>[-<<<<+>[<->-<<<<<<+>>>>>>]<[->+<]>>>>]<<<[->>>+<<<]<+<<<<<<<<<]>>>>>>>>>
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   603
[>>>>[-<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<+>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   604
]>>>>>]<<<<<<<<<[<<<<<<<<<]>>>>>>>>>[>>>[-<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<+>
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   605
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>]>>>>>>]<<<<<<<<<[<<<<<<<<<]>>>>>>>>>++++++++
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   606
+++++++[[>>>>>>>>>]<<<<<<<<<-<<<<<<<<<[<<<<<<<<<]>>>>>>>>>-]+[>>>>>>>>[-<<<<<<<+
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   607
>>>>>>>]<<<<<<<[->>>>>>>+<<<<<<+<]>>>>>>>>]<<<<<<<<<[<<<<<<<<<]>>>>>>>>>[>>>>>>[
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   608
-]>>>]<<<<<<<<<[<<<<<<<<<]>>>>+>[-<-<<<<+>>>>>]>[-<<<<<<[->>>>>+<++<<<<]>>>>>[-<
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   609
<<<<+>>>>>]<->+>]<[->+<]<<<<<[->>>>>+<<<<<]>>>>>>[-]<<<<<<+>>>>[-<<<<->>>>]+<<<<
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   610
[->>>>->>>>>[>>[-<<->>]+<<[->>->[-<<<+>>>]<<<[->>>+<<<<<<<<<<<<[<<<<<<<<<]>>>[-]
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   611
+>>>>>>[>>>>>>>>>]>+<]]+>>>[-<<<->>>]+<<<[->>>-<[-<<+>>]<<[->>+<<<<<<<<<<<[<<<<<
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   612
<<<<]>>>>[-]+>>>>>[>>>>>>>>>]>[-]+<]]+>[-<[>>>>>>>>>]<<<<<<<<]>>>>>>>>]<<<<<<<<<
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   613
[<<<<<<<<<]>>>>[-<<<<+>>>>]<<<<[->>>>+>>>>>[>+>>[-<<->>]<<[->>+<<]>>>>>>>>]<<<<<
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   614
<<<+<[>[->>>>>+<<<<[->>>>-<<<<<<<<<<<<<<+>>>>>>>>>>>[->>>+<<<]<]>[->>>-<<<<<<<<<
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   615
<<<<<+>>>>>>>>>>>]<<]>[->>>>+<<<[->>>-<<<<<<<<<<<<<<+>>>>>>>>>>>]<]>[->>>+<<<]<<
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   616
<<<<<<<<<<]>>>>[-]<<<<]>>>[-<<<+>>>]<<<[->>>+>>>>>>[>+>[-<->]<[->+<]>>>>>>>>]<<<
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   617
<<<<<+<[>[->>>>>+<<<[->>>-<<<<<<<<<<<<<<+>>>>>>>>>>[->>>>+<<<<]>]<[->>>>-<<<<<<<
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   618
<<<<<<<+>>>>>>>>>>]<]>>[->>>+<<<<[->>>>-<<<<<<<<<<<<<<+>>>>>>>>>>]>]<[->>>>+<<<<
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   619
]<<<<<<<<<<<]>>>>>>+<<<<<<]]>>>>[-<<<<+>>>>]<<<<[->>>>+>>>>>[>>>>>>>>>]<<<<<<<<<
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   620
[>[->>>>>+<<<<[->>>>-<<<<<<<<<<<<<<+>>>>>>>>>>>[->>>+<<<]<]>[->>>-<<<<<<<<<<<<<<
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   621
+>>>>>>>>>>>]<<]>[->>>>+<<<[->>>-<<<<<<<<<<<<<<+>>>>>>>>>>>]<]>[->>>+<<<]<<<<<<<
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   622
<<<<<]]>[-]>>[-]>[-]>>>>>[>>[-]>[-]>>>>>>]<<<<<<<<<[<<<<<<<<<]>>>>>>>>>[>>>>>[-<
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   623
<<<+>>>>]<<<<[->>>>+<<<+<]>>>>>>>>]<<<<<<<<<[<<<<<<<<<]>>>>>>>>>+++++++++++++++[
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   624
[>>>>>>>>>]+>[-]>[-]>[-]>[-]>[-]>[-]>[-]>[-]>[-]<<<<<<<<<[<<<<<<<<<]>>>>>>>>>-]+
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   625
[>+>>>>>>>>]<<<<<<<<<[<<<<<<<<<]>>>>>>>>>[>->>>>[-<<<<+>>>>]<<<<[->>>>+<<<<<[->>
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   626
[-<<+>>]<<[->>+>+<<<]+>>>>>>>>>]<<<<<<<<[<<<<<<<<<]]>>>>>>>>>[>>>>>>>>>]<<<<<<<<
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   627
<[>[->>>>>>>>>+<<<<<<<<<]<<<<<<<<<<]>[->>>>>>>>>+<<<<<<<<<]<+>>>>>>>>]<<<<<<<<<[
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   628
>[-]<->>>[-<<<+>[<->-<<<<<<<+>>>>>>>]<[->+<]>>>]<<[->>+<<]<+<<<<<<<<<]>>>>>>>>>[
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   629
>>>[-<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<+>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>]>
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   630
>>>>>]<<<<<<<<<[<<<<<<<<<]>>>>>[-]>>>>+++++++++++++++[[>>>>>>>>>]<<<<<<<<<-<<<<<
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   631
<<<<[<<<<<<<<<]>>>>>>>>>-]+[>>>[-<<<->>>]+<<<[->>>->[-<<<<+>>>>]<<<<[->>>>+<<<<<
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   632
<<<<<<<<[<<<<<<<<<]>>>>[-]+>>>>>[>>>>>>>>>]>+<]]+>>>>[-<<<<->>>>]+<<<<[->>>>-<[-
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   633
<<<+>>>]<<<[->>>+<<<<<<<<<<<<[<<<<<<<<<]>>>[-]+>>>>>>[>>>>>>>>>]>[-]+<]]+>[-<[>>
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   634
>>>>>>>]<<<<<<<<]>>>>>>>>]<<<<<<<<<[<<<<<<<<<]>>>[-<<<+>>>]<<<[->>>+>>>>>>[>+>>>
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   635
[-<<<->>>]<<<[->>>+<<<]>>>>>>>>]<<<<<<<<+<[>[->+>[-<-<<<<<<<<<<+>>>>>>>>>>>>[-<<
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   636
+>>]<]>[-<<-<<<<<<<<<<+>>>>>>>>>>>>]<<<]>>[-<+>>[-<<-<<<<<<<<<<+>>>>>>>>>>>>]<]>
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   637
[-<<+>>]<<<<<<<<<<<<<]]>>>>[-<<<<+>>>>]<<<<[->>>>+>>>>>[>+>>[-<<->>]<<[->>+<<]>>
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   638
>>>>>>]<<<<<<<<+<[>[->+>>[-<<-<<<<<<<<<<+>>>>>>>>>>>[-<+>]>]<[-<-<<<<<<<<<<+>>>>
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   639
>>>>>>>]<<]>>>[-<<+>[-<-<<<<<<<<<<+>>>>>>>>>>>]>]<[-<+>]<<<<<<<<<<<<]>>>>>+<<<<<
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   640
]>>>>>>>>>[>>>[-]>[-]>[-]>>>>]<<<<<<<<<[<<<<<<<<<]>>>[-]>[-]>>>>>[>>>>>>>[-<<<<<
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   641
<+>>>>>>]<<<<<<[->>>>>>+<<<<+<<]>>>>>>>>]<<<<<<<<<[<<<<<<<<<]>>>>+>[-<-<<<<+>>>>
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   642
>]>>[-<<<<<<<[->>>>>+<++<<<<]>>>>>[-<<<<<+>>>>>]<->+>>]<<[->>+<<]<<<<<[->>>>>+<<
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   643
<<<]+>>>>[-<<<<->>>>]+<<<<[->>>>->>>>>[>>>[-<<<->>>]+<<<[->>>-<[-<<+>>]<<[->>+<<
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   644
<<<<<<<<<[<<<<<<<<<]>>>>[-]+>>>>>[>>>>>>>>>]>+<]]+>>[-<<->>]+<<[->>->[-<<<+>>>]<
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   645
<<[->>>+<<<<<<<<<<<<[<<<<<<<<<]>>>[-]+>>>>>>[>>>>>>>>>]>[-]+<]]+>[-<[>>>>>>>>>]<
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   646
<<<<<<<]>>>>>>>>]<<<<<<<<<[<<<<<<<<<]>>>[-<<<+>>>]<<<[->>>+>>>>>>[>+>[-<->]<[->+
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   647
<]>>>>>>>>]<<<<<<<<+<[>[->>>>+<<[->>-<<<<<<<<<<<<<+>>>>>>>>>>[->>>+<<<]>]<[->>>-
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   648
<<<<<<<<<<<<<+>>>>>>>>>>]<]>>[->>+<<<[->>>-<<<<<<<<<<<<<+>>>>>>>>>>]>]<[->>>+<<<
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   649
]<<<<<<<<<<<]>>>>>[-]>>[-<<<<<<<+>>>>>>>]<<<<<<<[->>>>>>>+<<+<<<<<]]>>>>[-<<<<+>
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   650
>>>]<<<<[->>>>+>>>>>[>+>>[-<<->>]<<[->>+<<]>>>>>>>>]<<<<<<<<+<[>[->>>>+<<<[->>>-
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   651
<<<<<<<<<<<<<+>>>>>>>>>>>[->>+<<]<]>[->>-<<<<<<<<<<<<<+>>>>>>>>>>>]<<]>[->>>+<<[
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   652
->>-<<<<<<<<<<<<<+>>>>>>>>>>>]<]>[->>+<<]<<<<<<<<<<<<]]>>>>[-]<<<<]>>>>[-<<<<+>>
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   653
>>]<<<<[->>>>+>[-]>>[-<<<<<<<+>>>>>>>]<<<<<<<[->>>>>>>+<<+<<<<<]>>>>>>>>>[>>>>>>
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   654
>>>]<<<<<<<<<[>[->>>>+<<<[->>>-<<<<<<<<<<<<<+>>>>>>>>>>>[->>+<<]<]>[->>-<<<<<<<<
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   655
<<<<<+>>>>>>>>>>>]<<]>[->>>+<<[->>-<<<<<<<<<<<<<+>>>>>>>>>>>]<]>[->>+<<]<<<<<<<<
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   656
<<<<]]>>>>>>>>>[>>[-]>[-]>>>>>>]<<<<<<<<<[<<<<<<<<<]>>>[-]>[-]>>>>>[>>>>>[-<<<<+
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   657
>>>>]<<<<[->>>>+<<<+<]>>>>>>>>]<<<<<<<<<[<<<<<<<<<]>>>>>>>>>[>>>>>>[-<<<<<+>>>>>
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   658
]<<<<<[->>>>>+<<<+<<]>>>>>>>>]<<<<<<<<<[<<<<<<<<<]>>>>>>>>>+++++++++++++++[[>>>>
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   659
>>>>>]+>[-]>[-]>[-]>[-]>[-]>[-]>[-]>[-]>[-]<<<<<<<<<[<<<<<<<<<]>>>>>>>>>-]+[>+>>
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   660
>>>>>>]<<<<<<<<<[<<<<<<<<<]>>>>>>>>>[>->>>>[-<<<<+>>>>]<<<<[->>>>+<<<<<[->>[-<<+
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   661
>>]<<[->>+>>+<<<<]+>>>>>>>>>]<<<<<<<<[<<<<<<<<<]]>>>>>>>>>[>>>>>>>>>]<<<<<<<<<[>
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   662
[->>>>>>>>>+<<<<<<<<<]<<<<<<<<<<]>[->>>>>>>>>+<<<<<<<<<]<+>>>>>>>>]<<<<<<<<<[>[-
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   663
]<->>>>[-<<<<+>[<->-<<<<<<+>>>>>>]<[->+<]>>>>]<<<[->>>+<<<]<+<<<<<<<<<]>>>>>>>>>
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   664
[>+>>>>>>>>]<<<<<<<<<[<<<<<<<<<]>>>>>>>>>[>->>>>>[-<<<<<+>>>>>]<<<<<[->>>>>+<<<<
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   665
<<[->>>[-<<<+>>>]<<<[->>>+>+<<<<]+>>>>>>>>>]<<<<<<<<[<<<<<<<<<]]>>>>>>>>>[>>>>>>
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   666
>>>]<<<<<<<<<[>>[->>>>>>>>>+<<<<<<<<<]<<<<<<<<<<<]>>[->>>>>>>>>+<<<<<<<<<]<<+>>>
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   667
>>>>>]<<<<<<<<<[>[-]<->>>>[-<<<<+>[<->-<<<<<<+>>>>>>]<[->+<]>>>>]<<<[->>>+<<<]<+
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   668
<<<<<<<<<]>>>>>>>>>[>>>>[-<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<+>>>>>>>>>>>>>>>>>
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   669
>>>>>>>>>>>>>>>>>>>]>>>>>]<<<<<<<<<[<<<<<<<<<]>>>>>>>>>+++++++++++++++[[>>>>>>>>
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   670
>]<<<<<<<<<-<<<<<<<<<[<<<<<<<<<]>>>>>>>>>-]+>>>>>>>>>>>>>>>>>>>>>+<<<[<<<<<<<<<]
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   671
>>>>>>>>>[>>>[-<<<->>>]+<<<[->>>->[-<<<<+>>>>]<<<<[->>>>+<<<<<<<<<<<<<[<<<<<<<<<
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   672
]>>>>[-]+>>>>>[>>>>>>>>>]>+<]]+>>>>[-<<<<->>>>]+<<<<[->>>>-<[-<<<+>>>]<<<[->>>+<
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   673
<<<<<<<<<<<[<<<<<<<<<]>>>[-]+>>>>>>[>>>>>>>>>]>[-]+<]]+>[-<[>>>>>>>>>]<<<<<<<<]>
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   674
>>>>>>>]<<<<<<<<<[<<<<<<<<<]>>->>[-<<<<+>>>>]<<<<[->>>>+<<[-]<<]>>]<<+>>>>[-<<<<
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   675
->>>>]+<<<<[->>>>-<<<<<<.>>]>>>>[-<<<<<<<.>>>>>>>]<<<[-]>[-]>[-]>[-]>[-]>[-]>>>[
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   676
>[-]>[-]>[-]>[-]>[-]>[-]>>>]<<<<<<<<<[<<<<<<<<<]>>>>>>>>>[>>>>>[-]>>>>]<<<<<<<<<
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   677
[<<<<<<<<<]>+++++++++++[-[->>>>>>>>>+<<<<<<<<<]>>>>>>>>>]>>>>+>>>>>>>>>+<<<<<<<<
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   678
<<<<<<[<<<<<<<<<]>>>>>>>[-<<<<<<<+>>>>>>>]<<<<<<<[->>>>>>>+[-]>>[>>>>>>>>>]<<<<<
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   679
<<<<[>>>>>>>[-<<<<<<+>>>>>>]<<<<<<[->>>>>>+<<<<<<<[<<<<<<<<<]>>>>>>>[-]+>>>]<<<<
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   680
<<<<<<]]>>>>>>>[-<<<<<<<+>>>>>>>]<<<<<<<[->>>>>>>+>>[>+>>>>[-<<<<->>>>]<<<<[->>>
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   681
>+<<<<]>>>>>>>>]<<+<<<<<<<[>>>>>[->>+<<]<<<<<<<<<<<<<<]>>>>>>>>>[>>>>>>>>>]<<<<<
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   682
<<<<[>[-]<->>>>>>>[-<<<<<<<+>[<->-<<<+>>>]<[->+<]>>>>>>>]<<<<<<[->>>>>>+<<<<<<]<
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   683
+<<<<<<<<<]>>>>>>>-<<<<[-]+<<<]+>>>>>>>[-<<<<<<<->>>>>>>]+<<<<<<<[->>>>>>>->>[>>
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   684
>>>[->>+<<]>>>>]<<<<<<<<<[>[-]<->>>>>>>[-<<<<<<<+>[<->-<<<+>>>]<[->+<]>>>>>>>]<<
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   685
<<<<[->>>>>>+<<<<<<]<+<<<<<<<<<]>+++++[-[->>>>>>>>>+<<<<<<<<<]>>>>>>>>>]>>>>+<<<
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   686
<<[<<<<<<<<<]>>>>>>>>>[>>>>>[-<<<<<->>>>>]+<<<<<[->>>>>->>[-<<<<<<<+>>>>>>>]<<<<
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   687
<<<[->>>>>>>+<<<<<<<<<<<<<<<<[<<<<<<<<<]>>>>[-]+>>>>>[>>>>>>>>>]>+<]]+>>>>>>>[-<
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   688
<<<<<<->>>>>>>]+<<<<<<<[->>>>>>>-<<[-<<<<<+>>>>>]<<<<<[->>>>>+<<<<<<<<<<<<<<[<<<
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   689
<<<<<<]>>>[-]+>>>>>>[>>>>>>>>>]>[-]+<]]+>[-<[>>>>>>>>>]<<<<<<<<]>>>>>>>>]<<<<<<<
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   690
<<[<<<<<<<<<]>>>>[-]<<<+++++[-[->>>>>>>>>+<<<<<<<<<]>>>>>>>>>]>>>>-<<<<<[<<<<<<<
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   691
<<]]>>>]<<<<.>>>>>>>>>>[>>>>>>[-]>>>]<<<<<<<<<[<<<<<<<<<]>++++++++++[-[->>>>>>>>
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   692
>+<<<<<<<<<]>>>>>>>>>]>>>>>+>>>>>>>>>+<<<<<<<<<<<<<<<[<<<<<<<<<]>>>>>>>>[-<<<<<<
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   693
<<+>>>>>>>>]<<<<<<<<[->>>>>>>>+[-]>[>>>>>>>>>]<<<<<<<<<[>>>>>>>>[-<<<<<<<+>>>>>>
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   694
>]<<<<<<<[->>>>>>>+<<<<<<<<[<<<<<<<<<]>>>>>>>>[-]+>>]<<<<<<<<<<]]>>>>>>>>[-<<<<<
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   695
<<<+>>>>>>>>]<<<<<<<<[->>>>>>>>+>[>+>>>>>[-<<<<<->>>>>]<<<<<[->>>>>+<<<<<]>>>>>>
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   696
>>]<+<<<<<<<<[>>>>>>[->>+<<]<<<<<<<<<<<<<<<]>>>>>>>>>[>>>>>>>>>]<<<<<<<<<[>[-]<-
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   697
>>>>>>>>[-<<<<<<<<+>[<->-<<+>>]<[->+<]>>>>>>>>]<<<<<<<[->>>>>>>+<<<<<<<]<+<<<<<<
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   698
<<<]>>>>>>>>-<<<<<[-]+<<<]+>>>>>>>>[-<<<<<<<<->>>>>>>>]+<<<<<<<<[->>>>>>>>->[>>>
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   699
>>>[->>+<<]>>>]<<<<<<<<<[>[-]<->>>>>>>>[-<<<<<<<<+>[<->-<<+>>]<[->+<]>>>>>>>>]<<
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   700
<<<<<[->>>>>>>+<<<<<<<]<+<<<<<<<<<]>+++++[-[->>>>>>>>>+<<<<<<<<<]>>>>>>>>>]>>>>>
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   701
+>>>>>>>>>>>>>>>>>>>>>>>>>>>+<<<<<<[<<<<<<<<<]>>>>>>>>>[>>>>>>[-<<<<<<->>>>>>]+<
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   702
<<<<<[->>>>>>->>[-<<<<<<<<+>>>>>>>>]<<<<<<<<[->>>>>>>>+<<<<<<<<<<<<<<<<<[<<<<<<<
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   703
<<]>>>>[-]+>>>>>[>>>>>>>>>]>+<]]+>>>>>>>>[-<<<<<<<<->>>>>>>>]+<<<<<<<<[->>>>>>>>
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   704
-<<[-<<<<<<+>>>>>>]<<<<<<[->>>>>>+<<<<<<<<<<<<<<<[<<<<<<<<<]>>>[-]+>>>>>>[>>>>>>
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   705
>>>]>[-]+<]]+>[-<[>>>>>>>>>]<<<<<<<<]>>>>>>>>]<<<<<<<<<[<<<<<<<<<]>>>>[-]<<<++++
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   706
+[-[->>>>>>>>>+<<<<<<<<<]>>>>>>>>>]>>>>>->>>>>>>>>>>>>>>>>>>>>>>>>>>-<<<<<<[<<<<
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   707
<<<<<]]>>>]""", "mand")
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   708
183663740fb7 updated
Christian Urban <urbanc@in.tum.de>
parents: 708
diff changeset
   709