Close

Once Again I am Writing an Interpreter From Scratch

A project log for Pico Picow

A tiny handheld dev console, with a 12 button keypad, Pi Pico W inside, and 128x64 OLED.

gordonGordon 12/30/2024 at 10:510 Comments

My dream of writing a programming language that uses virtually no whitespace and as little symbols as possible is coming true. 

I have been playing around with the syntax a bit and found something to my liking. I will post a snippet of what I already have implemented and working in code, as well as a snippet of how I envision the larger syntax to look. It will look very similar to TGRK. TGRK was made the way it was for a very specific application. I think PGRK will be more universal.

Once I have it fully written in Python, I plan on writing it again in C.

On my Github, the original GORK programming language I started, I had the same concepts in mind that I wanted to accomplish, and was making some good progress on it, but, at the time, my knowledge of C was very limited. This was the second small project I was attempting after starting to learn C. So I ended up setting it aside, and started with MGRK, then that was too much, so moved on to SMGRK, which eventually turned into TGRK.

Enough history, I will get those code snippets.

The following piece of code will interpret and execute with the code I have running now, in any of the following whitespace configurations. Programming on a tiny device with a tiny screen, having the shortest possible keyword names as well as the ability to reduce whitespace to a minimum is a plus. Have you ever tried to read a large code page on a small screen? It is very frustrating.

On the Pico Picow, the line widths will be fixed to a maximum of 16 characters wide. There are several reasons for this. At this point I don't think I want to enable any wrapping, or having any text reach off the screen. The point is to have it all visible, and miniaturized enough that a lot can fit on that 16x8 character page.

0K20248K30O$Its December$, 8K,$th$, 0KI1KO1K

0K 2024
8K 30
O $Its December$, 8K,$th$, 0K 
I 1K 
O 1K

 What we have here is basic KEYWORD (variable) storage and retrieval, as well as some input and output.

Executed in the Python REPL, it outputs the following message, offers the user input which stores in the 1K KEYWORD, then outputs the message the user entered.

Creating and assigning a KEYWORD is done with "<n>K<value>" n can be any number from 0-99, and the value formats are as following:

An integer or float immediately following the K, or with any amount of whitespace between:

3K2045
3K 0
3K                                                                    72
3K 2.4928
3K


42

 The above are all valid. A string is created by using the $ symbol instead of quotes. It just made sense to do this.

12K $This is a string.$

12K
     $
       This is another string. We can format
        however we want.
     $

 Input will be like Python's input() function, which is completely blocking and can be typed into until the enter button is pressed. In PGRK, the input keyword is a single "I", immediately followed by the keyword we are storing the entered string into. I plan on adding keywords for getting individual keys and button presses for the Pico Picow, but as I am wanting to make a command line interface first, this will be helpful.

I 1K

The above takes input and stores it in the 1K keyword. It's that simple.

Output is even funnier! Output is done with a single "O" followed by the data we want to send out. On the Pico Picow, this means it will be getting sent to a function that displays it on the OLED display. But for testing, it gets printed to the python command line.

Output one value:

O123

Output two values, if there are more than one value to be sent out, they are separated by a comma. I was thinking about how I may or may not want to have spaces between these values. EASY. If you want a space, just add it after the comma. Adding more than one space will not add extra spaces. But if you don't want a space, don't add one and the data is contiguous.

O $Hell$,0

 Output with spaces, also visualized how It would look trying to enter something that long on a small screen.

OK3
1K2
O $Only$, OK, $d
ays$, $until$, $
January,$, 1K

O $Only$, OK,
$days$,
$until$,
$January,$,
1K

 There is no need to tell the interpreter to stop outputting the data. Once it reaches the last comma, it puts out the last value and passes the program pointer back to the main interpreter.

The above is what I have gotten working so far. Below are some concepts of how the rest of the syntax and functionality will look.

KEYWORDS:

There will be a lot of built in functions specific to the Pico Picow device, such as wifi handling, etc. various command line builtins that will be specific to controlling the hardware.

That's about all I have right now, have a happy new year and until next time!

Discussions