{"id":26022974,"url":"https://github.com/agrison/monkey-kotlin","last_synced_at":"2025-10-17T02:22:45.957Z","repository":{"id":173899193,"uuid":"651415192","full_name":"agrison/monkey-kotlin","owner":"agrison","description":"Writing an interpreter in Kotlin","archived":false,"fork":false,"pushed_at":"2023-06-13T18:50:32.000Z","size":60,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-03-06T10:43:04.696Z","etag":null,"topics":["compilerbook","interpreterbook","language","lexer","monkey","monkey-language","parser"],"latest_commit_sha":null,"homepage":"","language":"Kotlin","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/agrison.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","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":"2023-06-09T07:31:04.000Z","updated_at":"2024-11-12T07:35:49.000Z","dependencies_parsed_at":null,"dependency_job_id":"72243394-58a4-4092-999b-23f58a4f78d0","html_url":"https://github.com/agrison/monkey-kotlin","commit_stats":null,"previous_names":["agrison/monkey-kotlin"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/agrison/monkey-kotlin","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/agrison%2Fmonkey-kotlin","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/agrison%2Fmonkey-kotlin/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/agrison%2Fmonkey-kotlin/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/agrison%2Fmonkey-kotlin/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/agrison","download_url":"https://codeload.github.com/agrison/monkey-kotlin/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/agrison%2Fmonkey-kotlin/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":279272263,"owners_count":26138090,"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","status":"online","status_checked_at":"2025-10-17T02:00:07.504Z","response_time":56,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["compilerbook","interpreterbook","language","lexer","monkey","monkey-language","parser"],"created_at":"2025-03-06T10:37:37.221Z","updated_at":"2025-10-17T02:22:45.952Z","avatar_url":"https://github.com/agrison.png","language":"Kotlin","funding_links":[],"categories":[],"sub_categories":[],"readme":"## Writing an interpreter in \u003cstrike\u003eGo\u003c/strike\u003e Kotlin: Monktey\n\nI recently bought the bundle of books [*Writing an interpreter in Go*](https://interpreterbook.com/) and [*Writing a compiler in Go*](https://compilerbook.com/) by *Thorsten Ball*, and it was a great read.\n\nI had much fun, rediscovering things I learnt at University but in C with lex/yacc and OCaml (ocamllex, ocamlyacc).\n\nSo I took a chance at writing along the code in Kotlin while reading the book, so that we have a Monkey interpreter in Kotlin.\n\nI have also made some adaptations to the builtins functions and supporting:\n- Doubles (`3.14`)\n- Strings with escapement characters (`\\n`, `\\t`, `\\r`, `\\\\`)\n- Additional operators\n  - String repeat (`\"a\" * 3`)\n  - Array and Hash concatenations (`[0] + [1]`, `{a: 1} + {b: 2}`)\n  - `\u003c=` and `\u003e=`\n  - `\u0026\u0026` and `||`\n  - `%`\n- Ranges (`0..4`, `[0, 1, 2, 3, 4][1..2] == [1, 2]`)\n- Negative indexing (`[0, 1, 2, 3, 4][-1] == 4`)\n- while loops: (`let x = 0; while (x \u003c 3) { puts(\"hello\"); let x = x + 1; }`)\n  - no support for `break`/`continue` yet\n\nI'd like to implement:\n- `for` loops (including `break`/`continue`)\n- infix `if` called when / or similarly unless\n- more operators (in (contains), etc)\n- macro system from the book\n- ...\n\nThe code is here in this repository.\n\n## Sample\n\n```js\nlet name = \"M\\ton\\\\k\\\"ey\\n\\tis kool\";\nputs(name);\nlet age = 1;\nlet inspirations = [\"Scheme\", \"Lisp\", \"JavaScript\", \"Clojure\"];\nlet prequel = {\n  \"prequel\": \"Writing An Interpreter in Go\"\n};\nlet newBook = {\n  \"title\": \"Writing A Compiler In Go\",\n  \"author\": \"Thorsten Ball\",\n};\nlet book = prequel + newBook;\n\nlet printBookName = fn(book) {\n  let title = book[\"title\"];\n  let author = book[\"author\"];\n  puts(author + \" - \" + title);\n};\nprintBookName(book);\n\nlet fibonacci = fn(x) {\n  if (x == 0) {\n    0\n  } else {\n    if (x == 1) {\n      return 1;\n    } else {\n      fibonacci(x - 1) + fibonacci(x - 2);\n    }\n  }\n};\n\nlet map = fn(arr, f) {\n  let iter = fn(arr, accumulated) {\n    if (len(arr) == 0) {\n      accumulated\n    } else {\n      iter(rest(arr), push(accumulated, f(first(arr))));\n    }\n  };\n\n  iter(arr, []);\n};\n\nlet numbers = [1.0, 1 + 1, 4 - 1, 2 * 2, 2 + 3] + [12 / 2, 17.0];\nlet fib = map(numbers, fibonacci);\nputs(fib);\nputs(fib[2..4]);\n```\n\n#### Output\n\n```text\nM\ton\\k\"ey\n    is kool\nThorsten Ball - Writing A Compiler In Go\n[1, 1, 2, 3, 5, 8, 1597]\n[2, 3, 5]\n```\n\n## Structure\n\n```\n+ interpreter/\n  + ast/ \n  + evaluator/\n  + lexer/\n  + object/\n  + parser/\n  + repl/\n  + token/\n  Main.kt \u003c- main program\n```\n\n## Tests\n\nTests are located in `src/test/kotlin`.\n\n```\nTests passed: 131 of 131 tests - 161ms\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fagrison%2Fmonkey-kotlin","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fagrison%2Fmonkey-kotlin","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fagrison%2Fmonkey-kotlin/lists"}