dreasgrech / yabfcompiler

Yet another brainfuck (and Ook!) compiler...
http://blog.dreasgrech.com
1 stars 1 forks source link

What should be the size of each cell i.e. the type of array? #13

Closed dreasgrech closed 11 years ago

dreasgrech commented 11 years ago

I'm currently using a char[] for the domain array and char.MaxValue == 65535. A char in C# is a Unicode 16-bit character.

But when looking at some interpreters and other compilers, I've noticed that they use a byte for the size of the cells i.e. the range of each value in a cell would be [0, 255] rather than [0, 65535].

If I decide to go for the byte approach, I would need to change the type of the domain array to byte.

dreasgrech commented 11 years ago

I'm actually treating this as a bug now because basically all the compilers/interpreters I found use a byte.

Wikipedia says "The brainfuck language uses a simple machine model consisting of the program and instruction pointer, as well as an array of at least 30,000 byte cells initialized to zero".

dreasgrech commented 11 years ago

One program to test the byte cells would be:

.+[.+]

This program prints out the ASCII set.

dreasgrech commented 11 years ago

A byte in C# is an 8-bit unsigned integer, with a range of [0, 255]. In CIL, it's:

uint8

http://msdn.microsoft.com/en-us/library/cc230388(v=prot.20).aspx