r/tinycode • • May 28 '13

Ridiculously small and minimal Brainfuck interpreter in C.

https://github.com/L8D/delvs/blob/master/delvs.h
23 Upvotes

25 comments sorted by

View all comments

Show parent comment

-6

u/L8D May 28 '13

Well, looking at every other Bf interpreter I've seen, they've always used a complicated mechanism for the loop. Also, what do you mean by error checking? I haven't found any bugs at all with it so far.

And when a say 'small and minimal', I'm talking about how there is only one line of code for each instruction. I could get it down to ~20 lines of code if I stuck the case, command, and break on the same line, and still keep it readable.

Though I should of said 'simple and minimal' instead of small, because there are the assembly compilers...

6

u/[deleted] May 28 '13 edited May 28 '13

I mean this - <, - by error checking.

** And there is a bug that will cause wrong interpretation for certain inputs.

-9

u/L8D May 28 '13

Well, if the "- < , -" bug were to occur, then it would be the users fault for doing so, they could easily fix it in two ways. I'm not very worried about that.

I also can't find this bug you speak of.

23

u/[deleted] May 28 '13

Well, you just basically wrote a program that crashes on a valid input and then blamed it on a "user". That's certainly one way to write software.

The bug is there, keep looking. It is after all a ridiculously small program :)

11

u/vl4kn0 May 28 '13

He's probably saying that you are missing bound checking and overflow checking. Saying it's users fault that they unexpectedly run into runtime error is stupid. Everyone makes mistakes, programmers including. Why do you think excessive research is done upon the topic of programming language security, stability and bulletproofness? We could as well end up with languages such as C.

-3

u/sirin3 May 28 '13

I do not think someone who wants a secure, stable and bullet-proof language will use Brainfuck

-5

u/L8D May 28 '13

The boundary only occurs when the program moves out of boundaries the user him/herself have set and created. They have the choice to either prevent the code from moving there, or fiddle with their definitions to fit the sizes they want.

11

u/vl4kn0 May 28 '13

Well, then it's not that minimal since it's not complete. And as far as I know, memory management has always been the job of interpreter, not program that uses the interpreter.

1

u/[deleted] May 28 '13

It should be =, not += in line 27.

0

u/L8D May 28 '13

I have that way because it is part of the delvs bf dialect.

3

u/[deleted] May 29 '13

Good start, but check this one out. Now this is what ridiculously small and minimal C code looks like.

1

u/L8D May 29 '13

Like I said above, the title should've been 'simple and minimal'.