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