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