Your challenge is to take input like this (a Hello World program):
++++++++[>++++[>++>+++>+++>+<<<<-]>+>+>->>+[<]<-]>>.>---.+++++++..+++.>>.<-.<.+++.------.--------.>>+.>++.
And output a prompt (which will be "> "
):
>
The user can then enter anything at the prompt. Your simple debugger must have these commands:
S
- step- Output the current location (see
L
) after stepping. S(a positive integer)
- step that many spaces
- Output the current location (see
L
- location- The term "location" always refers to where you are in the program (i.e., the instruction pointer).
Formatted like this:
v +++++++[>+++++++<-]>.
This means that the current location of the program is at the third
+
.
G(an integer)
- go to- This means keep stepping until you get to that location. If you reach the end of the program and you haven't gotten there, simply exit the program.
- A negative integer means that many characters from the end. Yes, this means that
-0
is different than0
, and-1
is the second to last character. - Don't output anything for this command.
D
- dump array- Formatted like
1, 2, 3, 4, 5
- If the array is
1, 2, 3, 0, 0, 0, 0, 0, ...
, only output1, 2, 3
. D(a positive integer) (a positive integer)
- dump all array items between those two positions (inclusive)
- Formatted like
(a positive integer)
- output the item currently at that array positionP
- output the index of the BF pointer (the thing you change with>
and<
).
When the program requests input, show the prompt "I> "
. (You may input one character at a time.)
When it outputs something, show "O> " + (the output)
. Multiple outputs between commands must be chained together (i.e. you can't do > G-0 O> H O> e O> l O> l O> o ...
, it has to be > G-0 O> Hello, World!
).
Output "Done" and exit once you reach the end of the program.
Sample run:
++++++++[>++++[>++>+++>+++>+<<<<-]>+>+>->>+[<]<-]>>.>---.+++++++..+++.>>.<-.<.+++.------.--------.>>+.>++.
> S
1
> S
2
> S2
4
> S0
4
> L
v
++++++++[>++++[>++>+++>+++>+<<<<-]>+>+>->>+[<]<-]>>.>---.+++++++..+++.>>.<-.<.+++.------.--------.>>+.>++.
> D
4
> 0
4
> D10 15
0, 0, 0, 0, 0, 0
> G-0
O> Hello, World!
Done
Sample run showing stepping through loops and the P
instruction (calculates 3*2+1
)
+++[>++<-]>+
> S3
3
> L
v
+++[>++<-]>+
> S3
6
> L
v
+++[>++<-]>+
> P
1
> S3
9
> L
v
+++[>++<-]>+
> S
3
> L
v
+++[>++<-]>+
> D
2, 2
>
Sample run showing I/O
>+[>,---------------------------------]<[<]>[>.]
> G37
I> H
I> e
I> l
I> l
I> o
I> !
> D
0, 39, 68, 75, 75, 78
> G-0
O> 'DKKN
Done
This is code-golf, so the shortest code will win.