A toy programming language written in Go.
This language is based on the books "Writing An Interpreter In Go" and "Writing A Compiler In Go" by Thorsten Ball, but I intend to extend it further.
Why the name? The language is named after the football player Dominik Szoboszlai with jersey number 8 aka my fiance's favorite player :)
Just go run ./main.go for now and go with the flow from there
Showcasing some features:
// Variable binding
let age = 1;
let name = "Szoboszlai";
let result = 10 / 5;
// Data structures
let arr = [1, 2, 3, 4, 5];
arr[0]
let me = {"name": "Hong Anh", "age": 28"};
me["name"]
// Bind functions to names with implicit return
let explicitAdd = funk(a, b) { return a + b;}
let implicitADd = funk(a, b) { a + b};
let fib = funk(x) {
if (x == 0) {
0; // Implicit return
} else {
if (x == 1) {
1;
} else {
fib(x - 1) + fib(x - 2);
}
};
// Higher-order functions (functions that take other functions as arguments)
let twice = funk(f, x) {
return f(f(x)); // Call the function passed as an argument two times
};
let addTwo = funk(x) {
return x + 2;
};
twice(addTwo; 2); // Return the value of the first call... and many more!
Compilers
- Compile on RV64
- Compile to WebAssembly?
Operators
-
?as ternary operator -
~as bitwise NOT operator -
^as bitwise XOR operator -
|as bitwise OR operator -
&as bitwise AND operator -
++for incrementing and--for decrementing -
go -
select -
match -
.to access fields
Object types
- Float
- Double
- Lambda functions (a subset of anonymous functions)
- LazyObject
- Comments
- Struct
- Tuple
- Generics
- Channels
- Interface
- Range
- Procedure
Statements
-
switch -
foreach -
for
Builtins & Libs
-
sleep -
map -
leftandrightto return child nodes of an AST node -
operatorto return the operator of an infix expression -
argumentsto return an array of nodes in a*ast.CallExpression -
childrenfunction to return child nodes
Macros
- Make
quoteandunquoteseparate keywords - Passing block statements to
quote/unquote
Other nasty stuff
- Upgrade macro error handling system
- Use
runeinstead ofbytefor chars - Error handling by values
- Rewrite the interpreter + compiler in Zig
Refs:
The project isn't mature enough yet but the spirit of the effort is this: https://justforfunnoreally.dev/