Sloth is a simple interpeter written in Golang. This is hoby project for learning golang. I converted this to WebAssembly :) program, now i can run it on browser.
This is a simple syntax for sloth. currently, sloth works with following syntax in repl.
Variable declaration in sloth is like this:
var name = value
- Addition of two numbers
>>> var a = 10
>>> var b = 20
>>> a + b
30Note: Sloth support all basic arithmetic operations except >= and <=.
- Function
>>> var add = fun(a,b) { return a + b};
>>> add(1,2)
3- If else statement
>>> var isten = fun(a) { if(a == 10) { return "yes" } else { return "no"} }
>>> isten(10)
yes
>>> isten(11)
no- String concatenation
>>> var say = "hello" + " " + "world"
>>> say
hello world
>>> var say = concat("hello", "world")
>>> say
hello world- Built-in functions
len(a): returns length of arrayconcat(a,b): concatenates two strings
- Array
>>> var a = [1,2 + 2,3]
>>> a[0]
1
>>> a[1]
4- WASM build
$ cd wasm
$ $ENV:GOOS="js"
$ $ENV:GOARCH="wasm"
$ go build -o ../build/sloth.wasmI wrote this project based on Thorsten Ball's Writing an Interpreter in Go.