{"id":19457936,"url":"https://github.com/sharparam/klox","last_synced_at":"2026-01-05T01:33:11.392Z","repository":{"id":42490099,"uuid":"101596196","full_name":"Sharparam/klox","owner":"Sharparam","description":"Kotlin implementation of the Lox language","archived":false,"fork":false,"pushed_at":"2022-04-03T01:47:37.000Z","size":170,"stargazers_count":4,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-01-27T22:21:42.994Z","etag":null,"topics":["gradle","interpreter","kotlin","lox","parser","parsing"],"latest_commit_sha":null,"homepage":null,"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/Sharparam.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":"2017-08-28T02:28:51.000Z","updated_at":"2023-08-19T22:04:36.000Z","dependencies_parsed_at":"2022-08-30T18:21:46.810Z","dependency_job_id":null,"html_url":"https://github.com/Sharparam/klox","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Sharparam%2Fklox","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Sharparam%2Fklox/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Sharparam%2Fklox/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Sharparam%2Fklox/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Sharparam","download_url":"https://codeload.github.com/Sharparam/klox/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244999230,"owners_count":20544866,"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":["gradle","interpreter","kotlin","lox","parser","parsing"],"created_at":"2024-11-10T17:24:42.177Z","updated_at":"2026-01-05T01:33:11.346Z","avatar_url":"https://github.com/Sharparam.png","language":"Kotlin","funding_links":[],"categories":[],"sub_categories":[],"readme":"# klox\nA Kotlin implementation of the Lox language (mimics the Java implementation from [\"Crafting Interpreters\"][book]).\n\nThe implementation follows [the book][book] by [munificent][].\n\nTo launch the interpreter or run a file, use `./klox [file]` after building the `jar` target with Gradle.\n\n## Grammar\n\nThis is the grammar implemented in klox.\n\nIt's mostly the grammar as explained in the book, with some of the \"challenges\" implemented as well.\n\nBoth line (`//`) and multi-line (`/* */`) comments are supported (but not nested multi-line comments, at the moment).\n\n```\nprogram        -\u003e declaration* EOF ;\n\ndeclaration    -\u003e classDecl | funDecl | varDecl | statement ;\n\nclassDecl      -\u003e \"class\" IDENTIFIER ( \"\u003c\" IDENTIFIER )? \"{\" function* \"}\" ;\nfunDecl        -\u003e \"fun\" function ;\nfunction       -\u003e IDENTIFIER \"(\" parameters? \")\" block ;\nparameters     -\u003e IDENTIFIER ( \",\" IDENTIFIER )* ;\n\nvarDecl        -\u003e \"var\" IDENTIFIER (\"=\" expression)? \";\" ;\n\nstatement      -\u003e exprStmt | forStmt | ifStmt | returnStmt\n                | whileStmt | block | break | continue ;\nexprStmt       -\u003e expression \";\" ;\nforStmt        -\u003e \"for\" \"(\" ( varDecl | exprStmt | \";\" ) expression? \";\" expression? \")\" statement ;\nifStmt         -\u003e \"if\" \"(\" expression \")\" statement ( \"else\" statement )? ;\nreturnStmt     -\u003e \"return\" expression? \";\" ;\nwhileStmt      -\u003e \"while\" \"(\" expression \")\" statement ;\nblock          -\u003e \"{\" declaration* \"}\" ;\nbreak          -\u003e \"break\" \";\" ;\n\nexpression     -\u003e comma ;\ncomma          -\u003e assignment ( \",\" assignment )* ;\narguments      -\u003e assignment ( \",\" assignment )* ;\nassignment     -\u003e ( call \".\" )? IDENTIFIER ( \"-\" | \"+\" )? \"=\" assignment | conditional ;\nconditional    -\u003e logic_or ( \"?\" expression \":\" conditional )? ;\nlogic_or       -\u003e logic_and ( \"or\" logic_and )* ;\nlogic_and      -\u003e equality ( \"and\" equality )* ;\nequality       -\u003e comparison ( ( \"!=\" | \"==\" ) comparison )* ;\ncomparison     -\u003e addition ( ( \"\u003e\" | \"\u003e=\" | \"\u003c\" | \"\u003c=\" ) addition )* ;\naddition       -\u003e multiplication ( ( \"-\" | \"+\" ) multiplication )* ;\nmultiplication -\u003e unary ( ( \"/\" | \"*\" ) unary )* ;\nunary          -\u003e ( \"!\" | \"-\" ) unary | call ;\ncall           -\u003e primary ( \"(\" arguments? \")\" | \".\" IDENTIFIER )* ;\nprimary        -\u003e NUMBER | STRING | \"false\" | \"true\" | \"nil\"\n                | \"(\" expression \")\" | IDENTIFIER | funExpr\n                | \"super\" \".\" IDENTIFIER\n                // Erroneous grammar\n                | ( \"!=\" | \"==\" ) equality\n                | ( \"\u003e\" | \"\u003e=\" | \"\u003c\" | \"\u003c=\" ) comparison\n                | \"+\" addition\n                | ( \"/\" | \"*\" ) multiplication ;\nfunExpr        -\u003e \"fun\" \"(\" parameters? \")\" block ;\n```\n\n## Built-ins\n\nThe implementation contains the built-in functions from the book, as well as some additional ones.\n\nSome of these functions are inspired from their namesakes in the Lua language.\n\n * `print(value)` - Prints `value` to stdout (originally a statement).\n * `clock()` - Returns current time in seconds since the Unix epoch.\n * `read()` - Reads one line from stdin and returns it.\n * `type(value)` - Returns the type of `value`.\n * `tonumber(value)` - Converts `value` to a number (or `nil` if conversion fails).\n * `tostring(value)` - Returns the string representation of `value`.\n\n## License\n\nCopyright (c) 2017 by Adam Hellberg.\n\nThis project is licensed under the [MIT License][mit], following the [main repo][main] licensing the code part under MIT.\n\nSee the file `LICENSE` for more information.\n\n[book]: http://www.craftinginterpreters.com/\n[munificent]: https://github.com/munificent\n[mit]: https://opensource.org/licenses/MIT\n[main]: https://github.com/munificent/craftinginterpreters\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsharparam%2Fklox","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsharparam%2Fklox","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsharparam%2Fklox/lists"}