Skip to main content

Indie game storeFree gamesFun gamesHorror games
Game developmentAssetsComics
SalesBundles
Jobs
TagsGame Engines

Update 1 - Implemented the basics.

So we have now implemented a really really basic pseudo-interpreter. It doesn't do very much right now. But it can now recognize basic program commands. This is a great start.

So here you can see how this works. On the right side is the editor window. There I have three very basic commands.

int a = 1 + 2;
int b = 2 + 3;
int c = a + b;

So what our program does now is that it gets the text from the editor and then it does some basic stuff like trimming extra spaces, which is done by replacing double space with a single space, and adding a delimiter at the end of the text.

And then it loops through each character, checking if the character is part of a predefined words set. For example if it is the letter 'i', then it gets appended to a string variable called word. When the program comes across a white space, in the above case that would be after appending the letters 'i', 'n', and 't' into the variable word, it understands that the word is complete and then appends the word into an array called tokens. If the program comes across special characters or operators like ; (semicolon), <, >, +, -, etc. then also it would recognize the word is complete and append it to the tokens array. But this time, the special character is also appended into the array, as a separate element. For example, in the first line, when the program encounters a semicolon, the value in the word (which would be 2 in this case) is appended to the tokens array. However, unlike when it encounters a white space, the character ' ; ' is also appended to the tokens array.

This tokens array is the first line printed as the output on the right side. In this case it was:

[int,a,=,1,+,2,;,int,b,=,2,+,3,;,int,c,=,a,+,b,;]

After the entire code is tokenized, our program then sends the token to another function called interpreter (name arbitrary). This function right now splits the tokens array into small chunks called lines and prints one line at a time. This is done by looking for semicolons to split the array into different lines. The output of this is given in the image as:

[int,a,=,1,+,2]
[int,b,=,2,+,3]
[int,c,=,a,+,b]

Note that these line arrays do not contain semicolon. This is because semicolon is only used as a delimiter here and is omitted when appending to the array.

This is only less than about 1 percent of the actual work. But this is a promising start.