marking4/bf.scala
author Christian Urban <urbanc@in.tum.de>
Wed, 30 Oct 2019 12:37:18 +0000
changeset 286 5c57c407e27b
parent 227 b5f3e814a710
permissions -rw-r--r--
updated
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
168
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     1
// Part 2 about an Interpreter for the Brainf*** language
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     2
//========================================================
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     3
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     4
object CW8b {
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     5
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     6
type Mem = Map[Int, Int]
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     7
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     8
// (2a) Complete the functions for safely reading  
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     9
// and writing brainf*** memory. Safely read should
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    10
// Return the value stored in the Map for a given memory
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    11
// pointer, if it exists; otherwise it Returns 0. The
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    12
// writing function generates a new Map with the
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    13
// same data, except at the given memory pointer the
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    14
// value v is stored.
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    15
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    16
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    17
def sread(mem: Mem, mp: Int) : Int = 
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    18
  mem.getOrElse(mp, 0)
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    19
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    20
def write(mem: Mem, mp: Int, v: Int) : Mem =
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    21
  mem.updated(mp, v)
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    22
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    23
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    24
// (2b) Implement the two jumping instructions in the 
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    25
// brainf*** language. In jumpRight, given a program and 
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    26
// a program counter move the program counter to the right 
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    27
// until after the *matching* ]-command. Similarly, 
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    28
// jumpLeft implements the move to the left to just after
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    29
// the *matching* [--command.
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    30
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    31
def jumpRight(prog: String, pc: Int, level: Int) : Int = {
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    32
  if (prog.length <= pc) pc 
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    33
  else (prog(pc), level) match {
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    34
    case (']', 0) => pc + 1
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    35
    case (']', l) => jumpRight(prog, pc + 1, l - 1)
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    36
    case ('[', l) => jumpRight(prog, pc + 1, l + 1)
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    37
    case (_, l) => jumpRight(prog, pc + 1, l)
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    38
  }
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    39
}
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    40
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    41
def jumpLeft(prog: String, p: Int, level: Int) : Int = {
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    42
  if (p < 0) p 
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    43
  else (prog(p), level) match {
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    44
    case ('[', 0) => p + 1
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    45
    case ('[', l) => jumpLeft(prog, p - 1, l - 1)
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    46
    case (']', l) => jumpLeft(prog, p - 1, l + 1)
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    47
    case (_, l) => jumpLeft(prog, p - 1, l)
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    48
  }
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    49
}
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    50
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    51
//jumpLeft("[******]***", 7, 0)
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    52
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    53
// (2c) Complete the run function that interpretes (runs) a brainf***
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    54
// program: the arguments are a program, a program counter,
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    55
// a memory counter and a brainf*** memory. It Returns the
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    56
// memory at the stage when the excution of the brainf*** program
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    57
// finishes. The interpretation finishes once the program counter
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    58
// pc is pointing to something outside the program string.
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    59
// If the pc points to a character inside the program, the pc, 
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    60
// memory pointer and memory need to be updated according to 
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    61
// rules of the brainf*** language. Then, recursively, run 
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    62
// function continues with the command at the new program
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    63
// counter. 
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    64
// Implement the start function that calls run with the program
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    65
// counter and memory counter set to 0.
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    66
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    67
def run(prog: String, pc: Int, mp: Int, mem: Mem) : Mem = {
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    68
  if (0 <= pc && pc < prog.length) { 
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    69
    val (new_pc, new_mp, new_mem) = prog(pc) match {
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    70
      case '>' => (pc + 1, mp + 1, mem)
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    71
      case '<' => (pc + 1, mp - 1, mem)
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    72
      case '+' => (pc + 1, mp, write(mem, mp, sread(mem, mp) + 1))
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    73
      case '-' => (pc + 1, mp, write(mem, mp, sread(mem, mp) - 1))
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    74
      case '.' => { print(sread(mem, mp).toChar); (pc + 1, mp, mem) }
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    75
      case ',' => (pc + 1, mp, write(mem, mp, Console.in.read().toByte))
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    76
      case '['  => 
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    77
	if (sread(mem, mp) == 0) (jumpRight(prog, pc + 1, 0), mp, mem) else (pc + 1, mp, mem) 
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    78
      case ']'  => 
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    79
	if (sread(mem, mp) != 0) (jumpLeft(prog, pc - 1, 0), mp, mem) else (pc + 1, mp, mem) 
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    80
      case _ => (pc + 1, mp, mem)
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    81
    }		     
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    82
    run(prog, new_pc, new_mp, new_mem)	
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    83
  }
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    84
  else mem
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    85
}
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    86
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    87
def start(prog: String, m: Mem) = run(prog, 0, 0, m)
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    88
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    89
// some sample programs collected from the Internet
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    90
//==================================================
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    91
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    92
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    93
/*
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    94
// first some contrived (small) programs
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    95
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    96
// clears the 0-cell
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    97
start("[-]", Map(0 -> 100)) 
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    98
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    99
// copies content of the 0-cell to 1-cell
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   100
start("[->+<]", Map(0 -> 10))
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   101
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   102
// copies content of the 0-cell to 2-cell and 4-cell
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   103
start("[>>+>>+<<<<-]", Map(0 -> 42))
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   104
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   105
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   106
// prints out numbers 0 to 9
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   107
start("""+++++[->++++++++++<]>--<+++[->>++++++++++<<]>>++<<----------[+>.>.<+<]""", Map())
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   108
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   109
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   110
// some more "useful" programs
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   111
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   112
// hello world program 1
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   113
start("""++++++++[>++++[>++>+++>+++>+<<<<-]>+>+>->>+[<]<-]>>.>---.+++++++
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   114
       ..+++.>>.<-.<.+++.------.--------.>>+.>++.""", Map())
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   115
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   116
// hello world program 2
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   117
start("""++++++++++[>+++++++>++++++++++>+++>+<<<<-]>++.>+.+++++++..+++.>+
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   118
      +.<<+++++++++++++++.>.+++.------.--------.>+.>.""", Map())
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   119
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   120
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   121
// draws the Sierpinski triangle
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   122
start("""++++++++[>+>++++<<-]>++>>+<[-[>>+<<-]+>>]>+[-<<<[
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   123
      ->[+[-]+>++>>>-<<]<[<]>>++++++[<<+++++>>-]+<<++.[-]<<
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   124
      ]>.>+[>>]>+]""", Map())
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   125
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   126
println(start("""++++++++[>+>++++<<-]>++>>+<[-[>>+<<-]+>>]>+[-<<<[
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   127
      ->[+[-]+>++>>>-<<]<[<]>>++++++[<<+++++>>-]+<<++.[-]<<
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   128
      ]>.>+[>>]>+]""", Map())) 
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   129
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   130
//fibonacci numbers below 100
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   131
start("""+++++++++++
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   132
      >+>>>>++++++++++++++++++++++++++++++++++++++++++++
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   133
      >++++++++++++++++++++++++++++++++<<<<<<[>[>>>>>>+>
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   134
      +<<<<<<<-]>>>>>>>[<<<<<<<+>>>>>>>-]<[>++++++++++[-
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   135
      <-[>>+>+<<<-]>>>[<<<+>>>-]+<[>[-]<[-]]>[<<[>>>+<<<
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   136
      -]>>[-]]<<]>>>[>>+>+<<<-]>>>[<<<+>>>-]+<[>[-]<[-]]
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   137
      >[<<+>>[-]]<<<<<<<]>>>>>[+++++++++++++++++++++++++
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   138
      +++++++++++++++++++++++.[-]]++++++++++<[->-<]>++++
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   139
      ++++++++++++++++++++++++++++++++++++++++++++.[-]<<
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   140
      <<<<<<<<<<[>>>+>+<<<<-]>>>>[<<<<+>>>>-]<-[>>.>.<<<
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   141
      [-]]<<[>>+>+<<<-]>>>[<<<+>>>-]<<[<+>-]>[<+>-]<<<-]""", Map())
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   142
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   143
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   144
//outputs the square numbers up to 10000
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   145
start("""++++[>+++++<-]>[<+++++>-]+<+[
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   146
    >[>+>+<<-]++>>[<<+>>-]>>>[-]++>[-]+
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   147
    >>>+[[-]++++++>>>]<<<[[<++++++++<++>>-]+<.<[>----<-]<]
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   148
    <<[>>>>>[>>>[-]+++++++++<[>-<-]+++++++++>[-[<->-]+[<<<]]<[>+<-]>]<<-]<<-]""", Map())
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   149
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   150
//collatz numbers (need to be typed in)
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   151
start(""">,[[----------[
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   152
      >>>[>>>>]+[[-]+<[->>>>++>>>>+[>>>>]++[->+<<<<<]]<<<]
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   153
      ++++++[>------<-]>--[>>[->>>>]+>+[<<<<]>-],<]>]>>>++>+>>[
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   154
      <<[>>>>[-]+++++++++<[>-<-]+++++++++>[-[<->-]+[<<<<]]<[>+<-]>]
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   155
      >[>[>>>>]+[[-]<[+[->>>>]>+<]>[<+>[<<<<]]+<<<<]>>>[->>>>]+>+[<<<<]]
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   156
      >[[>+>>[<<<<+>>>>-]>]<<<<[-]>[-<<<<]]>>>>>>>
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   157
      ]>>+[[-]++++++>>>>]<<<<[[<++++++++>-]<.[-]<[-]<[-]<]<,]""", Map())
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   158
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   159
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   160
// infinite collatz (never stops)
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   161
start(""">>+>+<[[->>[>>]>>>[>>]+[<<]<<<[<<]>[>[>>]>>+>[>>]<+<[<<]<<<[<
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   162
      <]>-]>[>>]>>[<<<<[<<]>+>[>>]>>-]<<<<[<<]+>>]<<[+++++[>+++++++
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   163
      +<-]>.<++++++[>--------<-]+<<]>>[>>]+[>>>>[<<+>+>-]<-[>+<-]+<
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   164
      [<<->>-[<<+>>[-]]]>>>[<<<+<<+>>>>>-]<<<[>>>+<<<-]<<[[-]>+>>->
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   165
      [<+<[<<+>>-]<[>+<-]<[>+<-]>>>>-]<[>+<-]+<[->[>>]<<[->[<+++>-[
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   166
      <+++>-[<+++>-[<[-]++>>[-]+>+<<-[<+++>-[<+++>-[<[-]+>>>+<<-[<+
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   167
      ++>-[<+++>-]]]]]]]]]<[>+<-]+<<]>>>+<[->[<+>-[<+>-[<+>-[<+>-[<
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   168
      +>-[<+>-[<+>-[<+>-[<+>-[<[-]>>[-]+>+<<-[<+>-]]]]]]]]]]]<[>+<-
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   169
      ]+>>]<<[<<]>]<[->>[->+>]<[-[<+>-[<->>+<-[<+>-[<->>+<-[<+>-[<-
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   170
      >>+<-[<+>-[<->>+<-[<+>-[<->>+<-[<+>-[<->>+<-[<+>-[<->>+<-[<+>
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   171
      -[<->>+<-[<+>-[<->>+<-[<+>-]]]]]]]]]]]]]]]]]]]>[<+>-]<+<[<+++
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   172
      +++++++>-]<]>>[<+>->>]<<[>+>+<<-]>[<+>-]+>[<->[-]]<[-<<-]<<[<
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   173
      <]]++++++[>+++++++<-]>++.------------.[-]>[>>]<<[+++++[>+++++
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   174
      +++<-]>.<++++++[>--------<-]+<<]+<]>[<+>-]<]>>>[>>]<<[>[-]<-<
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   175
      <]++++++++++.[-]<<<[<<]>>>+<[->[<+>-[<+>-[<+>-[<+>-[<+>-[<+>-
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   176
      [<+>-[<+>-[<+>-[<[-]>>[-]+>+<<-]]]]]]]]]]<[>+<-]+>>]<<[<<]>>]""", Map())
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   177
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   178
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   179
start("""+++++[>+++++++++<-],[[>--.++>+<<-]>+.->[<.>-]<<,]""", Map())
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   180
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   181
*/ 
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   182
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   183
/*
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   184
def splice(cs: List[Char], acc: List[(Char, Int)]) : List[(Char, Int)] = (cs, acc) match {
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   185
  case (Nil, acc) => acc
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   186
  case (c :: cs, Nil) => splice(cs, List((c, 1)))
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   187
  case (c :: cs, (d, n) :: acc) => 
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   188
    if (c == d) splice(cs, (c, n + 1) :: acc)
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   189
    else splice(cs, (c, 1) :: (d, n) :: acc)
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   190
}
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   191
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   192
def spl(s: String) = splice(s.toList, Nil).reverse
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   193
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   194
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   195
// simple instructions
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   196
def instr(c: Char) : String = c match {
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   197
  case '>' => "ptr++;"
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   198
  case '<' => "ptr--;"
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   199
  case '+' => "(*ptr)++;"
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   200
  case '-' => "(*ptr)--;"
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   201
  case '.' => "putchar(*ptr);"
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   202
  case ',' => "*ptr = getchar();\n"
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   203
  case '['  => "while(*ptr){"
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   204
  case ']'  => "}"
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   205
  case _ => ""
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   206
}
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   207
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   208
def instrs(prog: String) : String =
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   209
  prog.toList.map(instr(_)).mkString
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   210
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   211
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   212
//optimised instructions
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   213
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   214
def instr2(c: Char, n: Int) : String = c match {
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   215
  case '>' => "ptr += " + n.toString + ";"
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   216
  case '<' => "ptr -= " + n.toString + ";"
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   217
  case '+' => "(*ptr) += " + n.toString + ";"
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   218
  case '-' => "(*ptr) -= " + n.toString + ";"
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   219
  case '.' => "putchar(*ptr);" * n
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   220
  case ',' => "*ptr = getchar();\n" * n
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   221
  case '['  => "while(*ptr){" * n
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   222
  case ']'  => "}" * n
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   223
  case _ => ""
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   224
}
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   225
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   226
def instrs2(prog: String) : String =
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   227
  spl(prog).map{ case (c, n) => instr2(c, n) }.mkString
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   228
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   229
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   230
// peephole optimisers are at
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   231
// https://github.com/Wilfred/bfc#peephole-optimisations
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   232
// http://calmerthanyouare.org/2015/01/07/optimizing-brainfuck.html
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   233
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   234
def compile_str(prog: String) : String = {
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   235
  "#include <string.h>\n" ++
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   236
  "#include <stdio.h>\n" ++
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   237
  "char field[30000];\n" ++
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   238
  "char *ptr = &field[15000];" ++
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   239
  "int main()\n{\n" ++
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   240
  "memset(field, '\\0', 30000);\n" ++
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   241
  instrs2(prog) ++
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   242
  "\n re turn 0;\n}"
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   243
}
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   244
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   245
def compile(name: String, prog: String) = {
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   246
  val fw = new java.io.FileWriter(name + ".c") 
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   247
  fw.write(compile_str(prog)) 
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   248
  fw.close()
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   249
}
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   250
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   251
import sys.process._
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   252
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   253
def compile_run(prog: String) = {
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   254
  compile("tmp", prog)
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   255
  "gcc -O3 -o tmp tmp.c".!
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   256
  "./tmp".!
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   257
  ()
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   258
}
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   259
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   260
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   261
compile_run("""++++++++[>++++[>++>+++>+++>+<<<<-]>+>+>->>+[<]<-]>>.>---.+++++++
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   262
       ..+++.>>.<-.<.+++.------.--------.>>+.>++.""")
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   263
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   264
compile_run("""++++++++[>+>++++<<-]>++>>+<[-[>>+<<-]+>>]>+[-<<<[
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   265
      ->[+[-]+>++>>>-<<]<[<]>>++++++[<<+++++>>-]+<<++.[-]<<
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   266
      ]>.>+[>>]>+]""")
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   267
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   268
compile_run("""      A mandelbrot set fractal viewer in brainf*** written by Erik Bosman
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   269
+++++++++++++[->++>>>+++++>++>+<<<<<<]>>>>>++++++>--->>>>>>>>>>+++++++++++++++[[
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   270
>>>>>>>>>]+[<<<<<<<<<]>>>>>>>>>-]+[>>>>>>>>[-]>]<<<<<<<<<[<<<<<<<<<]>>>>>>>>[-]+
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   271
<<<<<<<+++++[-[->>>>>>>>>+<<<<<<<<<]>>>>>>>>>]>>>>>>>+>>>>>>>>>>>>>>>>>>>>>>>>>>
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   272
>+<<<<<<<<<<<<<<<<<[<<<<<<<<<]>>>[-]+[>>>>>>[>>>>>>>[-]>>]<<<<<<<<<[<<<<<<<<<]>>
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   273
>>>>>[-]+<<<<<<++++[-[->>>>>>>>>+<<<<<<<<<]>>>>>>>>>]>>>>>>+<<<<<<+++++++[-[->>>
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   274
>>>>>>+<<<<<<<<<]>>>>>>>>>]>>>>>>+<<<<<<<<<<<<<<<<[<<<<<<<<<]>>>[[-]>>>>>>[>>>>>
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   275
>>[-<<<<<<+>>>>>>]<<<<<<[->>>>>>+<<+<<<+<]>>>>>>>>]<<<<<<<<<[<<<<<<<<<]>>>>>>>>>
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   276
[>>>>>>>>[-<<<<<<<+>>>>>>>]<<<<<<<[->>>>>>>+<<+<<<+<<]>>>>>>>>]<<<<<<<<<[<<<<<<<
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   277
<<]>>>>>>>[-<<<<<<<+>>>>>>>]<<<<<<<[->>>>>>>+<<+<<<<<]>>>>>>>>>+++++++++++++++[[
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   278
>>>>>>>>>]+>[-]>[-]>[-]>[-]>[-]>[-]>[-]>[-]>[-]<<<<<<<<<[<<<<<<<<<]>>>>>>>>>-]+[
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   279
>+>>>>>>>>]<<<<<<<<<[<<<<<<<<<]>>>>>>>>>[>->>>>[-<<<<+>>>>]<<<<[->>>>+<<<<<[->>[
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   280
-<<+>>]<<[->>+>>+<<<<]+>>>>>>>>>]<<<<<<<<[<<<<<<<<<]]>>>>>>>>>[>>>>>>>>>]<<<<<<<
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   281
<<[>[->>>>>>>>>+<<<<<<<<<]<<<<<<<<<<]>[->>>>>>>>>+<<<<<<<<<]<+>>>>>>>>]<<<<<<<<<
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   282
[>[-]<->>>>[-<<<<+>[<->-<<<<<<+>>>>>>]<[->+<]>>>>]<<<[->>>+<<<]<+<<<<<<<<<]>>>>>
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   283
>>>>[>+>>>>>>>>]<<<<<<<<<[<<<<<<<<<]>>>>>>>>>[>->>>>>[-<<<<<+>>>>>]<<<<<[->>>>>+
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   284
<<<<<<[->>>[-<<<+>>>]<<<[->>>+>+<<<<]+>>>>>>>>>]<<<<<<<<[<<<<<<<<<]]>>>>>>>>>[>>
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   285
>>>>>>>]<<<<<<<<<[>>[->>>>>>>>>+<<<<<<<<<]<<<<<<<<<<<]>>[->>>>>>>>>+<<<<<<<<<]<<
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   286
+>>>>>>>>]<<<<<<<<<[>[-]<->>>>[-<<<<+>[<->-<<<<<<+>>>>>>]<[->+<]>>>>]<<<[->>>+<<
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   287
<]<+<<<<<<<<<]>>>>>>>>>[>>>>[-<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<+>>>>>>>>>>>>>
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   288
>>>>>>>>>>>>>>>>>>>>>>>]>>>>>]<<<<<<<<<[<<<<<<<<<]>>>>>>>>>+++++++++++++++[[>>>>
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   289
>>>>>]<<<<<<<<<-<<<<<<<<<[<<<<<<<<<]>>>>>>>>>-]+>>>>>>>>>>>>>>>>>>>>>+<<<[<<<<<<
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   290
<<<]>>>>>>>>>[>>>[-<<<->>>]+<<<[->>>->[-<<<<+>>>>]<<<<[->>>>+<<<<<<<<<<<<<[<<<<<
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   291
<<<<]>>>>[-]+>>>>>[>>>>>>>>>]>+<]]+>>>>[-<<<<->>>>]+<<<<[->>>>-<[-<<<+>>>]<<<[->
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   292
>>+<<<<<<<<<<<<[<<<<<<<<<]>>>[-]+>>>>>>[>>>>>>>>>]>[-]+<]]+>[-<[>>>>>>>>>]<<<<<<
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   293
<<]>>>>>>>>]<<<<<<<<<[<<<<<<<<<]<<<<<<<[->+>>>-<<<<]>>>>>>>>>+++++++++++++++++++
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   294
+++++++>>[-<<<<+>>>>]<<<<[->>>>+<<[-]<<]>>[<<<<<<<+<[-<+>>>>+<<[-]]>[-<<[->+>>>-
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   295
<<<<]>>>]>>>>>>>>>>>>>[>>[-]>[-]>[-]>>>>>]<<<<<<<<<[<<<<<<<<<]>>>[-]>>>>>>[>>>>>
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   296
[-<<<<+>>>>]<<<<[->>>>+<<<+<]>>>>>>>>]<<<<<<<<<[<<<<<<<<<]>>>>>>>>>[>>[-<<<<<<<<
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   297
<+>>>>>>>>>]>>>>>>>]<<<<<<<<<[<<<<<<<<<]>>>>>>>>>+++++++++++++++[[>>>>>>>>>]+>[-
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   298
]>[-]>[-]>[-]>[-]>[-]>[-]>[-]>[-]<<<<<<<<<[<<<<<<<<<]>>>>>>>>>-]+[>+>>>>>>>>]<<<
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   299
<<<<<<[<<<<<<<<<]>>>>>>>>>[>->>>>>[-<<<<<+>>>>>]<<<<<[->>>>>+<<<<<<[->>[-<<+>>]<
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   300
<[->>+>+<<<]+>>>>>>>>>]<<<<<<<<[<<<<<<<<<]]>>>>>>>>>[>>>>>>>>>]<<<<<<<<<[>[->>>>
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   301
>>>>>+<<<<<<<<<]<<<<<<<<<<]>[->>>>>>>>>+<<<<<<<<<]<+>>>>>>>>]<<<<<<<<<[>[-]<->>>
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   302
[-<<<+>[<->-<<<<<<<+>>>>>>>]<[->+<]>>>]<<[->>+<<]<+<<<<<<<<<]>>>>>>>>>[>>>>>>[-<
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   303
<<<<+>>>>>]<<<<<[->>>>>+<<<<+<]>>>>>>>>]<<<<<<<<<[<<<<<<<<<]>>>>>>>>>[>+>>>>>>>>
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   304
]<<<<<<<<<[<<<<<<<<<]>>>>>>>>>[>->>>>>[-<<<<<+>>>>>]<<<<<[->>>>>+<<<<<<[->>[-<<+
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   305
>>]<<[->>+>>+<<<<]+>>>>>>>>>]<<<<<<<<[<<<<<<<<<]]>>>>>>>>>[>>>>>>>>>]<<<<<<<<<[>
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   306
[->>>>>>>>>+<<<<<<<<<]<<<<<<<<<<]>[->>>>>>>>>+<<<<<<<<<]<+>>>>>>>>]<<<<<<<<<[>[-
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   307
]<->>>>[-<<<<+>[<->-<<<<<<+>>>>>>]<[->+<]>>>>]<<<[->>>+<<<]<+<<<<<<<<<]>>>>>>>>>
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   308
[>>>>[-<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<+>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   309
]>>>>>]<<<<<<<<<[<<<<<<<<<]>>>>>>>>>[>>>[-<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<+>
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   310
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>]>>>>>>]<<<<<<<<<[<<<<<<<<<]>>>>>>>>>++++++++
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   311
+++++++[[>>>>>>>>>]<<<<<<<<<-<<<<<<<<<[<<<<<<<<<]>>>>>>>>>-]+[>>>>>>>>[-<<<<<<<+
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   312
>>>>>>>]<<<<<<<[->>>>>>>+<<<<<<+<]>>>>>>>>]<<<<<<<<<[<<<<<<<<<]>>>>>>>>>[>>>>>>[
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   313
-]>>>]<<<<<<<<<[<<<<<<<<<]>>>>+>[-<-<<<<+>>>>>]>[-<<<<<<[->>>>>+<++<<<<]>>>>>[-<
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   314
<<<<+>>>>>]<->+>]<[->+<]<<<<<[->>>>>+<<<<<]>>>>>>[-]<<<<<<+>>>>[-<<<<->>>>]+<<<<
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   315
[->>>>->>>>>[>>[-<<->>]+<<[->>->[-<<<+>>>]<<<[->>>+<<<<<<<<<<<<[<<<<<<<<<]>>>[-]
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   316
+>>>>>>[>>>>>>>>>]>+<]]+>>>[-<<<->>>]+<<<[->>>-<[-<<+>>]<<[->>+<<<<<<<<<<<[<<<<<
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   317
<<<<]>>>>[-]+>>>>>[>>>>>>>>>]>[-]+<]]+>[-<[>>>>>>>>>]<<<<<<<<]>>>>>>>>]<<<<<<<<<
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   318
[<<<<<<<<<]>>>>[-<<<<+>>>>]<<<<[->>>>+>>>>>[>+>>[-<<->>]<<[->>+<<]>>>>>>>>]<<<<<
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   319
<<<+<[>[->>>>>+<<<<[->>>>-<<<<<<<<<<<<<<+>>>>>>>>>>>[->>>+<<<]<]>[->>>-<<<<<<<<<
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   320
<<<<<+>>>>>>>>>>>]<<]>[->>>>+<<<[->>>-<<<<<<<<<<<<<<+>>>>>>>>>>>]<]>[->>>+<<<]<<
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   321
<<<<<<<<<<]>>>>[-]<<<<]>>>[-<<<+>>>]<<<[->>>+>>>>>>[>+>[-<->]<[->+<]>>>>>>>>]<<<
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   322
<<<<<+<[>[->>>>>+<<<[->>>-<<<<<<<<<<<<<<+>>>>>>>>>>[->>>>+<<<<]>]<[->>>>-<<<<<<<
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   323
<<<<<<<+>>>>>>>>>>]<]>>[->>>+<<<<[->>>>-<<<<<<<<<<<<<<+>>>>>>>>>>]>]<[->>>>+<<<<
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   324
]<<<<<<<<<<<]>>>>>>+<<<<<<]]>>>>[-<<<<+>>>>]<<<<[->>>>+>>>>>[>>>>>>>>>]<<<<<<<<<
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   325
[>[->>>>>+<<<<[->>>>-<<<<<<<<<<<<<<+>>>>>>>>>>>[->>>+<<<]<]>[->>>-<<<<<<<<<<<<<<
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   326
+>>>>>>>>>>>]<<]>[->>>>+<<<[->>>-<<<<<<<<<<<<<<+>>>>>>>>>>>]<]>[->>>+<<<]<<<<<<<
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   327
<<<<<]]>[-]>>[-]>[-]>>>>>[>>[-]>[-]>>>>>>]<<<<<<<<<[<<<<<<<<<]>>>>>>>>>[>>>>>[-<
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   328
<<<+>>>>]<<<<[->>>>+<<<+<]>>>>>>>>]<<<<<<<<<[<<<<<<<<<]>>>>>>>>>+++++++++++++++[
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   329
[>>>>>>>>>]+>[-]>[-]>[-]>[-]>[-]>[-]>[-]>[-]>[-]<<<<<<<<<[<<<<<<<<<]>>>>>>>>>-]+
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   330
[>+>>>>>>>>]<<<<<<<<<[<<<<<<<<<]>>>>>>>>>[>->>>>[-<<<<+>>>>]<<<<[->>>>+<<<<<[->>
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   331
[-<<+>>]<<[->>+>+<<<]+>>>>>>>>>]<<<<<<<<[<<<<<<<<<]]>>>>>>>>>[>>>>>>>>>]<<<<<<<<
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   332
<[>[->>>>>>>>>+<<<<<<<<<]<<<<<<<<<<]>[->>>>>>>>>+<<<<<<<<<]<+>>>>>>>>]<<<<<<<<<[
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   333
>[-]<->>>[-<<<+>[<->-<<<<<<<+>>>>>>>]<[->+<]>>>]<<[->>+<<]<+<<<<<<<<<]>>>>>>>>>[
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   334
>>>[-<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<+>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>]>
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   335
>>>>>]<<<<<<<<<[<<<<<<<<<]>>>>>[-]>>>>+++++++++++++++[[>>>>>>>>>]<<<<<<<<<-<<<<<
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   336
<<<<[<<<<<<<<<]>>>>>>>>>-]+[>>>[-<<<->>>]+<<<[->>>->[-<<<<+>>>>]<<<<[->>>>+<<<<<
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   337
<<<<<<<<[<<<<<<<<<]>>>>[-]+>>>>>[>>>>>>>>>]>+<]]+>>>>[-<<<<->>>>]+<<<<[->>>>-<[-
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   338
<<<+>>>]<<<[->>>+<<<<<<<<<<<<[<<<<<<<<<]>>>[-]+>>>>>>[>>>>>>>>>]>[-]+<]]+>[-<[>>
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   339
>>>>>>>]<<<<<<<<]>>>>>>>>]<<<<<<<<<[<<<<<<<<<]>>>[-<<<+>>>]<<<[->>>+>>>>>>[>+>>>
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   340
[-<<<->>>]<<<[->>>+<<<]>>>>>>>>]<<<<<<<<+<[>[->+>[-<-<<<<<<<<<<+>>>>>>>>>>>>[-<<
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   341
+>>]<]>[-<<-<<<<<<<<<<+>>>>>>>>>>>>]<<<]>>[-<+>>[-<<-<<<<<<<<<<+>>>>>>>>>>>>]<]>
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   342
[-<<+>>]<<<<<<<<<<<<<]]>>>>[-<<<<+>>>>]<<<<[->>>>+>>>>>[>+>>[-<<->>]<<[->>+<<]>>
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   343
>>>>>>]<<<<<<<<+<[>[->+>>[-<<-<<<<<<<<<<+>>>>>>>>>>>[-<+>]>]<[-<-<<<<<<<<<<+>>>>
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   344
>>>>>>>]<<]>>>[-<<+>[-<-<<<<<<<<<<+>>>>>>>>>>>]>]<[-<+>]<<<<<<<<<<<<]>>>>>+<<<<<
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   345
]>>>>>>>>>[>>>[-]>[-]>[-]>>>>]<<<<<<<<<[<<<<<<<<<]>>>[-]>[-]>>>>>[>>>>>>>[-<<<<<
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   346
<+>>>>>>]<<<<<<[->>>>>>+<<<<+<<]>>>>>>>>]<<<<<<<<<[<<<<<<<<<]>>>>+>[-<-<<<<+>>>>
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   347
>]>>[-<<<<<<<[->>>>>+<++<<<<]>>>>>[-<<<<<+>>>>>]<->+>>]<<[->>+<<]<<<<<[->>>>>+<<
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   348
<<<]+>>>>[-<<<<->>>>]+<<<<[->>>>->>>>>[>>>[-<<<->>>]+<<<[->>>-<[-<<+>>]<<[->>+<<
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   349
<<<<<<<<<[<<<<<<<<<]>>>>[-]+>>>>>[>>>>>>>>>]>+<]]+>>[-<<->>]+<<[->>->[-<<<+>>>]<
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   350
<<[->>>+<<<<<<<<<<<<[<<<<<<<<<]>>>[-]+>>>>>>[>>>>>>>>>]>[-]+<]]+>[-<[>>>>>>>>>]<
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   351
<<<<<<<]>>>>>>>>]<<<<<<<<<[<<<<<<<<<]>>>[-<<<+>>>]<<<[->>>+>>>>>>[>+>[-<->]<[->+
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   352
<]>>>>>>>>]<<<<<<<<+<[>[->>>>+<<[->>-<<<<<<<<<<<<<+>>>>>>>>>>[->>>+<<<]>]<[->>>-
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   353
<<<<<<<<<<<<<+>>>>>>>>>>]<]>>[->>+<<<[->>>-<<<<<<<<<<<<<+>>>>>>>>>>]>]<[->>>+<<<
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   354
]<<<<<<<<<<<]>>>>>[-]>>[-<<<<<<<+>>>>>>>]<<<<<<<[->>>>>>>+<<+<<<<<]]>>>>[-<<<<+>
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   355
>>>]<<<<[->>>>+>>>>>[>+>>[-<<->>]<<[->>+<<]>>>>>>>>]<<<<<<<<+<[>[->>>>+<<<[->>>-
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   356
<<<<<<<<<<<<<+>>>>>>>>>>>[->>+<<]<]>[->>-<<<<<<<<<<<<<+>>>>>>>>>>>]<<]>[->>>+<<[
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   357
->>-<<<<<<<<<<<<<+>>>>>>>>>>>]<]>[->>+<<]<<<<<<<<<<<<]]>>>>[-]<<<<]>>>>[-<<<<+>>
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   358
>>]<<<<[->>>>+>[-]>>[-<<<<<<<+>>>>>>>]<<<<<<<[->>>>>>>+<<+<<<<<]>>>>>>>>>[>>>>>>
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   359
>>>]<<<<<<<<<[>[->>>>+<<<[->>>-<<<<<<<<<<<<<+>>>>>>>>>>>[->>+<<]<]>[->>-<<<<<<<<
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   360
<<<<<+>>>>>>>>>>>]<<]>[->>>+<<[->>-<<<<<<<<<<<<<+>>>>>>>>>>>]<]>[->>+<<]<<<<<<<<
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   361
<<<<]]>>>>>>>>>[>>[-]>[-]>>>>>>]<<<<<<<<<[<<<<<<<<<]>>>[-]>[-]>>>>>[>>>>>[-<<<<+
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   362
>>>>]<<<<[->>>>+<<<+<]>>>>>>>>]<<<<<<<<<[<<<<<<<<<]>>>>>>>>>[>>>>>>[-<<<<<+>>>>>
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   363
]<<<<<[->>>>>+<<<+<<]>>>>>>>>]<<<<<<<<<[<<<<<<<<<]>>>>>>>>>+++++++++++++++[[>>>>
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   364
>>>>>]+>[-]>[-]>[-]>[-]>[-]>[-]>[-]>[-]>[-]<<<<<<<<<[<<<<<<<<<]>>>>>>>>>-]+[>+>>
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   365
>>>>>>]<<<<<<<<<[<<<<<<<<<]>>>>>>>>>[>->>>>[-<<<<+>>>>]<<<<[->>>>+<<<<<[->>[-<<+
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   366
>>]<<[->>+>>+<<<<]+>>>>>>>>>]<<<<<<<<[<<<<<<<<<]]>>>>>>>>>[>>>>>>>>>]<<<<<<<<<[>
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   367
[->>>>>>>>>+<<<<<<<<<]<<<<<<<<<<]>[->>>>>>>>>+<<<<<<<<<]<+>>>>>>>>]<<<<<<<<<[>[-
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   368
]<->>>>[-<<<<+>[<->-<<<<<<+>>>>>>]<[->+<]>>>>]<<<[->>>+<<<]<+<<<<<<<<<]>>>>>>>>>
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   369
[>+>>>>>>>>]<<<<<<<<<[<<<<<<<<<]>>>>>>>>>[>->>>>>[-<<<<<+>>>>>]<<<<<[->>>>>+<<<<
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   370
<<[->>>[-<<<+>>>]<<<[->>>+>+<<<<]+>>>>>>>>>]<<<<<<<<[<<<<<<<<<]]>>>>>>>>>[>>>>>>
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   371
>>>]<<<<<<<<<[>>[->>>>>>>>>+<<<<<<<<<]<<<<<<<<<<<]>>[->>>>>>>>>+<<<<<<<<<]<<+>>>
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   372
>>>>>]<<<<<<<<<[>[-]<->>>>[-<<<<+>[<->-<<<<<<+>>>>>>]<[->+<]>>>>]<<<[->>>+<<<]<+
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   373
<<<<<<<<<]>>>>>>>>>[>>>>[-<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<+>>>>>>>>>>>>>>>>>
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   374
>>>>>>>>>>>>>>>>>>>]>>>>>]<<<<<<<<<[<<<<<<<<<]>>>>>>>>>+++++++++++++++[[>>>>>>>>
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   375
>]<<<<<<<<<-<<<<<<<<<[<<<<<<<<<]>>>>>>>>>-]+>>>>>>>>>>>>>>>>>>>>>+<<<[<<<<<<<<<]
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   376
>>>>>>>>>[>>>[-<<<->>>]+<<<[->>>->[-<<<<+>>>>]<<<<[->>>>+<<<<<<<<<<<<<[<<<<<<<<<
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   377
]>>>>[-]+>>>>>[>>>>>>>>>]>+<]]+>>>>[-<<<<->>>>]+<<<<[->>>>-<[-<<<+>>>]<<<[->>>+<
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   378
<<<<<<<<<<<[<<<<<<<<<]>>>[-]+>>>>>>[>>>>>>>>>]>[-]+<]]+>[-<[>>>>>>>>>]<<<<<<<<]>
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   379
>>>>>>>]<<<<<<<<<[<<<<<<<<<]>>->>[-<<<<+>>>>]<<<<[->>>>+<<[-]<<]>>]<<+>>>>[-<<<<
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   380
->>>>]+<<<<[->>>>-<<<<<<.>>]>>>>[-<<<<<<<.>>>>>>>]<<<[-]>[-]>[-]>[-]>[-]>[-]>>>[
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   381
>[-]>[-]>[-]>[-]>[-]>[-]>>>]<<<<<<<<<[<<<<<<<<<]>>>>>>>>>[>>>>>[-]>>>>]<<<<<<<<<
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   382
[<<<<<<<<<]>+++++++++++[-[->>>>>>>>>+<<<<<<<<<]>>>>>>>>>]>>>>+>>>>>>>>>+<<<<<<<<
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   383
<<<<<<[<<<<<<<<<]>>>>>>>[-<<<<<<<+>>>>>>>]<<<<<<<[->>>>>>>+[-]>>[>>>>>>>>>]<<<<<
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   384
<<<<[>>>>>>>[-<<<<<<+>>>>>>]<<<<<<[->>>>>>+<<<<<<<[<<<<<<<<<]>>>>>>>[-]+>>>]<<<<
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   385
<<<<<<]]>>>>>>>[-<<<<<<<+>>>>>>>]<<<<<<<[->>>>>>>+>>[>+>>>>[-<<<<->>>>]<<<<[->>>
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   386
>+<<<<]>>>>>>>>]<<+<<<<<<<[>>>>>[->>+<<]<<<<<<<<<<<<<<]>>>>>>>>>[>>>>>>>>>]<<<<<
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   387
<<<<[>[-]<->>>>>>>[-<<<<<<<+>[<->-<<<+>>>]<[->+<]>>>>>>>]<<<<<<[->>>>>>+<<<<<<]<
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   388
+<<<<<<<<<]>>>>>>>-<<<<[-]+<<<]+>>>>>>>[-<<<<<<<->>>>>>>]+<<<<<<<[->>>>>>>->>[>>
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   389
>>>[->>+<<]>>>>]<<<<<<<<<[>[-]<->>>>>>>[-<<<<<<<+>[<->-<<<+>>>]<[->+<]>>>>>>>]<<
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   390
<<<<[->>>>>>+<<<<<<]<+<<<<<<<<<]>+++++[-[->>>>>>>>>+<<<<<<<<<]>>>>>>>>>]>>>>+<<<
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   391
<<[<<<<<<<<<]>>>>>>>>>[>>>>>[-<<<<<->>>>>]+<<<<<[->>>>>->>[-<<<<<<<+>>>>>>>]<<<<
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   392
<<<[->>>>>>>+<<<<<<<<<<<<<<<<[<<<<<<<<<]>>>>[-]+>>>>>[>>>>>>>>>]>+<]]+>>>>>>>[-<
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   393
<<<<<<->>>>>>>]+<<<<<<<[->>>>>>>-<<[-<<<<<+>>>>>]<<<<<[->>>>>+<<<<<<<<<<<<<<[<<<
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   394
<<<<<<]>>>[-]+>>>>>>[>>>>>>>>>]>[-]+<]]+>[-<[>>>>>>>>>]<<<<<<<<]>>>>>>>>]<<<<<<<
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   395
<<[<<<<<<<<<]>>>>[-]<<<+++++[-[->>>>>>>>>+<<<<<<<<<]>>>>>>>>>]>>>>-<<<<<[<<<<<<<
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   396
<<]]>>>]<<<<.>>>>>>>>>>[>>>>>>[-]>>>]<<<<<<<<<[<<<<<<<<<]>++++++++++[-[->>>>>>>>
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   397
>+<<<<<<<<<]>>>>>>>>>]>>>>>+>>>>>>>>>+<<<<<<<<<<<<<<<[<<<<<<<<<]>>>>>>>>[-<<<<<<
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   398
<<+>>>>>>>>]<<<<<<<<[->>>>>>>>+[-]>[>>>>>>>>>]<<<<<<<<<[>>>>>>>>[-<<<<<<<+>>>>>>
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   399
>]<<<<<<<[->>>>>>>+<<<<<<<<[<<<<<<<<<]>>>>>>>>[-]+>>]<<<<<<<<<<]]>>>>>>>>[-<<<<<
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   400
<<<+>>>>>>>>]<<<<<<<<[->>>>>>>>+>[>+>>>>>[-<<<<<->>>>>]<<<<<[->>>>>+<<<<<]>>>>>>
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   401
>>]<+<<<<<<<<[>>>>>>[->>+<<]<<<<<<<<<<<<<<<]>>>>>>>>>[>>>>>>>>>]<<<<<<<<<[>[-]<-
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   402
>>>>>>>>[-<<<<<<<<+>[<->-<<+>>]<[->+<]>>>>>>>>]<<<<<<<[->>>>>>>+<<<<<<<]<+<<<<<<
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   403
<<<]>>>>>>>>-<<<<<[-]+<<<]+>>>>>>>>[-<<<<<<<<->>>>>>>>]+<<<<<<<<[->>>>>>>>->[>>>
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   404
>>>[->>+<<]>>>]<<<<<<<<<[>[-]<->>>>>>>>[-<<<<<<<<+>[<->-<<+>>]<[->+<]>>>>>>>>]<<
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   405
<<<<<[->>>>>>>+<<<<<<<]<+<<<<<<<<<]>+++++[-[->>>>>>>>>+<<<<<<<<<]>>>>>>>>>]>>>>>
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   406
+>>>>>>>>>>>>>>>>>>>>>>>>>>>+<<<<<<[<<<<<<<<<]>>>>>>>>>[>>>>>>[-<<<<<<->>>>>>]+<
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   407
<<<<<[->>>>>>->>[-<<<<<<<<+>>>>>>>>]<<<<<<<<[->>>>>>>>+<<<<<<<<<<<<<<<<<[<<<<<<<
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   408
<<]>>>>[-]+>>>>>[>>>>>>>>>]>+<]]+>>>>>>>>[-<<<<<<<<->>>>>>>>]+<<<<<<<<[->>>>>>>>
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   409
-<<[-<<<<<<+>>>>>>]<<<<<<[->>>>>>+<<<<<<<<<<<<<<<[<<<<<<<<<]>>>[-]+>>>>>>[>>>>>>
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   410
>>>]>[-]+<]]+>[-<[>>>>>>>>>]<<<<<<<<]>>>>>>>>]<<<<<<<<<[<<<<<<<<<]>>>>[-]<<<++++
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   411
+[-[->>>>>>>>>+<<<<<<<<<]>>>>>>>>>]>>>>>->>>>>>>>>>>>>>>>>>>>>>>>>>>-<<<<<<[<<<<
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   412
<<<<<]]>>>]""")
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   413
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   414
compile_run("""
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   415
>+>+>+>+>++<[>[<+++>-
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   416
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   417
  >>>>>
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   418
  >+>+>+>+>++<[>[<+++>-
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   419
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   420
    >>>>>
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   421
    >+>+>+>+>++<[>[<+++>-
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   422
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   423
      >>>>>
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   424
      >+>+>+>+>++<[>[<+++>-
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   425
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   426
        >>>>>
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   427
        +++[->+++++<]>[-]<
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   428
        <<<<<
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   429
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   430
      ]<<]>[-]
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   431
      <<<<<
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   432
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   433
    ]<<]>[-]
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   434
    <<<<<
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   435
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   436
  ]<<]>[-]
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   437
  <<<<<
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   438
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   439
]<<]>.""")
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   440
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   441
// benchmarks
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   442
compile_run(""">++[<+++++++++++++>-]<[[>+>+<<-]>[<+>-]++++++++
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   443
[>++++++++<-]>.[-]<<>++++++++++[>++++++++++[>++
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   444
++++++++[>++++++++++[>++++++++++[>++++++++++[>+
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   445
+++++++++[-]<-]<-]<-]<-]<-]<-]<-]++++++++++.""")
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   446
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   447
//
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   448
compile_run("""++++[>++++<-]>[>+>++>[+++++++>]+++[<]>-]>>>>>>>>-.
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   449
<<<<.<..+++.<.>>>>.<<<.+++.------.>-.<<+.<------.""")
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   450
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   451
compile_run("""++++++++[->-[->-[->-[-]<]<]<]
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   452
>++++++++[<++++++++++>-]<[>+>+<<-]>-.>-----.>""")
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   453
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   454
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   455
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   456
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   457
// register to BF compiler
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   458
// https://gergo.erdi.hu/blog/2010-09-06-from_register_machines_to_brainfuck,_part_1/
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   459
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   460
*/
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   461
03530cb87cd0 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   462
}