
so i made a programming language.
it's called catscript. you print with cat, functions are called hunt, lists are called litter, and if you type fetch anywhere in your code it refuses to run, because this is a cat household.
try it in your browser: https://yupthatscole.github.io/catscript
(no install. the first load takes a few seconds because it's loading python into your browser.)
what it looks like
hunt double(x) { bring x * 2 } kittens = litter["mochi", "pip", "clover"] cat("there are", size(kittens), "kittens") cat("double 21 is", double(21)) there are 3 kittens double 21 is 42 /\_/\ ( ^.^ ) purr. it worked. > ^ < every program ends with a cat. a happy one if it worked. an angry one if it didn't.
the cat words
-
cat(x)prints something (it's also the linux command for printing files, so it's a pun twice) -
pspsps("name? ")asks the user for input. you're literally calling them over -
huntmakes a function,bringreturns something, because cats bring you things -
litter[1, 2, 3]is a list -
purrandhissare true and false -
empty_bowlis null -
knock(x)deletes a variable. knocks it off the table -
try { } pounce { }catches errors
errors
errors get a hiss code, a line number, and an insult.
HISS-404 (line 2): never heard of 'y'. did you make it up? did you write this while walking across the keyboard? /\_/\ ( >.< ) HISS. > ^ < dividing by zero is HISS-500: you can't split the fish into zero pieces. a function that calls itself forever is HISS-508: your cat is chasing its tail.
and the dog words (fetch, bark, goodboy, woof, sit, wag) are just banned:
HISS-403 (line 1, col 1): 'fetch'?? this is a cat household. how it works
i always assumed making a programming language was some crazy thing. it's actually three parts:
- the lexer reads your code and chops it into pieces.
cat("hi")becomescat,(,"hi",) - the parser turns those pieces into a tree, so it knows
1 + 2 * 3means do the2 * 3first - the interpreter walks through the tree and actually runs it
the whole thing is about 1,100 lines of python with no libraries.
the bug
the first time i typed my own code into the playground instead of using the examples, it crashed with a huge python error.
turns out the lexer looks two characters ahead to catch stuff like == and >=. if your code ended on something like ) with nothing after it, it looked at a character that didn't exist and fell off the end of the file.
it worked fine for me because all my example files ended with a blank line. so it only broke the second someone else used it. classic.
now if catscript itself ever crashes, you get HISS-999: catscript tripped over its own tail. this one's not your fault. instead of a wall of python.
it also runs in your browser and vs code
the playground runs the exact same python files in your browser using pyodide, so there's no separate version to keep updated.
there's also a vs code extension that gives .meow files syntax highlighting, a little cat icon, and a run button. dog words get a red squiggle.
try it
- playground: https://yupthatscole.github.io/catscript
- code: https://github.com/yupthatscole/catscript
write something in catscript and put it in the comments. i want to see what you make
meow