Initial blueprint, and a lexer.
Before I wrote any code, I spent a while brainstorming features I wanted in this language.
I wanted something with simple syntax and few keywords. There are currently 18 keywords. No keyword has more than four letters.
I have yet to reserve names for types. I might stick with something similar to Rust for naming types.
Declarations
val Value (immutable).
var Variable (mutable).
fn
enum I intend to support storing values inside, like Rust.
obj Equivalent to a struct in Rust.
type Type alias or an interface.
ext Like an impl block in Rust.
Conditional
if
else
cmp Similar to Rust’s match statement.
Flow
ret Return.
loop Overloaded loop operator. Go uses for, this uses loop.
jmp Depending on context, this replaces continue and goto (though I intend to add constraints like Go for memory safety).
drop Acts as a break statement, dropping out of a labeled loop or scope. May take a return value.
Misc
in Used for iteration.
use Import.
pub Export.
del Manually delete a variable (free memory).
I’m considering two more keywords for a macro system later on, but I’m not going to invest energy into that quite yet.
- For the sake of simplicity, there will be no
:: operator. It will all be ..
- For type casting, I intend to use
-> instead of adding another keyword.
- To keep the parser simple, I’m looking at using square brackets instead of angled brackets for type generics, like Go does. I’m still deciding.
- I intend to support function variadics with
.. prefixing a parameter name.
- Like with Rust, labels will be prefixed by a single quote. I might change this.
I wrote a lexer for this with a bit of hacky TypeScript and RegExp. Don’t ask why it’s in TypeScript. I’m pretty sure I was half-asleep when I started this the other day, and it shouldn’t matter in the long run. If I can get this to transpile to C or something, I’ll bootstrap it.
For memory management, I don’t want a garbage collector. I don’t want Rust’s ownership system either. It would defeat the point of a simple language if you need to wrestle with the compiler so often. The current plan is to use RAII and manual freeing where needed. I’m considering an ARC hybrid with RAII or something later on, so memory management won’t be manual forever.