I’ve always wanted to make a programming language. I’ve known how they work for a while, but this is my first (completed) programming language. It has bugs and the design could definitely be improved by a lot, but it’s a starting point.
Here’s a simple Fizzbuzz program in Telid:
let fn fizzbuzz n =
if == % n 15 0
'FizzBuzz'
else if == % n 3 0
'Fizz'
else if == % n 5 0
'Buzz'
else
n;
for i in .. 1 15 println(fizzbuzz(i));
let count = 15;
while < count 30 {
count = + count 1;
println(fizzbuzz(count));
}
How It Works
Telid has three stages (all written in Rust):
- The lexer first scans the tokens and outputs a
Vec<Token>
- The parser (using Chumsky) outputs an AST (here, I decided to represent the top level as a
Vec<Statement>
) - The evaluator then evaluates the AST given to it
Error reporting is done with Ariadne.
What I Could Improve
Of course, being my first language and a learning project, Telid has many issues. If I were to redo it, this is what I would do from the beginning:
- Use infix notation (prefix was simpler for me to implement)
- Use postfix for array indexing, not prefix (I couldn’t get postfix to work, and I didn’t spend too much time trying to get it to)
Good error reporting – only the lexer and parser have good (decent, at the very least) error reporting; the evaluator simply outputs an error without the location, which makes for a horrible experience for anyone using the language– This has been fixed! See commit 740bd2b- Figure the semicolon thing out
Leave a Reply