Shiro Branch
Nevergarden
Posted on January 18, 2024
So I've been writing my own programming language for fun I decided to write a devlog series on what I'll be doing.
In my language I decided to omit if
else
and switch
or any conditional statement and instead use a singular statement called branch
.
It uses the same concept in CS Branching in a way that it will be much closer to it's mathematical implementation and result of this statement can be evaluated.
An example of a mathematical equation:
fx = branch x {
< 2 => { return 12; }
== 2 => { return 13; }
> 2 => { return 100; }
}
Another feature is that the inner block expressions will be evaluated:
var x := 4;
var m = 10;
var fx := branch x {
< 10 => { m = 12; return 5; }
>= 10 => { return 2; }
}
will result in x = 4
, m = 12
and fx = 5
.
(variable declaration for mutable and immutable variables are not finalized yet but var name = expr
is mutable variable declaration and var name := expr
is immutable variable declaration for now.)
For this statement I decided to add branch
=>
otherwise
tokens to lexer.
using otherwise
otherwise
is for any other condition in a mathematical function.
var y := branch {
x == 1 => { return 1; }
x == 2 => { return -1; }
otherwise => { return 0; }
}
so while evaluating y if x is any number except 1 or 2 y value would be 0.
Posted on January 18, 2024
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.