invisible programming language

This esoteric The language was created by Edwin Brady and Chris Morris in 2003 and, of course, is not intended for practical use, existing as a kind of challenge for programmers – like, try to debug invisible code.

So, as you already understood, the main feature of whitespace is that its entire alphabet consists of only 3 non-printable characters: space, tab, and line feed. A piece of code in this language looks like a large indent, and, interestingly, any characters except these 3 are simply skipped by the interpreter, and they can be used as comments. It follows that this language can be embedded into existing programs or documentation, unnoticed by the average reader – well, in case you really want to play spy.

For the sake of readability, let us agree on the following conventions within this article: S – space, T – tabulation, L – line break.

How do commands work in this language?

Let's look at the skeleton of each language command:

Firstlyeach command contains a so-called IMP or instruction modification parameter – en. instruction modification parameter (When your language consists of only 3 characters, it is foolish to expect that it will execute a lot of commands. But we can expand their number, due to the combination of IMP + Main command, so you can treat IMP simply as a way to increase the functionality of the language)

Secondlythe main command itself (for example, addition, push to the stack, program termination, etc.)

And thirdlyits argument (if any), almost always the arguments will be a binary number. I think this is the only data type we are going to consider in this article.

So, usually the command parameter is a binary number.

But how can we represent binary numbers in this language?

Remember, we only have 3 characters, so this will require a bit of creativity. The creators of the language came up with the following:

They decided to represent binary numbers with tabs and spaces, instead of ones and zeros. A tab would be a one, and a space would be a zero. (Translator's note: the first sign of each binary number stores a + or -. Space for positive and tab for negative)

But another problem arises: How do we know when a binary number ends?

For example, we have the following program: Our IMP= S, the main command will also be S, and we want to pass the binary number SSTSTT to it. Then it will look like this: SS SSTSTT

And the next command will start right here, SSSSTSTTSS

But how does the computer know where the number ends and the next command begins? To do this, we use the last remaining symbol in the language: the line break L. Binary numbers are fairly easy in this language, since they always end with a line break.

So when you think about a binary number in whitespace, just remember that the first character is the sign, tabs are ones, spaces are zeros, and you always end the number with a newline, and you'll be fine.

IMP

Now I will tell you about all IMPs – there are 5 types, each of which does something different. Each IMP has commands specific to it (I have put this in the picture below)

Whitespace IMPs

Whitespace IMPs

That is, when you write an IMP, after it you can write one command from a set specific to the selected IMP.

Let's quickly run through them:

  1. Manipulations over the stack. This IMP is denoted simply by the space S, and the commands belonging to it are typical for any stack: push, pop, etc.

  2. Arithmetic. It is designated by the combination TS, and implies continuation in the form of addition, multiplication, subtraction, etc. commands. In this article, we will not consider arithmetic examples, but you can do it yourself.

  3. Heap access – is only for storing and retrieving data. This IMP is TT. I will not give an example here, but again, if you really want to store and retrieve some data, you can do it.

  4. Flow control – it will be difficult for me to explain the sacred meaning of this IMP, but I will say that we designate this IMP with the line feed symbol L, and, for example, we can correctly terminate our program with it. It is like control of the place where we are in the program. With the help of this IMP, we can also place marks in the code, and then return to them, implementing the concept of a cycle.

  5. Input/Output – The final IMP, and probably the most important one for us. It is denoted by TL and allows us to work with input and output. For example, consider the print command – as stated on the official website (you can check it out here , as it has long since been taken down from hosting) this command simply prints to the console the ASCII representation of the number on the top of the stack. This program does not take any arguments, it simply prints what is on the top of the stack.

Now that we have at least a rough basis for how whitespace commands work, let's try writing something very simple, like printing the letter A to the console.

Yes, we don't have letters in Whitespace, we only have 3 symbols, from which we can compose commands and binary numbers. As was said above, the print command prints to the console the ASCII representation of the top number in the stack (translator's note – actually, there are 2 variations of the print command in whitespace – one (ST) prints the number, and the second (SS) – its ASCII representation, that is, the symbol). If you don't know what ASCII is, then I'll tell you briefly – it's just a table that assigns a certain number to almost every existing symbol. Let's leave the standard part of the ASCII table here:

ASCII table

ASCII table

We see that in this table the number 65 corresponds to the letter A. It is not difficult to represent it in binary form, since it is 64+1, that is, 1000000+1 = 1000001

Don't forget about the positive sign before the number, which is represented by a space, and then translate our 1000001 into tabs and spaces. We get: STSSSSSTL – at the end, don't forget the newline symbol.

Let's divide our program into 2 parts:

Part 1 – put the number on the stack

Part 2 – we call the print command in the console

Part 1: Implementation. As we remember, for any operations on the stack we need a corresponding IMP – operations on the stack are S.

Now we need the actual command to push the number onto the stack. As luck would have it, this command is also S. Then we pass in the parameter – our number that we are pushing onto the stack (STSSSSSTL).

Total team 1: SSSTSSSSSTL

S is the stack IMP, S is the push command, S is the + sign indicating that the next binary number will be positive, TSSSSST is the binary representation of the number 65, L is the end of binary sign, and since this command takes only 1 argument, the end of command sign respectively.

