Skip to content

michaelbdev/lua-monkey

Repository files navigation

lua-monkey

lua-monkey is a lua implementation of a tree-walking interpreter for Monkey.

Extensions

My monkey implementation has been extended to support the following new features:

  • Friendly error messages that display the offending line of code and underline the exact location of the error.

  • arrow functions e.g let adder = fn x => fn y => x+y; adder(1)(2) let adder = fn(x,y)=> x+y

  • Default parameters let add = fn (x,y=1) => x+y; add(1); //2 add(10,90); //100

  • for in loops for(item,index in [1,2,3,4]){ puts(item+index)}

  • Ability to run monkey files (.mo extension)

  • comments (both single and multi line) // a comment! /* a multiline comment */

  • Logical OR and logical AND operators

  • <= and >= operators

  • % operator

  • String comparison

  • String indexing

  • more builtin functions

    • map map([1,2,3,4], fn x => x*2)
    • find find(["hello", "world"], fn w => w=="hello")
    • reduce reduce([1,2,3,4], fn(acc,curr) => acc+curr,100)
    • filter filter([1,2,3,4], fn x => x%2==0)
    • set let map = { "a": 1 }; set(map,"b",2); map["b"] //2

Run

Clone the project

  git clone https://github.com/michaelbdev/lua-monkey

Go to the project directory

  cd lua-monkey

Install dependencies

  luarocks install --only-deps  lua-monkey-0.1.0-1.rockspec

Using the REPL

   lua main.lua --repl

Run from monkey files

   lua main.lua

Run tests

   busted tests

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Languages