Code Monkey home page Code Monkey logo

sloth's Introduction

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.

sloth's People

Contributors

n4ze3m avatar

Stargazers

 avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.