Note
This is a really simple language, just developed for fun (not production ready).
GoVetryx is an interpreter written in Golang for the Vetryx language.
I have been reading recently the AMAZING book Crafting Interpreters and it inspired me a lot to try those ideas out.
This language is based on the Lox language implementation in Java created by Robert Nystrom in the book mentioned above. I tried to follow the exact same implementation from the book (except for some tiny changes I did to the syntax and grammar, and some minor things I changed to experiment a bit on the topic). Since I changed some tiny things in the language, I added a different name for it: Vetryx.
It's been a while since I wanted to dive deeper into this topic, so this is just to do some practice around the concepts explained in the book.
- Refer to this doc to understand the syntax of the language, and some of its rules.
Some things I changed in comparison to the Lox language:
- Parentheses to wrap if/while conditions are not necessary (but can be added if wanted)
- Added modulus operator
- Changed some reserved words & chars used for some operators
- Added support for short variable declarator (eg:
a := 1
) - Added support for sleep, min and max native fns
- Support
break
andcontinue
in while loop
Coming next:
- Add support for structs
- Add support for arrays
- Add more native functions
This interpreter is coded in Golang. It's implemented as a Tree-Walk Interpreter (trying to follow the ideas and same implementation from the Java implementation in the Crafting Interpreters book, so all the credit goes to Bob Nystrom here - althought I tried out some slightly different implementations in some parts just for fun & to experiment a bit on this topic).
I developed a playground for it, using Next.js and NextUI. You can test it online here.
- I also intend to create a compiler later. But step by step :)
Thanks a lot Robert Nystrom for writing such a pleasant book to read, and to learn about! Also the code in the book is really easy to follow! One of the nicest books about software that I've read in the past years!