Question: How tiny a programming language can be ? Consider a minimalist workspace that only consists of 1 array and 1 pointer: unsigned int tape [

How tiny a programming language can be? Consider a minimalist workspace that only
consists of 1 array and 1 pointer:
unsigned int tape[4]={0,0,0,0};
unsigned int *ptr = &tape[0];
And a minimalist programming language that only consists of the following instructions:
Instruction Function C++ equivalent
> Move pointer one position to the right ++ptr;
Move pointer one position to the left --ptr;
+ Increment the contents of the pointer ++*ptr;
- Decrement the contents of the pointer --*ptr;
.(dot) Output the contents of the pointer cout *ptr endl;
,(comma) Take user input and store it at the place that
pointer is pointing to
cin >>*ptr;
[ If contents of the pointer are not 0, proceed, else
skip to its matching ]
while(*ptr !=0)
{
] If contents of the pointer are not 0, go back to its
matching [, else proceed
}// end while
Simulate the following programs and observe the output. Also explain what each of these
programs is doing?
Sample Instructions: ,+++. Add 3 to input
,[->++]>. Multiply the input by 2
a.,>,[>+-]>.[Solution available in the folder for this part]
b.>++[+++>-].
c.>,[->+[->-]]>>.How tiny a programming language can be? Consider a minimalist workspace that only
consists of 1 array and 1 pointer:
unsigned int tape [4]={0,0,0,0};
unsigned int ?(()()*)ptr=& tape [0];
And a minimalist programming language that only consists of the following instructions:
Simulate the following programs and observe the output. Also explain what each of these
programs is doing?
Sample Instructions:
a.,>,[>+-]>.
,+++. Add 3to input
,[++]>. Multiply the input by2
b.>++[+++>-].
[Solution available in the folder for this part]
c.>,[+[-]]>>.
I will also include the "solution" mentioned in our instructions:
#include
using namespace std;
void comma(unsigned int* ptr){
cout ">>";
cin >>*ptr;
}
int main(){
unsigned int tape[4]={0,0,0,0};
unsigned int* ptr = &tape[0];
comma(ptr); //,
++ptr; //>
comma(ptr); //,
--ptr; //
while (*ptr !=0){//[
++ptr; //>
++(*ptr); //+
--ptr; //
--(*ptr); //-
}//]
++ptr; //>
cout *ptr endl; //.
return 0;
}
 How tiny a programming language can be? Consider a minimalist workspace

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!