Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Print characters in brainfuck

I am new to this language and i am building brainfuck interpreter in scala i am facing one problem what should i print if the value at memory index is greater than 127 ? what a real brainfuck interpreter print if value is greater than 127? for eg
memory[index]=178 when "." (print command) is called what should a brainfuck iterpreter print ?
my compiled some codes on ideone.com but it showing runtime error .
for follwing code:

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++[+.<-]

like image 235
user2124441 Avatar asked Feb 15 '14 14:02

user2124441


1 Answers

The original implementation for . just calls putchar() with whatever unsigned char value is in the cell:

...
case '.': putchar(a[p]); fflush(stdout); break;
...

This means how characters 128-255 show up depends on what encoding your terminal uses. If I set mine to CP437, characters 32-255 look like this:

example output

In your case, Scala's toChar method on numbers sounds like it should do what you want; also, maybe ideone is just weird about printing extended ASCII.

like image 175
Lynn Avatar answered Sep 29 '22 06:09

Lynn