5

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:

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

user2124441
  • 125
  • 3
  • 10

2 Answers2

3

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.

Lynn
  • 10,425
  • 43
  • 75
2

There is no thorough language specification, but in most interpreters incrementing a cell which holds its maximal value (with the + command) will bring it to its minimal value and vice verse.

Etheryte
  • 24,589
  • 11
  • 71
  • 116