Skip to content

An idiomatic C# port of the Monkey programming language from the Writing An Interpreter In Go book.

License

Notifications You must be signed in to change notification settings

ronnieholm/Monkey-CSharp

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

51 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Monkey-CSharp

(A Python version of Monkey is also available)

A C# port of the Monkey programming language from the Writing an interpreter in Go book. It's written in idiomatic C# targeting .NET Core on Windows, Mac, and Linux.

From the book:

It supports mathematical expressions, variable bindings, functions and the application of those functions, conditionals, return statements and even advanced concepts like higher-order functions and closures. And then there are the different data types: integers, booleans, strings, arrays and hashes.

The Monkey parser consists of a hand-written LL(1) traditional recursive descent parser for statements combined with a Pratt parser for expressions. The hybrid parser ensures efficient parsing while elegantly supporting operator precedence. Its outputs is an abstract syntax tree walked by the evaluator as part of program execution.

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

Examples

See "The Monkey Programming Language" section on the official homepage and have a look at the unit tests and Examples folder 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 # Interactive REPL
$ dotnet run -p Monkey.Cli -- Examples/Fibonacci.monkey

Resources

About

An idiomatic C# port of the Monkey programming language from the Writing An Interpreter In Go book.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages