MonkeyScript
January 19, 2026 ยท View on GitHub
A lightweight, interpreted programming language written in C#. MonkeyScript features a simple syntax with support for functions, conditionals, loops, and basic arithmetic operations Note that this language has no future expectations, as this is just a "side quest" meant to sharpen my Computer Science knowledge and problem solving skills. If there is demand development will continue, but as it stands this project is concluded
Features
- Dynamic typing with runtime type inference
- First-class functions with closures
- Lexical scoping with nested environments
- Control flow with
if/elseandwhileloops - Function literals with parameter passing
- REPL-ready architecture for interactive programming
Quick Start
Prerequisites
- .NET 6.0 or higher
- A C# IDE (Visual Studio, VS Code, or Rider recommended)
Running a Script
Create a file named script.ms:
def x = 5;
def y = 10;
def sum = x + y;
print(sum);
Run it:
dotnet run # or alternatively just use Visual Studio as I do
Language Syntax
Variables
def x = 42;
def name = myVariable;
Functions
def add = fn(a, b): a + b; end;
add(5, 3);
Conditionals
if x > 10:
def result = 1;
else:
def result = 0;
end;
Loops
def i = 0;
while i < 5:
def i = i + 1;
end;
Expressions
def result = (10 + 5) - 3;
def isTrue = true;
def isFalse = false;
Architecture
MonkeyScript follows a classic interpreter architecture:
- Lexical Analysis - The
Lexerbreaks source code into 'tokens' - Parsing - The
Parserbuilds an Abstract Syntax Tree (AST) - Evaluation - The
Evaluatorwalks the AST and executes code
Pipeline Flow
Source Code > Lexer > Tokens > Parser > AST > Evaluator > Eventual output
Examples
Factorial Function
def factorial = fn(n):
if n < 2:
1;
else:
n * factorial(n - 1);
end;
end;
factorial(5);
Counter with Closure
def makeCounter = fn():
def count = 0;
fn():
def count = count + 1;
count;
end;
end;
def counter = makeCounter();
counter();
counter();
counter();
Documentation
- Language Specification - Complete language reference
- Contributing Guide - How to contribute
- Roadmap - Future features and plans
Contributing
Contributions are welcome! Please read CONTRIBUTING.md for details on our code of conduct and the process for submitting pull requests You're allowed to fork this and go on your own way but I'd like to contribute myself if demand is present (as I have the most knowledge about my own intepreter)
License
This project is licensed under the MIT License: see the LICENSE file for details
Acknowledgments
Inspired by the "Writing An Interpreter In Go" book by Thorsten Ball, adapted to C# with custom syntax decisions
Support
For bugs and feature requests, please open an issue on GitHub