The full language spec can be found here.
For example Fibonacci series looks like this:
fun fibonacci(x: Int): Int {
if x == 0 or x == 1 then {
return x;
} else {
return fibonacci(x - 1) + fibonacci(x - 2);
}
}
var i: Int = 0;
while i <= 15 do {
print_int(fibonacci(i));
i = i + 1;
}Prequisites: Go 1.23.5
Clone the repository
git clone git:@github.com:tfhuhtal/compiler.git
cd compilerInstall dependencies
go mod tidyRun all tests
go test ./...Or run a specific test
go test -v ./parserRun the compiler:
go run main.go compile --input=<input> --output=<output-file>Run the compiler as server
go run main.go serve --host=0.0.0.0Then you can send request to the server, for example:
echo '{"command":"compile","code":"var x: Int = 10; var y: Int = 20; print_int(x + y);"}' | nc -w 2 -q 1 127.0.0.1 3000
Run the interpreter
go run main.go interpret --input=<input>for example
go run main.go interpret --input="var a: Int = 0; var b: Int = 1; var next: Int = b; var count: Int = 1; while count <= 50 do { print_int(next); count = count + 1; a = b; b = next; next = a + b;}"