{"id":25089847,"url":"https://github.com/atharvathorve/monke","last_synced_at":"2025-04-01T17:25:15.028Z","repository":{"id":280373353,"uuid":"936350335","full_name":"AtharvaThorve/monkE","owner":"AtharvaThorve","description":"Implementation of an interpreter for the monkE programming language in Go","archived":false,"fork":false,"pushed_at":"2025-04-01T05:38:56.000Z","size":105,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-04-01T06:28:45.580Z","etag":null,"topics":["abstract-syntax-tree","evaluator","go","interpreter","lexer","object-system","parser"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/AtharvaThorve.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2025-02-20T23:49:31.000Z","updated_at":"2025-04-01T05:38:59.000Z","dependencies_parsed_at":"2025-03-25T06:34:39.143Z","dependency_job_id":null,"html_url":"https://github.com/AtharvaThorve/monkE","commit_stats":null,"previous_names":["atharvathorve/monke"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AtharvaThorve%2FmonkE","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AtharvaThorve%2FmonkE/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AtharvaThorve%2FmonkE/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AtharvaThorve%2FmonkE/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/AtharvaThorve","download_url":"https://codeload.github.com/AtharvaThorve/monkE/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246679129,"owners_count":20816411,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["abstract-syntax-tree","evaluator","go","interpreter","lexer","object-system","parser"],"created_at":"2025-02-07T11:20:08.923Z","updated_at":"2025-04-01T17:25:15.022Z","avatar_url":"https://github.com/AtharvaThorve.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# monkE Interpreter \u0026 Compiler\n\nThis project is an implementation of an interpreter and compiler for the `monkE` programming language, inspired by the books **\"Writing an Interpreter in Go\"** and **\"Writing a Compiler in Go\"** by Thorsten Ball.\n```monkE\n\u003e\u003e print(\"Hello World from monkE!!\");\nHello World!!\nnull\n```\n\n## Overview\n\n`monkE` is a simple, dynamically-typed programming language. The interpreter is written in Go, and work is underway to convert it into a bytecode compiler and virtual machine.\n\nThe aim of the project was to learn core concepts of interpreters and compilers such as:\n- lexer\n- parser\n- abstract syntax tree\n- object system\n- evaluator\n- builtin functions\n- bytecode compilation\n- virtual machine execution\n\n**Note:** The compiler implementation is in progress and currently supports a subset of the interpreter's features.\n\n## Table of Contents\n\n- [Overview](#overview)\n- [Features](#features)\n- [Project Structure](#project-structure)\n- [Getting Started](#getting-started)\n  - [Prerequisites](#prerequisites)\n  - [Installation](#installation)\n- [Usage](#usage)\n  - [Print](#print)\n  - [Basic Arithmetic](#basic-arithmetic)\n  - [Conditional Statements](#conditional-statements)\n  - [Variable Declarations](#variable-declarations)\n  - [Functions](#functions)\n  - [String Manipulation](#string-manipulation)\n  - [Built-in Functions](#built-in-functions)\n  - [Array Literals](#array-literals)\n  - [Array Builtins](#array-builtins)\n  - [Hash Literals](#hash-literals)\n- [Compiler Implementation](#compiler-implementation)\n  - [Current Status](#current-status)\n  - [Bytecode Format](#bytecode-format)\n  - [Virtual Machine](#virtual-machine)\n- [License](#license)\n- [Acknowledgements](#acknowledgements)\n\n## Features\n\n### Interpreter Features\n- **Lexer**: Tokenizes the input source code.\n- **Parser**: Parses the tokens into an Abstract Syntax Tree (AST).\n- **REPL**: A Read-Eval-Print Loop for interactive programming.\n- **Evaluator**: Tree-walking evaluator for the AST.\n\n### Compiler Features (In Progress)\n- **Bytecode Generation**: Converts AST into bytecode instructions.\n- **Virtual Machine**: Executes the generated bytecode.\n- **Code Optimization**: Optimizes the generated bytecode (partial implementation).\n\n## Project Structure\n\n- `ast/`: Contains the Abstract Syntax Tree (AST) definitions.\n- `lexer/`: Contains the lexer implementation.\n- `parser/`: Contains the parser implementation.\n- `repl/`: Contains the REPL implementation.\n- `token/`: Contains token definitions.\n- `compiler/`: Contains the compiler implementation.\n- `vm/`: Contains the virtual machine implementation.\n- `main.go`: Entry point of the interpreter and compiler.\n\n## Getting Started\n\n### Prerequisites\n\n- Go 1.23.5 or higher\n\n### Installation\n\n1. Clone the repository:\n    ```sh\n    git clone https://github.com/yourusername/monkE.git\n    cd monkE\n    ```\n\n2. Build the project:\n    ```sh\n    go build\n    ```\n\n3. Run the REPL:\n    ```sh\n    ./monkE\n    ```\n\n## Usage\n\nOnce the REPL is running, you can start typing `monkE` code and see the results immediately.\n\n### Print\n```monkE\n\u003e\u003e print(\"Hello World!!\");\nHello World!!\nnull\n```\n\n### Basic Arithmetic\n\n```monkE\n\u003e\u003e 5 * 5 + 10\n35\n\u003e\u003e 3 + 4 * 5 == 3 * 1 + 4 * 5\ntrue\n\u003e\u003e 5 * 10 \u003e 40 + 9\ntrue\n\u003e\u003e (10 + 2) * 30 == 300 + 20 * 3\ntrue\n\u003e\u003e (5 \u003e 5 == true) != false                                                                                                                                                                  \nfalse\n\u003e\u003e 500 / 2 != 250\nfalse\n```\n\n### Conditional Statements\n\n```monkE\n\u003e\u003e if (5 * 5 + 10 \u003e 34) { 99 } else { 100 }\n99\n\u003e\u003e if ((1000 / 2) + 250 * 2 == 1000) { 9999 }\n9999\n```\n\n### Variable Declarations\n\n```monkE\n\u003e\u003e let a = 5;\n\u003e\u003e let b = a \u003e 3;\n\u003e\u003e let c = a * 99;\n\u003e\u003e if (b) { 10 } else { 1 };\n10\n\u003e\u003e let d = if (c \u003e a) { 99 } else { 100 };\n\u003e\u003e d\n99\n\u003e\u003e d * c * a;\n245025\n```\n\n### Functions\n\n```monkE\n\u003e\u003e let addTwo = fn(x) { x + 2; };\n\u003e\u003e addTwo(2)\n4\n\u003e\u003e let multiply = fn(x, y) { x * y; };\n\u003e\u003e multiply(50 / 2, 1 * 2);\n50\n\u003e\u003e fn(x) { x == 10 }(5)\nfalse\n\u003e\u003e fn(x) { x == 10 }(10) \ntrue\n\u003e\u003e let newAdder = fn(x) { fn(y) { x + y } };\n\u003e\u003e let addTwo = newAdder(2);\n\u003e\u003e addTwo(3);\n5\n\u003e\u003e let addThree = newAdder(3);\n\u003e\u003e addThree(10);\n13\n```\n\n### String Manipulation\n\n```monkE\n\u003e\u003e let makeGreeter = fn(greeting) { fn(name) { greeting + \" \" + name + \"!\" } };\n\u003e\u003e let hello = makeGreeter(\"Hello\");\n\u003e\u003e hello(\"Atharva\");\nHello Atharva!\n\u003e\u003e let heythere = makeGreeter(\"Hey there\");\n\u003e\u003e heythere(\"Atharva\");\nHey there Atharva!\n```\n\n### Built-in Functions\n\n```monkE\n\u003e\u003e len(\"1234\")\n4\n\u003e\u003e len(\"Hello World!\")\n12\n\u003e\u003e len(\"Woooooohooo!\", \"len works!!\")\nERROR: wrong number of arguments. got=2, want=1\n\u003e\u003e len(12345)\n```\n\n### Array Literals\n```monkE\n\u003e\u003e [1,2,3,4]\n[1, 2, 3, 4]\n\u003e\u003e let double = fn(x) { x * 2 };\n\u003e\u003e [1, double(2), 3 * 3, 4 - 3]\n[1, 4, 9, 1]\n\u003e\u003e let a = [1, 2 * 2, 10 - 5, 8 / 2];\n\u003e\u003e a[0] \n1\n\u003e\u003e a[1]\n4\n\u003e\u003e a[5-3]\n5\n\u003e\u003e a[99]\nnull\n```\n\n### Array Builtins\n```monkE\n\u003e\u003e let a = [1, 2, 3, 4]\n\u003e\u003e first(a)\n1\n\u003e\u003e last(a)\n4\n\u003e\u003e rest(a)\n[2, 3, 4]\n\u003e\u003e rest(rest(a))\n[3, 4]\n\u003e\u003e rest(rest(rest(a)))\n[4]\n\u003e\u003e rest(rest(rest(rest(a))))\n[]\n\u003e\u003e rest(rest(rest(rest(rest(a)))))\nnull\n```\n\n### Hash Literals\n```monkE\n\u003e\u003e {\"name\": \"Monkey\", \"age\": 0, \"type\": \"Language\", \"status\": \"awesome\"}\n{name: Monkey, age: 0, type: Language, status: awesome}\n\u003e\u003e let people = [{\"name\": \"Alice\", \"age\": 24}, {\"name\": \"Anna\", \"age\": 28}];\n\u003e\u003e people[0][\"name\"];\nAlice\n\u003e\u003e people[1][\"age\"]\n28\n\u003e\u003e people[1][\"age\"] + people[0][\"age\"]\n52\n\u003e\u003e let getName = fn(person) { person[\"name\"]; };\n\u003e\u003e getName(people[0]);\nAlice\n\u003e\u003e getName(people[1]);\nAnna\n```\n\n## Compiler Implementation\n\n### Current Status\n\nThe compiler implementation has made significant progress. Currently supported features include:\n\n- Arithmetic operations (addition, subtraction, multiplication, division)\n- Conditional statements (if/else expressions)\n- Variable declarations and variable access\n- String operations and concatenation\n- Array literals and index expressions\n- Hash map literals and access\n\nFeatures still being worked on include:\n- Function closures with proper environment handling\n- Built-in functions within the VM context\n- Advanced optimizations\n\n### Bytecode Format\n\nThe compiler generates bytecode instructions that are executed by the virtual machine. The bytecode format is designed to be compact and efficient.\n\n### Virtual Machine\n\nThe virtual machine executes the bytecode generated by the compiler. It includes a stack-based execution model and supports basic operations such as arithmetic, variable access, and function calls.\n\n## License\n\nThis project is licensed under the MIT License.\n\n## Acknowledgements\n\n- Thorsten Ball for his excellent books **\"Writing an Interpreter in Go\"** and **\"Writing a Compiler in Go\"**.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fatharvathorve%2Fmonke","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fatharvathorve%2Fmonke","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fatharvathorve%2Fmonke/lists"}