Part 2: Implementation

We use Input-output IMP: TL, then the print command, represented by the characters SS. Once again, I repeat that it does not take any arguments, but simply looks at the stack, and prints the number from there. So the 2nd command: TLSS

In fact, we could have finished here, the code would have worked anyway. But it is considered good form to tell the interpreter to terminate the program explicitly. To do this, we will add a 3rd command that will terminate the program:

It will consist of flow control IMP – L, and program termination command – LL. Thus, the 3rd command as a whole: LLL

We combine all 3 commands and get: SSSTSSSSSTLTLSSLLL – our first program!

I wrote a small piece of java code that translates the program as it is into real non-printable characters, I'll leave it here:

public class LettersToWhitespace {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        String whitespaceCodeAsLetters = scanner.nextLine();
      
        for(char c : whitespaceCodeAsLetters.toLowerCase().toCharArray()){
            if(c=='s') System.out.print("\s");
            if(c=='t') System.out.print("\t");
            if(c=='l') System.out.print("\n");
        }
    }
}

I will also leave links to online whitespace interpreters: once And two

Our code actually ran and printed the letter A to the console, hooray.

Total:

To avoid thinking of the language as a complete jumble of symbols (oh my gosh, my code isn't working and I'm just staring at a white screen!), think of it as combinations of its essential elements: the IMP, a particular command, the parameters of that command, and its completion.

If we wanted to print more letters, we could repeat this code several times with different symbols. I will leave here an example that prints “Hello, world of spaces!” to the console – the example was borrowed from here

SSSSLSSSTSSTSSSLTTSSSSTLSSSTTSSTSTLTTSSSSTSLSSSTTSTTSSLTTSSSSTTLSSSTTSTTSSLTTSSSSTSSLSSSTTSTTTTLTTSSSSTSTLSSSTSTTSSLTTSSSSTTSLSSSTSSSSSLTTSSSSTTTLSSSTTTSTTTLTTSSSSTSSSLSSSTTSTTTTLTTSSSSTSSTLSSSTTTSSTSLTTSSSSTSTSLSSSTTSTTSSLTTSSSSTSTTLSSSTTSSTSSLTTSSSSTTSSLSSSTSSSSSLTTSSSSTTSTLSSSTTSTTTTLTTSSSSTTTSLSSSTTSSTTSLTTSSSSTTTTLSSSTSSSSSLTTSSSSTSSSSLSSSTTTSSTTLTTSSSSTSSSTLSSSTTTSSSSLTTSSSSTSSTSLSSSTTSSSSTLTTSSSSTSSTTLSSSTTSSSTTLTTSSSSTSTSSLSSSTTSSTSTLTTSSSSTSTSTLSSSTTTSSTTLTTSSSSTSTTSLSSSTSSSSTLTTSSSSTSTTTLSSSSLTTSSSSSLLSTSTTTSTTTSTTTSSTSSTTSTSSTSTTTSTSSSTTSSTSTLLSTSTTSTTTSSTTSSTSTSTTTSTTTSTTSTTSSSTTSTSSTSTTSTTTSSTTSSTSTLLLLLSSSTTSSSSTSTTSSTSSSTTSSTSSLTSSSLTLLSSSTTTSTTTSTTTSSTSSTTSTSSTSTTTSTSSSTTSSTSTLSLSTTTSLSLTSSTTTSTTTSTTTSSTSSTTSTSSTSTTTSTSSSTTSSTSTSTSTTTTTSTTSSTSTSTTSTTTSSTTSSTSSLTLSSSSSTLTSSSLSLSTTTSTTTSTTTSSTSSTTSTSSTSTTTSTSSSTTSSTSTLLSSSTTTSTTTSTTTSSTSSTTSTSSTSTTTSTSSSTTSSTSTSTSTTTTTSTTSSTSTSTTSTTTSSTTSSTSSLSLLSLLLTLLSSSTTTSSTSSTTSSTSTSTTSSSSTSTTSSTSSLSLSSLSTLTSTTTSLSSSSTSTSLTSSTLTSSTTTSSTSSTTSSTSTSTTSSSSTSTTSSTSSSTSTTTTTSTTSSTSTSTTSTTTSSTTSSTSSLSLLSSSTLTSSSLSLSTTTSSTSSTTSSTSTSTTSSSSTSTTSSTSSLLSSSTTTSSTSSTTSSTSTSTTSSSSTSTTSSTSSSTSTTTTTSTTSSTSTSTTSTTTSSTTSSTSSLSLLSSSTLTSSSSSSSLTTSLTLLSSSTTSTTTSSTTSSTSTSTTTSTTTSTTSTTSSSTTSTSSTSTTSTTTSSTTSSTSTLSSSTSTSLSSSTTSTLTLSSTLSSLT

This concludes this article, thank you all for your attention.

If it works, I'll make a sequel where I'll use all the IMPs in practice and give many more examples of whitespace code, and maybe even write my own readable wrapper for its commands

Sources and useful links:

Downloading whitespace sources: here

Online interpreters: once And two

Perhaps the most comprehensive video on the language to date: YouTo

Similar Posts

Leave a Reply

Your email address will not be published. Required fields are marked *