sloth

command module
v0.0.0-...-313cf9d Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 20, 2022 License: MIT Imports: 3 Imported by: 0

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
>>> var a = 10
>>> var b = 20
>>> a + b
30

Note: Sloth support all basic arithmetic operations except >= and <=.

  1. Function
>>> var add = fun(a,b) { return a + b};
>>> add(1,2)
3
  1. If else statement
>>> var isten = fun(a) { if(a == 10) { return "yes" } else { return "no"} }
>>> isten(10)
yes
>>> isten(11)
no
  1. String concatenation
>>> var say = "hello" + " " + "world"
>>> say
hello world
>>> var say = concat("hello", "world")
>>> say
hello world
  1. Built-in functions
  • len(a): returns length of array
  • concat(a,b): concatenates two strings
  1. Array
>>> var a = [1,2 + 2,3]
>>> a[0]
1
>>> a[1]
4

Build

  1. WASM build
$ 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.

Documentation

The Go Gopher

There is no documentation for this package.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL