Presenting Assistant Language. A programming language created with GPT3

Presenting Assistant Language. A programming language created with GPT3

Ok, so you probably heard about OpenAI's chatbot. It's the most advanced chatbot created so far. It can help people with LaTeX questions, find bugs in code or solve code challenges.

What I tried for this post is something different. I instructed ChatGPT to create a programming language for me and become the interpreter for that programming language.

I took the idea and a few useful instructions from this blog post.

Let's start simple

I started instructing the bot to create a simple language with an instruction to print. Also, it has to act as the interpreter of that language. To keep communicating with the bot I added a special format with slashes and quotes. Here's the result:

Language explanation Part I
Language explanation Part II

If you want to use my prompt, here it is

I want you to create a new programming language. It has to provide only an instruction for printing something to screen. I want you to explain to me how to use it in a concise way. After that, you will become an interpreter of that language. Answer with the execution result inside one unique code block, and nothing else. Only write explanations if the code contains errors. When I need to tell you something in English, I will put text inside forward slashes and double quotes /"like this"/.

Ok, looks good so far. Let's try the interpreter.

Interpreter response

It looks like it worked!

Adding functionality to the programming language

Let's try to add some more functionality to our new programming language.


Ok, using the slashes and quotes format I'll try to add variables to the programming language.

Variables explanation Part I
Variables explanation Part II

Again, looks promising, let's try the interpreter.

Result of the variables execution

Arithmetic operators

Now, the same thing but with arithmetic operators.

Arithmetic operators explanation Part I
Arithmetic operators explanation Part II
Arithmetic operators explanation Part III

Now that we know how to use it, let's try it:

Testing arithmetic operators

Logic operators

Now, I'll try to add logic operators to the language, but without instructing first about data types or anything else:

Logic operators explanation Part I
Logic operators explanation Part II
Logic operators explanation Part III

I haven't talked about conditionals or flow control structures, but it added the ternary operator when asked to include logic operators. It may mean that GPT already "knows" the language, just telling me how to use every piece of it when I ask.

Let's try these new operators:

Testing conditionals

If statement

I don't want to bias the bot so I won't ask it to add if structure. Instead, I'll ask for a flow control structure for branching based on condition:

Conditionals Part I
Conditionals Part II
Conditionals Part III

Well... exactly what I had in mind... Testing time!

Testing if block

Comparison operators

I almost forgot about a crucial part of a programming language, the comparison operators!! Let's add them to our language.  

Comparison operators Part I
Comparison operators Part II
Comparison operators Part III
Comparison operators Part IV

Ok, now let's see how it behaves:

Testing comparison operators


Again, for not biasing the bot, I'll ask for structures to loop or iterate.

Looping Part I
Looping Part II
Looping Part III
Looping Part IV

Ok, so it added a classic for loop as well as a while loop...

For loop

Hmmm... and what if I try to run an infinite loop?

Infinite loop

It detects it and prevents me from running it!


The next step is to add functions to our new programming language.

Functions Part I
Functions Part II

Wow, we also can return multiple values and unpack them...

Testing functions

Utility functions

Let's see if we can create some "global" utility functions to make our life easier.

Random numbers Part I
Random numbers Part II

Let's try to generate some random numbers:

Random numbers loop

And if we try to add a function to get the current date?

Getting the current date

Let's do a little test:

Date test

So GPT knows which day it is, but not which time. Interesting.

Interact with the underlying OS

Shell commands Part I
Shell commands Part II

It already warns me about the shell function but, of course, I'll try to mess up to see if we can figure out something.

Shell test

For the first time, it included an explanation along with the output, even though there are no errors. Also, the waning message is there again.

Let's keep testing.

Testing for ls

For some reason, it explains the command instead of executing it. Maybe because it knows that the output won't be the same every time?

Shell test II

Did it really create the file? Or is it just "assuming" what would happen...

Apparently, it created it... Let's do another test for getting the contents of the root directory.

Hmmm, is the same output as the previous example but with the test dir...

Nope, it doesn't exist...

Ok, enough messing with the underlying OS.

Some advanced features

Would GPT be able to add pointers to our language?

Pointers Part I
Pointers Part II

So... we have pointers now!

And it also works!

Naming the language

Nice, I like Assistant Language, let's use it!

Would it be able to implement something in this language?

Not the most efficient version, but definitely in Assistant Language. Let's test it:

It actually works!

Wrap it up and provide an interpreter

I want the bot to generate a document with the language specification as well as an interpreter implemented, for example, in Python. Let's try!

You can see the full README here.

And finally... the interpreter.

It implemented an interpreter that supports only "let" and "print" statements... Let's see if I can get something more complete.

This looks way better! We don't have pointers, but it seems that everything else is supported.

You have all the code available here.

I hope more people try something like this and see how far it can get in adding functionality to the language!