Skip to content
An idiomatic C# port of the Monkey programming language from the Writing An Interpreter In Go book.
C#
Branch: master
Clone or download
Latest commit ff5572c Jul 5, 2019
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.vscode
Monkey.Cli Clean-up Jul 5, 2019
Monkey.Core
Monkey.Tests Clean-up Jul 5, 2019
.gitignore
LICENSE Clean-up Jul 5, 2019
Monkey.sln Initial checkin. May 8, 2018
README.md Update README.md Jul 3, 2019

README.md

Monkey-CSharp

This repository contains a C# port of the Monkey programming language from the Writing an interpreter in Go book. Its code closely resembles that presented in the book, but written in idiomatic C# for the .NET Core runtime. Using the instructions below, the interpreter runs on both Windows, Mac, and Linux.

The Monkey parser is an hand-written LL(1) hybrid of a traditional recursive descent parser for statements and a Pratt, also known as Top Down Operator Precedence, parser for expressions. The hybrid parser ensures efficient parsing while supporting operator precedence and associativity. Its outputs is an abstract syntax tree which the tree walking evaluator traverses as part of executing a Monkey program.

The complete implementation of the lexer, parser, and evaluator consists of 2,200 lines of code with an additional 1,150 lines of tests. Not a lot of code for such a capable interpreter, implemented entirely without third party libraries.

Features

The Monkey language supports mathematical expressions, variable bindings, functions and the application of those functions, conditionals, return statements, and advanced concepts such as higher-order functions and closures. The data types supported are integers, booleans, strings, arrays, and hashes.

Examples

See the official homepage. Navigate to "The Monkey Programming Language" section for examples and browse through the tests in this repository.

Getting started

$ git clone https://github.com/ronnieholm/Monkey-CSharp.git
$ cd Monkey-CSharp
$ dotnet build
$ dotnet test Monkey.Tests
$ dotnet run -p Monkey.Cli

Resources

You can’t perform that action at this time.