Thread: brain........ interpreter

  1. #1
    Registered User
    Join Date
    May 2010

    brain........ interpreter

    Ok, so i think there is something wrong with this because it was way too simple to write. I know it's a simple language, but still.

    I actually have no clue about the language, so could anyone with any background in brain........ help me out here?

    Also, I think I got the general idea of brain........ loops wrong.

    and, no functions, I know. Give me a break, I'm 14.

    #include <stdio.h>
    int main(int argc, char *argv[]){
    	int array[30000];
    	long int currentByte = 0;
    	char currentInput;
    	if(argc > 2){
    		printf("You sent too many arguments!\n");
    		return 0;
    	}else if(argc < 2){
    		printf("You didn't send any arguments!\n");
    		return 0;
    	FILE *fp;
    	if( (fp = fopen(argv[1], "r")) == NULL){
    		printf("File doesn't exist!");
    		return 0;
    	while((currentInput = fgetc(fp))!=EOF && currentInput != '['){
    		if(currentInput == '>'){
    		if(currentInput == '<'){
    		if(currentInput == '+'){
    		if(currentInput == '-'){
    		if(currentInput == '.'){
    		if(currentInput == ','){
    			array[currentByte] = fgetc(stdin);
    	if(currentInput == '['){
    		goto whileloop;
    	return 0;

  2. #2
    30 Helens Agree neandrake's Avatar
    Join Date
    Jan 2002
    you don't clearly state what it is you are trying to do, and what you need help with. it sounds like you are making an interpreter for some language? post a link to reference the language, otherwise we may not be able to help.

    your while loop condition will break if the input is '[', but then you use a goto to jump back to the loop if the input is a '['. i believe those bits of code invalidate eachother; there's no point in having them both. either '[' means stop or it doesn't, not both. maybe you're supposed to clear the array if you read in '[' but i wouldn't know.

    there are typically better constructs to use instead of goto statements, simply for readability. once you implement '[' properly, you should try not using a goto statement and see if the code reads any more clearly.
    Environment: OS X, GCC / G++
    Codes: Java, C#, C/C++
    AOL IM: neandrake, Email: neandrake (at) gmail (dot) com

  3. #3
    Registered User
    Join Date
    Sep 2006
    The language is called "brainphuck", with an f. You can read about it on Wikipedia.

    The only place for a goto is when you're nested inside a number of loops, and need to break out of more than one loop, at a time. Other than that, goto's should be gone.

    To get good help, the OP is going to have to ask good questions, and that's not the case here, so far.

    Show the input you are having problems with, and the output you want. Not many of us will be familiar with bfk, and will be lost without something to refer to as an example.

    What a language! Makes me laugh just to look at it.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Interpreter Features Question
    By audinue in forum C Programming
    Replies: 0
    Last Post: 10-19-2008, 07:29 AM
  2. So I wrote brain.......... interpreter
    By cboard_member in forum A Brief History of
    Replies: 6
    Last Post: 04-07-2006, 09:24 AM
  3. Mouse to have human brain
    By nickname_changed in forum A Brief History of
    Replies: 22
    Last Post: 03-10-2005, 05:39 PM
  4. brain vs. computer (brain wins hands down)
    By hk_mp5kpdw in forum A Brief History of
    Replies: 18
    Last Post: 09-17-2003, 08:41 PM
  5. Re: Girlfriend Post
    By PsychoBrat in forum A Brief History of
    Replies: 57
    Last Post: 05-13-2002, 06:11 AM