{"id":45399261,"url":"https://github.com/bit-web24/lox","last_synced_at":"2026-02-21T19:47:14.726Z","repository":{"id":255530884,"uuid":"850604948","full_name":"bit-web24/lox","owner":"bit-web24","description":"A Tree-Walk Interpreter","archived":false,"fork":false,"pushed_at":"2025-07-07T07:58:10.000Z","size":210,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-07-07T08:45:54.702Z","etag":null,"topics":["hacktoberfest","interpreter","tree-walk-interpreter"],"latest_commit_sha":null,"homepage":"","language":"Rust","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/bit-web24.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,"zenodo":null}},"created_at":"2024-09-01T09:04:03.000Z","updated_at":"2025-02-13T14:40:17.000Z","dependencies_parsed_at":"2024-10-22T23:57:02.787Z","dependency_job_id":"b66c6e45-c1cf-4be2-a76c-465fe02ee2af","html_url":"https://github.com/bit-web24/lox","commit_stats":null,"previous_names":["bit-web24/lox"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/bit-web24/lox","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bit-web24%2Flox","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bit-web24%2Flox/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bit-web24%2Flox/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bit-web24%2Flox/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/bit-web24","download_url":"https://codeload.github.com/bit-web24/lox/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bit-web24%2Flox/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29691081,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-21T18:18:25.093Z","status":"ssl_error","status_checked_at":"2026-02-21T18:18:22.435Z","response_time":107,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"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":["hacktoberfest","interpreter","tree-walk-interpreter"],"created_at":"2026-02-21T19:47:14.652Z","updated_at":"2026-02-21T19:47:14.720Z","avatar_url":"https://github.com/bit-web24.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Lox Interpreter in Rust\n\nA high-performance, tree-walk interpreter for the Lox programming language, written in Rust.\n\nThis implementation follows the design patterns described in Bob Nystrom's [Crafting Interpreters](https://craftinginterpreters.com/). It features a full lexical scanner, recursive descent parser, and an AST-walking interpreter.\n\n## Features\n\n- **Dynamic Typing**: Variables can hold any type of value.\n- **Garbage Collection**: Uses Rust's ownership model and `Rc` for memory management (no manual GC implementation required).\n- **Functions**: First-class functions with closures.\n- **Control Flow**: `if`, `while`, and `for` loops.\n- **Expressions**: Basic arithmetic, comparison, and logical operators.\n- **Classes**: *Currently parsed but runtime execution is partially implemented (Work In Progress).*\n\n## Architecture\n\nThe interpreter processes Lox code in several stages:\n\n1.  **Scanner (`src/scanner.rs`)**: Reads raw source code and tokenizes it into a stream of meaningful symbols (tokens).\n2.  **Parser (`src/parser.rs`)**: Consumes tokens using a recursive descent algorithm to build an Abstract Syntax Tree (AST). The grammar is defined in `grammar.bnf`.\n3.  **Resolver (`src/resolver.rs`)**: Performs a semantic analysis pass to resolve variable binding scopes and verify correct usage before runtime.\n4.  **Interpreter (`src/interpreter.rs`)**: Walks the AST to execute statements and evaluate expressions.\n    -   It maintains environments for variable scope (`src/env.rs`).\n    -   It handles native functions and user-defined functions (`src/function.rs`, `src/callable.rs`).\n\n## Prerequisites\n\n- [Rust](https://www.rust-lang.org/tools/install) (latest stable version recommended)\n\n## Build \u0026 Run\n\n### Clone the Repository\n```bash\ngit clone https://github.com/your-username/lox-rust.git\ncd lox-rust\n```\n\n### Build\n```bash\ncargo build --release\n```\n\n### Usage\n\n**Run the REPL (Interactive Mode):**\nTo start an interactive session, run `lox` without arguments:\n```bash\ncargo run\n\u003e print \"Hello, Lox!\";\nHello, Lox!\n```\n\n**Run a Script:**\nTo execute a Lox source file (`.lox`), pass the file path as an argument:\n```bash\ncargo run -- path/to/script.lox\n```\n\n## Syntax \u0026 Language Guide\n\n### Variables \u0026 Types\nLox is dynamically typed with `nil`, `Boolean`, `Number`, `String`.\n\n```lox\nvar a = 1;\nvar b = \"hello\";\nvar c = true;\nvar d = nil;\n\nprint a + 2; // 3\n```\n\n### Control Flow\n\n**If Statements:**\n```lox\nif (condition) {\n  print \"yes\";\n} else {\n  print \"no\";\n}\n```\n\n**While Loops:**\n```lox\nvar i = 0;\nwhile (i \u003c 5) {\n  print i;\n  i = i + 1;\n}\n```\n\n**For Loops:**\n```lox\nfor (var i = 0; i \u003c 5; i = i + 1) {\n  print i;\n}\n```\n\n### Functions\nFunctions are declared with `fun`. They support closures.\n\n```lox\nfun add(a, b) {\n  return a + b;\n}\n\nprint add(1, 2); // 3\n\nfun makeCounter() {\n  var i = 0;\n  fun count() {\n    i = i + 1;\n    print i;\n  }\n  return count;\n}\n\nvar counter = makeCounter();\ncounter(); // 1\ncounter(); // 2\n```\n\n### Classes (WIP)\nClass syntax is supported by the parser, but full object-oriented features (inheritance, `this`, `super`) are currently under developement.\n\n```lox\nclass Breakfast {\n  cook() {\n    print \"Eggs a-fryin'!\";\n  }\n\n  serve(who) {\n    print \"Enjoy your breakfast, \" + who + \".\";\n  }\n}\n```\n\n## Grammar Reference\n\nThe full grammar definition can be found in `grammar.bnf`.\n\n```bnf\nprogram    -\u003e declaration* EOF;\ndeclaration -\u003e varDecl | statement | funDecl ;\nstatement  -\u003e exprStmt | printStmt | block | ifStmt | whileStmt | forStmt | returnStmt ;\n...\n```\n\n## License\n\nThis project is open-source and available under the generic MIT License.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbit-web24%2Flox","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbit-web24%2Flox","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbit-web24%2Flox/lists"}