proc main var prog := "++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.+." var mem := [0, 0, 0, 0, 0, 0, 0, 0] var ptr := 0 var pc := 0 from pc = 0 until pc = prog.len if prog.(pc) = '>' ptr += 01 else if prog.(pc) = '<' ptr -= 01 else if prog.(pc) = '+' mem.(ptr) += 01 else if prog.(pc) = '-' mem.(ptr) -= 01 else if prog.(pc) = ',' do get_char: mem.(ptr) else if prog.(pc) = '.' do show: mem.(ptr) as Char as Str else if prog.(pc) = '[' if mem.(ptr) = 0 var count := 0 from count = 0 if prog.(pc) = '[' count += 01 else if prog.(pc) = ']' count -= 01 fi fi until count = 0 pc += 01 loop drop count := 0 fi prog.(pc) = ']' else if prog.(pc) = ']' if mem.(ptr) != 0 var count := 0 from count = 0 if prog.(pc) = ']' count += 01 else if prog.(pc) = '[' count -= 01 fi fi until count = 0 pc += 1 loop drop count := 0 fi prog.(pc) = '[' ~ TODO double-check post-conditions for '[' and ']', since pc gets modified in ~ those blocks so pre-conditions will not necessarily be true anymore. fi ~ TODO fi ~ TODO fi fi fi fi fi fi pc += 01 loop ~do print: ptr ~do print: mem drop pc := prog.len drop ptr := 0 drop mem := [0, 0, 0, 0, 0, 0, 0, 0] drop prog return