{"id":50785366,"url":"https://github.com/zlliang/tslox","last_synced_at":"2026-06-12T07:06:12.009Z","repository":{"id":45413180,"uuid":"343670106","full_name":"zlliang/tslox","owner":"zlliang","description":"An interpreter of the Lox scripting language, implemented in TypeScript","archived":false,"fork":false,"pushed_at":"2021-12-24T13:44:33.000Z","size":190,"stargazers_count":13,"open_issues_count":0,"forks_count":2,"subscribers_count":1,"default_branch":"main","last_synced_at":"2023-11-19T14:45:32.017Z","etag":null,"topics":["interpreter","programming-language","typescript"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","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/zlliang.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}},"created_at":"2021-03-02T06:32:46.000Z","updated_at":"2023-09-04T03:01:18.000Z","dependencies_parsed_at":"2022-08-20T01:53:05.834Z","dependency_job_id":null,"html_url":"https://github.com/zlliang/tslox","commit_stats":null,"previous_names":[],"tags_count":0,"template":null,"template_full_name":null,"purl":"pkg:github/zlliang/tslox","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zlliang%2Ftslox","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zlliang%2Ftslox/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zlliang%2Ftslox/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zlliang%2Ftslox/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/zlliang","download_url":"https://codeload.github.com/zlliang/tslox/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zlliang%2Ftslox/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":34232905,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-06-12T02:00:06.859Z","response_time":109,"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":["interpreter","programming-language","typescript"],"created_at":"2026-06-12T07:06:11.005Z","updated_at":"2026-06-12T07:06:12.001Z","avatar_url":"https://github.com/zlliang.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# TSLox\n\nAn interpreter of the [Lox](https://github.com/munificent/craftinginterpreters) scripting language, implemented in TypeScript.\n\nLox is a tiny scripting language described in [Bob Nystrom](https://stuffwithstuff.com/)'s book [Crafting Interpreters](https://craftinginterpreters.com/). Following [Part II](https://craftinginterpreters.com/a-tree-walk-interpreter.html) of the book, I complete a tree-walk interpreter of Lox using [TypeScript](https://www.typescriptlang.org/), as a writing-an-interpreter-from-scratch exercise.\n\nGoing on reading [Part III](https://craftinginterpreters.com/a-bytecode-virtual-machine.html) of the book,\nI also implement the second version of Lox interpreter using C, It is a bytecode virtual machine. See [zlliang/clox](https://github.com/zlliang/clox).\n\n## Usage\n\nClone this repository, and run the CLI as:\n\n```bash\n$ pnpm tslox # Or `yarn tslox` / `npm run tslox`\n```\n\nFor detailed usages, see the help message:\n\n```\ntslox v0.0.0-20211215\nUsage:\n\n  tslox [--verbose]            Run tslox REPL (Add '--verbose' to show AST)\n  tslox \u003cscript\u003e [--verbose]   Run a specified script file (Add '--verbose' to show AST)\n  tslox -v, --version          Show version info\n  tslox -h, --help             Show this help message\n```\n\nAlso, feel free to run examples in the `examples` directory:\n\n```\n$ pnpm tslox examples/hello-world.lox\nHello, world!\n```\n\n## Features\n\n1. **REPL that allows Lox expressions.** This is a challenge in [Chapter 8](https://craftinginterpreters.com/statements-and-state.html#challenges) of the book. In REPL mode, one can input zero or more statements (ending with '`;`') and maybe an expression. The interpreter executes all the statements. If there is an expression, the REPL evaluates and prints its value.\n\n   ```\n   [tslox]\u003e var a = 3; a + 3\n   6\n\n   [tslox]\u003e print a / 8;\n   0.375\n\n   [tslox]\u003e a + 25\n   28\n   ```\n\n2. **Verbose mode that prints both ASTs and outputs.** In [Chapter 5](https://craftinginterpreters.com/representing-code.html#the-visitor-pattern) of the book, a utility class [`AstPrinter`](\u003chttps://craftinginterpreters.com/representing-code.html#a-(not-very)-pretty-printer\u003e) is created to print parsed Lox ASTs as [S-expressions](https://en.wikipedia.org/wiki/S-expression). TSLox basically adds all of the visit methods, and shows ASTs alongside script outputs, when the `--verbose` flag is enabled.\n\n   ```\n   $ pnpm tslox -- --verbose\n\n   [tslox]\u003e fun greet() { return \"Hello, world!\"; }  print greet();\n   [AST]\n   (fun greet\n     (block\n       (return \"Hello, world!\")))\n   (print (call greet))\n\n   [Output]\n   Hello, world!\n   ```\n\n## Disclaimer\n\nCode structures and some implementation details of TSLox are different from the original [jlox](https://github.com/munificent/craftinginterpreters/tree/master/java/com/craftinginterpreters) version. Since I read the book just for learning and exercising, I didn't write any test for TSLox. Bugs may occur. If you find one, please feel free to open an issue! :)\n\n## Resources\n\n- Book: [Crafting Interpreters](https://craftinginterpreters.com/)\n- Blog post: [Crafting \"Crafting Interpreters\"](http://journal.stuffwithstuff.com/2020/04/05/crafting-crafting-interpreters/)\n- Wiki: [Lox implementations](https://github.com/munificent/craftinginterpreters/wiki/Lox-implementations)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzlliang%2Ftslox","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fzlliang%2Ftslox","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzlliang%2Ftslox/lists"}