{"id":23455430,"url":"https://github.com/aden-q/monkey","last_synced_at":"2025-04-11T03:48:08.401Z","repository":{"id":238937924,"uuid":"791070979","full_name":"Aden-Q/monkey","owner":"Aden-Q","description":"An interpreted language written in Go","archived":false,"fork":false,"pushed_at":"2025-04-01T12:49:16.000Z","size":102,"stargazers_count":0,"open_issues_count":1,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-04-11T03:48:03.652Z","etag":null,"topics":["go","golang","interpreter","programming-language"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Aden-Q.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","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":"2024-04-24T03:28:09.000Z","updated_at":"2025-02-27T16:22:10.000Z","dependencies_parsed_at":"2024-05-16T06:12:13.284Z","dependency_job_id":"878fb7a8-7091-40ec-a61d-fd0c38c1c5a9","html_url":"https://github.com/Aden-Q/monkey","commit_stats":null,"previous_names":["aden-q/monkey"],"tags_count":24,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Aden-Q%2Fmonkey","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Aden-Q%2Fmonkey/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Aden-Q%2Fmonkey/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Aden-Q%2Fmonkey/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Aden-Q","download_url":"https://codeload.github.com/Aden-Q/monkey/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248339267,"owners_count":21087214,"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":["go","golang","interpreter","programming-language"],"created_at":"2024-12-24T03:31:19.684Z","updated_at":"2025-04-11T03:48:08.386Z","avatar_url":"https://github.com/Aden-Q.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Monkey\n\nMonkey is an interpreted language written in Go. *This project is actively under development.*\n\n## Requirements\n\n+ Built with Go 1.22 (though you don't need go installation if you have docker)\n+ [direnv](https://direnv.net/)\n+ [just](https://just.systems/)\n+ [ginkgo](https://onsi.github.io/ginkgo/) (if you want to run local unit tests)\n+ [golangci-lint](https://golangci-lint.run/) (if you want to do local lint)\n+ [docker](https://www.docker.com/) (if you want to run it in the docker way)\n\n## Usages\n\n### Local build and run\n\nOpen your shell, then REPL is ready for you:\n\n```bash\n➜  ~ just run\n            __,__\n   .--.  .-\"     \"-.  .--.\n  / .. \\/  .-. .-.  \\/ .. \\\n | |  '|  /   Y   \\  |'  | |\n | \\   \\  \\ 0 | 0 /  /   / |\n  \\ '- ,\\.-\"\"\"\"\"\"\"-./, -' /\n   ''-' /_   ^ ^   _\\ '-''\n       |  \\._   _./  |\n       \\   \\ '~' /   /\n        '._ '-=-' _.'\n           '-----'\nHello xxx! This is the Monkey programming language!\n\u003e\u003e\u003e \n```\n\n### Docker\n\n```bash\n➜  ~ docker pull ghcr.io/aden-q/monkey\n➜  ~ docker run -it --rm --name monkey ghcr.io/aden-q/monkey\n            __,__\n   .--.  .-\"     \"-.  .--.\n  / .. \\/  .-. .-.  \\/ .. \\\n | |  '|  /   Y   \\  |'  | |\n | \\   \\  \\ 0 | 0 /  /   / |\n  \\ '- ,\\.-\"\"\"\"\"\"\"-./, -' /\n   ''-' /_   ^ ^   _\\ '-''\n       |  \\._   _./  |\n       \\   \\ '~' /   /\n        '._ '-=-' _.'\n           '-----'\nHello xxx! This is the Monkey programming language!\n\u003e\u003e\u003e \n```\n\n### Binary installation\n\nAssuming you have `$GOPATH` appended to your `$PATH` env var:\n\n```bash\n➜  ~ go install github.com/aden-q/monkey@latest\n➜  ~ monkey\n            __,__\n   .--.  .-\"     \"-.  .--.\n  / .. \\/  .-. .-.  \\/ .. \\\n | |  '|  /   Y   \\  |'  | |\n | \\   \\  \\ 0 | 0 /  /   / |\n  \\ '- ,\\.-\"\"\"\"\"\"\"-./, -' /\n   ''-' /_   ^ ^   _\\ '-''\n       |  \\._   _./  |\n       \\   \\ '~' /   /\n        '._ '-=-' _.'\n           '-----'\nHello xxx! This is the Monkey programming language!\n```\n\n## Demo\n\nFor more examples and language details. Please check the blog post [here](https://aden-q.github.io/monkey-an-interpreted-language-written-in-go/).\n\n### Built-in functions\n\n```bash\n\u003e\u003e\u003e print(\"Hello, world!\");\nHello, world!\n\u003e\u003e\u003e len(\"Hello, world!\");\n13\n```\n\n### Functions\n\nAnonymous function and function binding:\n\n```bash\n\u003e\u003e\u003e fn(x, y) { return x * y; } (5, 6);\n30\n\u003e\u003e\u003e let add = fn(x, y) { return x + y; };\n\u003e\u003e\u003e add(2, 8);\n10\n```\n\n### Control structures\n\n#### If\n\n```bash\n\u003e\u003e\u003e if (10 \u003e 5) { 5; } else { 10; };\n5\n```\n\n### Arrays\n\n```bash\n\u003e\u003e\u003e let arr = [1, 2, 3, 4, 5];\n\u003e\u003e\u003e arr[0];\n1\n```\n\n### Hashes\n\n```bash\n\u003e\u003e\u003e let person = {\"name\": \"alice\", \"age\": 21};  \n\u003e\u003e\u003e person[\"name\"];\nalice\n```\n\n## Conventions and Features\n\n+ Programs can run in REPL or as scripts\n+ Primitive data types: `int`, `boolean`, `string`\n+ Identifiers consist of alphabet letters or underscore\n+ Statements are explicitly end by seminlon `;`\n+ Comments start with double slash `//`\n+ Conditional statements (`if` and `switch` keywords)\n+ Loops (`for`, `range`, and `while` keywords)\n+ First-class functions and closures\n+ Prefix operators (binary expressions)\n+ Infix operators (unary expressions)\n+ Postfix operators\n+ A Pratt Parser implementation\n+ A Tree-walking interpreter\n+ Use Go's GC to prevent memory leak\n\n## Components\n\n+ Token set\n+ Lexer\n+ Abstract Syntax Tree (AST)\n+ Pratt parser based on context-free grammars and the Backus-Naur-Form\n+ Tree-walking interpreter/evaluator\n+ Object system\n\n## TODOs\n\n+ [ ] docs: doc everything related to usage and implementation details\n+ [ ] feat: Unicode\n+ [ ] feat: parsing line, column number for better visibility\n+ [ ] feat: hexical notation and octal notation for integers\n+ [ ] feat: formatting and prettier in REPL\n+ [ ] feat: support for multiple types: boolean, float, struct, string, byte, etc\n+ [ ] feat: support for collection types: array, map, set\n+ [ ] feat: add support for variadic functions\n+ [ ] feat: add support for anonymous functions\n+ [x] feat: add \u003c=, \u003e= operators\n+ [ ] feat: add logical operators ||， \u0026\u0026\n+ [ ] feat: add bitwise operators ^, |, \u0026\n+ [ ] refactor: unary operators, binary operators, ternary operators\n+ [ ] feat: use Cobra to enable multiple modes when launching the REPL\n+ [ ] feat: support for concurrency primitives such as Mutex, RWMutex, atomic\n+ [ ] feat: support for comments\n+ [ ] docs: a diagram for the full REPL loop including the AST used\n+ [ ] check whether we need the token field in AST\n+ [ ] test: increase test coverage to at least 80%\n+ [ ] feat: return can only be used in functions, do not allow plain return in REPL\n+ [ ] feat: if expression with multiple branches\n+ [ ] feat: check peek token type in parseExpression\n+ [ ] feat: check the difference between if expression and if statement\n+ [ ] feat: empty statement with only a single ;\n+ [ ] feat: scroll in command history with up and down keys\n+ [ ] feat: PrettyPrint, color, AST, etc\n+ [ ] feat: sys call such as print(...)\n+ [ ] feat: add a helper for available functions\n+ [ ] feat: switch between multiple value representation system using some flag\n+ [ ] feat: class (object system)\n+ [ ] feat: configuration with yaml or envrc\n+ [ ] feat: edge cases for those operators\n+ [ ] feat: integer division operator and float division operator\n+ [ ] feat: reference integer literal as constant, simulate some static memory space for literals of integer, strings, etc.\n+ [ ] feat: integer overflow problem\n+ [ ] feat: command history and navigate in REPL using left, right, up, bottom\n+ [ ] feat: configuration as env vars, default + direnv\n+ [ ] feat: semantics for left and right arrows in REPL\n+ [ ] feat: semantics for up and down arrows in REPL\n+ [ ] feat: lexing, parsing, evaluation of nil expression statement\n+ [ ] fix: slow startup issue\n+ [ ] fix: do not allow plain return in REPL outside of a function, report an error instead\n+ [ ] docs: add a section for all control structures\n+ [ ] feat: semantics of scope\n+ [ ] feat: pointer/reference semantics\n+ [ ] feat: func multiple return values\n+ [ ] refactor: evalExpressions (int, error)\n+ [ ] feat: parallel assignment\n+ [ ] feat: escaping characters and error when \" mismatches\n+ [ ] perf: add immutable constants to the envvironment to reduce memory allocation\n+ [ ] feat: add a print builtin function\n+ [ ] feat: add quit(), exit() builtin functions to exit elegantly\n+ [ ] feat: add a static/dynamic type system\n+ [x] ci: build and publish as a pkg on Docker Hub\n+ [ ] feat: dot as an operator (similar to infix index expression)\n+ [ ] feat: mutable array implementation for efficient push/pop\n+ [ ] feat: map-reduce as an example\n+ [ ] feat: iterator, range operator\n+ [ ] feat: bytecode, VM, and JIT compilation\n+ [ ] feat: make array mutable, array should support re-assignment, extending, pop, etc.\n\n## References\n\n+ *Writing An Interpreter In Go* by Thorsten Ball\n+ *Top Down Operator Precedence* by Vaughan Pratt\n+ *The Structure and Interpretation of Computer Programs (SICP)* by Harold Abelson\n\n## License\n\n[MIT License](./LICENSE)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faden-q%2Fmonkey","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Faden-q%2Fmonkey","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faden-q%2Fmonkey/lists"}