Question
Please provide an answer in C. Need help learning it and don't copy paste from the other questions. Need a straight C answer! thanks! Sample
Please provide an answer in C. Need help learning it and don't copy paste from the other questions. Need a straight C answer! thanks!
Sample BrainFuck programs:
Read an integer and write it back out: ;:
Read an integer and write out the number doubled: ;[->++:
You are to write an interpreter in C for the BrainFuck programming language. When run, your interpreter will check its command line arguments for the following (these arguments may be in any order): -v Run in verbose mode optional
-r Run the program repeatedly, optional.
filename The file which contains the Brainfuck source code, required. Brainfuck programs typically end in .b or .bf
If the -v flag was used, the CODE and DATA (the first 10 cells) will be displayed before every command in the BrainFuck program. Identify the locations of the Code Pointer and the Data Pointer. See the examples below for a sample.
If the -r flag was used, the interpreter will run the BrainFuck program repeatedly until killed (CtrlC). Otherwise, it will run it once and exit.
When the Brainfuck program reads an integer, prompt the user with a ?. When the Brainfuck program writes an integer, write the integer followed by a space (no newline). Additional
BrainFuck ge Description: BrainFuck is a very simple programming language notable for its extreme minimalism. It is not a practical language but one that was designed to challenge and amuse programmers. The language consists of only eight simple commands and an instruction pointer. A complete write-up is here https://en.wikipedia.org/wiki/Brainfuck. However, the version required for this project is slightly different in the reading and writing commands. Please read carefully To understand the language you must first understand the programming model. The model is made up of a sequence of characters that make up the CODE, and an unlimited sequence of integers that make up the DATA. A Code Pointer starts at 0, the location of the first command. A Data Pointer also starts at 0, the location of the first integer (also known as the current data element). All DATA integers are initialized to 0 with each run. Our version of this language is made up of the following eight, single-letter commands an Set the value of the current data element to an integer value supplied by the user. You should prompt the user with a '?" Print the current data element. Move the Data Pointer to the previous data element. Print an error and stop execution if the Data Pointer goes negative Move the data pointer to the next data element. There is no largest element. If the integer at the current data pointer is zero, move the Code Pointer to the right to the matching . Otherwise, do nothing. Print an error and stop execution if there is no matching brace. Move the Code Pointer left to the matching [. Print an error and stop execution if there is no matching brace ; : I 1 +Increment the current data element. Decrement the current data element. Data elements can go negative Spaces, tabs and newlines are ignored. A program is executed as follows 0. Set the Code Pointer and Data Pointer to 0. Initialize all the data elements to 0. 1. Get the command at the current Code Pointer 2. Execute the command 3. ncrement the Code Pointer 4. If there is another command at the Code Pointer, go to step 1 5. Otherwise, exit. BrainFuck ge Description: BrainFuck is a very simple programming language notable for its extreme minimalism. It is not a practical language but one that was designed to challenge and amuse programmers. The language consists of only eight simple commands and an instruction pointer. A complete write-up is here https://en.wikipedia.org/wiki/Brainfuck. However, the version required for this project is slightly different in the reading and writing commands. Please read carefully To understand the language you must first understand the programming model. The model is made up of a sequence of characters that make up the CODE, and an unlimited sequence of integers that make up the DATA. A Code Pointer starts at 0, the location of the first command. A Data Pointer also starts at 0, the location of the first integer (also known as the current data element). All DATA integers are initialized to 0 with each run. Our version of this language is made up of the following eight, single-letter commands an Set the value of the current data element to an integer value supplied by the user. You should prompt the user with a '?" Print the current data element. Move the Data Pointer to the previous data element. Print an error and stop execution if the Data Pointer goes negative Move the data pointer to the next data element. There is no largest element. If the integer at the current data pointer is zero, move the Code Pointer to the right to the matching . Otherwise, do nothing. Print an error and stop execution if there is no matching brace. Move the Code Pointer left to the matching [. Print an error and stop execution if there is no matching brace ; : I 1 +Increment the current data element. Decrement the current data element. Data elements can go negative Spaces, tabs and newlines are ignored. A program is executed as follows 0. Set the Code Pointer and Data Pointer to 0. Initialize all the data elements to 0. 1. Get the command at the current Code Pointer 2. Execute the command 3. ncrement the Code Pointer 4. If there is another command at the Code Pointer, go to step 1 5. Otherwise, exit
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started