Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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;
}
image text in transcribed

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Genomes And Databases On The Internet A Practical Guide To Functions And Applications

Authors: Paul Rangel

1st Edition

189848631X, 978-1898486312

More Books

Students also viewed these Databases questions