Skip to content

ktanaka101/monkey.dart

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

monkey.dart

Summury

We can learn how to make an interpreter in this book.
====> β˜†β˜†β˜† "Writing An Interpreter in Go" β˜†β˜†β˜†
That interpreter is called Monkey in the book.
The Monkey is written in Go in the book.
But in this repository it is written in Dart.

Supports

  • Lexer
  • Parser
  • Evaluator
  • Compiler
  • VM
  • REPL
  • Test case
  • Evaluator and VM benchmarks

Example

REPL

$ dart run
>> let a = 5
>> a + 10
15
>> let new_closure = fn(a) { fn() { a; }; };
>> let closure = new_closure(99);
>> closure();
99

Fibonacchi

let fibonacci = fn(x) {
  if (x == 0) {
    return 0;
  } else {
    if (x == 1) {
      return 1;
    } else {
      fibonacci(x - 1) + fibonacci(x - 2);
    } 
  }
};
fibonacci(15); #=> 610
$ dart run
>> let fibonacci = fn(x) { if (x == 0) { return 0; } else { if (x == 1) { return 1; } else { fibonacci(x - 1) + fibonacci(x - 2); } } };
>> fibonacci(15)
610

Contributors

License

MIT