A programming language built just to my liking :)
Interpreter written in C++
Great for competitive programming (USACO / codeforces) because of the syntax
A programming language built just to my liking :)
Interpreter written in C++
Great for competitive programming (USACO / codeforces) because of the syntax
This was a pretty big update but I didn’t add anything that is syntaxically weird. I added functions, vectors, and strings.
Functions + Returns
fn name(args){...} and return expr.Strings
"string"
s[i]) and use len(s).Vectors (Dynamic Arrays)
[1, 2, 3].v[i].len(v)push(v, x)pop(v)Multidimensional vectors
[[1,2],[3,4]] just work.m[1][0]).Comments + Illegal Character Throwing
// or /* ... */
Reorganization
src/ has source codetest/ has testsbuild/ now contains the compiled binariesdocs/ contains docs/devlogs.Makefile + Testing
Makefile with nice commandsmake run launches REPL.make run <file.zpp> runs a file directly.test.zpp as a file with every command in the language and then wrote the expected output and made make test run the test script and compare output.Log in to leave a comment
Ok so in this devlog I spent a lot of time thinking about syntax and I would like some feedback about for loops.
First though, while loops were simple (not simple to implement these loops cooked me in coding but syntaxically simple), its just.
while boolean {
do this code here yeah
}
So while loops are very simple. Now for loops were a pain. I wanted them to be simple as this is meant to be super fast to write for competitive programming and the likes. So for this I took inspiration from my C++ template file.
#define FOR(i, a) for(int i = 0; i < a; i++)
#define ROF(i, a) for(int i = a; i >= 0; i--)
#define FORA(i, a, b) for(int i = a; i <= b; i++)
#define ROFA(i, a, b) for(int i = a; i >= b; i--)
That’s how I macro for loops during Codeforces contests. So instead of
for(int i=0;i<n;i++){...} I can just do FOR(i,n). Now I wanted something nice and simple for Zen++ to. So I landed on this:
A four loop has four components, the variable used, the start, the end, and the step. So why not instead of writing those as a declaration, a boolean, and an incrementation like in C++, just treat those almost as paramateres to a method. So thats what I did.
for i start end step {...}
Thats the syntax. If you want a reverse for loop you just make end bigger than start and step will be negative.
There is a 3-arg version which defaults step to 1 or -1 depending on direction and looks like: for i start end{...} and there is a 2-arg one which is: for i end{...} and defaults step to +1 and start to 0. So for codeforces you can just write for i n{...}. Very simple, but leave comments if you think its ugly. Its exclusive by default rn with no way to make it inclusive, I’ll fix that later.
Log in to leave a comment
I added if else statments to the code! The way an if else-if else statment will be written is like tihs:
if bool1{
x=1
}else if bool2{
x=2
}else{
x=3
}
Note the lack of parantehsis, you don’t rly need them beacuse you know your condition is just gonna be sandwiched between the if and the next curly brace. Also now that I added braces I made the parser handle the braces and the AST handle blocks of code.
What changed:
if, else, { and }.Log in to leave a comment
This step adds booleans and comparisons so I can start building if/else statements later. Booleans are just like they are in C++, a true boolean is a 1 and a false boolean is a 0.
What changed:
true/false and multi-character operators like ==, !=, <=, >=.!, while keeping postfix ! for factorial.Log in to leave a comment
I added variables and assignment. You can declare a variable like x=4 and reassign it like x=5
What changed:
Log in to leave a comment
So I did a few things:
Log in to leave a comment