Writing a Tiny Programming Language

Sooooo... I may have fallen down the language design rabbit hole and I'm here to show off some cool rocks I found that I think are maybe gems?

The boy from the netflix show Hilda pointing at a rock and saying "That's a cool rock.", then walking over to it.

First, what is a programming language?

Basically we want a tool to create programs with, back in the days of teletype machines(basically a typewriter strapped to a computer), the most natural representation was text. You had a keyboard, you knew how to type words, what if we could convert those words into machine instructions?

Wait, what is a program?

Fundementally, a program is just a list of instructions for the computer to do. Like, literally a list.

get 'a'
get 'b'
multiply the last 2 things
number 1
add the last 2 things
set 'c' to the last thing

or, in traditional math notation:

c = (a * b) + 1

or in postfix notation, aka reverse polish notation (we'll be using this a lot later):

a b * 1 + set(z)

A diagram of a text file passing into a compiler and becoming an executable A diagram of a text file passing into a compiler and becoming an executable

Traditionally, this is made of a text file (like a .c or .py file), which gets passed to a compiler (.exe) via the command line.

Let's break it down into Words, Numbers, and Symbols

Introduction to parsing

Parsing math expressions with 'Precedence Climbing'

Programs are lists of instructions.

struct magic {
	
};
OpCodeC equivelant
add a ba + b
sub a ba - b
mul a ba * b
div a ba / b
mod a ba % b
call arg-count funcfunc(a, b, c, etc..)