Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/n4ze3m/sloth
Sloth is a simple interpeter written in Golang.
https://github.com/n4ze3m/sloth
golang interpeter programming-language sloth
Last synced: 9 days ago
JSON representation
Sloth is a simple interpeter written in Golang.
- Host: GitHub
- URL: https://github.com/n4ze3m/sloth
- Owner: n4ze3m
- License: mit
- Created: 2021-09-28T07:24:57.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2022-02-20T17:35:39.000Z (almost 3 years ago)
- Last Synced: 2024-11-19T21:52:42.575Z (about 2 months ago)
- Topics: golang, interpeter, programming-language, sloth
- Language: Go
- Homepage: https://sloth.n4ze3m.com/
- Size: 48.8 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Sloth
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.
## Syntax
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
1. Addition of two numbers
```shell
>>> var a = 10
>>> var b = 20
>>> a + b
30
```Note: Sloth support all basic arithmetic operations except `>=` and `<=`.
2. Function
```shell
>>> var add = fun(a,b) { return a + b};
>>> add(1,2)
3
```3. If else statement
```shell
>>> var isten = fun(a) { if(a == 10) { return "yes" } else { return "no"} }
>>> isten(10)
yes
>>> isten(11)
no
```4. String concatenation
```shell
>>> var say = "hello" + " " + "world"
>>> say
hello world
>>> var say = concat("hello", "world")
>>> say
hello world
```
5. Built-in functions- `len(a)`: returns length of array
- `concat(a,b)`: concatenates two strings6. Array
```shell
>>> var a = [1,2 + 2,3]
>>> a[0]
1
>>> a[1]
4
```## Build
1. WASM build
```shell
$ cd wasm
$ $ENV:GOOS="js"
$ $ENV:GOARCH="wasm"
$ go build -o ../build/sloth.wasm
```# Btw
I wrote this project based on Thorsten Ball's [Writing an Interpreter in Go](https://interpreterbook.com/).