Skip to content

S3v3ru5/Monkey

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Monkey

GitHub license Python 3.6

This is a Python implementation of an interpreter for the Monkey Language.Monkey language is described in the book Writing an Interpreter in Go and this interpreter is developed following that book.

Installation

Monkey can be installed using:

$ git clone https://github.com/S3v3ru5/Monkey.git
$ pip install Monkey/

installing this package will create a command monkey.

Usage

For Monkey REPL, use monkey command without any arguments

$ monkey
            __,__
   .--.  .-"     "-.  .--.
  / .. \/  .-. .-.  \/ .. \
 | |  '|  /   Y   \  |'  | |
 | \   \  \ 0 | 0 /  /   / |
  \ '- ,\.-"""""""-./, -' /
   ''-' /_   ^ ^   _\ '-''
       |  \._   _./  |
       \   \ '~' /   /
        '._ '-=-' _.'
           '-----'

Monkey v0.1 (May 13 2021, 12:50:41 PM)
[Host-> Python] on linux
>>> 
>>> let i = 0; 
>>> let res = 0;
>>> while (i < 5) { let i = i + 1; let res = res + i;}
>>> res
15
>>> res == 5*(5 + 1)/2
true
>>> 

To run a monkey-script, use monkey command with filename of the script as the only argument i.e monkey script.mon.

$ monkey ./samples/fibonacii.mon
calculate nth fibonacii number :
--------------------------------
enter n: 10
result = 55

Note: monkey-script filename must have .mon extension.

Changes

changes from canon monkey language

  • This implementation doesn't support HashMaps
  • Tracks line number and column of tokens for better error reporting
  • Supports while loops

Syntax of while loops

while (condition) {
    ...
}

License

This source code is licensed under MIT License.

About

Python Implementation of Monkey Interpreter

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages