{"id":16982244,"url":"https://github.com/maxpatiiuk/leto","last_synced_at":"2025-06-28T07:34:19.004Z","repository":{"id":126933315,"uuid":"579453883","full_name":"maxpatiiuk/leto","owner":"maxpatiiuk","description":"This is a two part project that allows to create a lexer and a parser (with syntax directed translation) for an arbitrary LL(1) programming language.","archived":false,"fork":false,"pushed_at":"2023-12-03T22:07:40.000Z","size":1118,"stargazers_count":2,"open_issues_count":2,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-04-19T10:08:56.175Z","etag":null,"topics":["compiler","interpreter","language","parser","programming-language"],"latest_commit_sha":null,"homepage":"https://max.patii.uk/projects/alia","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/maxpatiiuk.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}},"created_at":"2022-12-17T18:47:35.000Z","updated_at":"2023-12-03T22:54:17.000Z","dependencies_parsed_at":"2023-12-03T22:21:19.904Z","dependency_job_id":"565d2be1-1c72-4a5e-9a52-4ba89fefed3f","html_url":"https://github.com/maxpatiiuk/leto","commit_stats":null,"previous_names":["maxpatiiuk/leto"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/maxpatiiuk/leto","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/maxpatiiuk%2Fleto","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/maxpatiiuk%2Fleto/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/maxpatiiuk%2Fleto/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/maxpatiiuk%2Fleto/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/maxpatiiuk","download_url":"https://codeload.github.com/maxpatiiuk/leto/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/maxpatiiuk%2Fleto/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":262392787,"owners_count":23303989,"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":["compiler","interpreter","language","parser","programming-language"],"created_at":"2024-10-14T02:07:41.917Z","updated_at":"2025-06-28T07:34:18.986Z","avatar_url":"https://github.com/maxpatiiuk.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# leto\n\nThis is a two part project that allows to create a lexer and a parser\n(with syntax directed translation) for an arbitrary\n[LL(1)](https://en.wikipedia.org/wiki/LL_grammar) programming language.\n\nYou might also be interested in [Alia](https://github.com/maxpatiiuk/alia) -\na compiler and interpreter for my programming language.\n\n## Prerequisites\n\n- Node 18\n- NPM 8\n\n## Installation\n\nInstall dependencies:\n\n```shell\nnpm install\n```\n\n## Lexer\n\nLexer is a Scanner-Generator. It's syntax is based on that of\n[Flex](https://www.cs.princeton.edu/~appel/modern/c/software/flex/flex.html).\n\nExample spec is provided in [`./fixtures/lexer.spec`](./fixtures/lexer.spec):\n\n![Lexer Spec file](./docs/img/lexer-spec.png)\n\nSpec file consists of list of rules. Each rule begins with a regular expression.\n\nSecond part could be one of:\n\n- `(SKIP)` - throws out matching text.\n- `(ERR)` - emits an error. Error will include token position. An error\n  message can be provided as a third argument.\n- any other string - will be used as a token type. In this case, the third part\n  of the rule is a boolean indicating whether this token type should capture\n  the matched characters (useful for identifiers and literals).\n\n## Running Lexer\n\nTo see available options, run the script with the `--help` argument:\n\n```shell\n./lexer --help\n```\n\nExample call:\n\n```shell\n./lexer --spec ./fixtures/lexer.spec --input ./fixtures/in.leto --output ./fixtures/out.tokens\n```\n\nWhere, `./fixtures/in.leto` is:\n\n```\n1 / (1\n   + 4)\n```\n\nThis is how resulting token steam looks like (outputted in `./fixtures/out.tokens`):\n\n![Lexer Result](./docs/img/lexer-tokens.png)\n\n## Parser \u0026 Syntax-Directed Translator\n\nSyntax-directed translator-generator written in TypeScript.\n\nImplements an [LL(1)](https://en.wikipedia.org/wiki/LL_grammar) parser.\n\n### Running Parser\n\nTo see available options, run the script with the `--help` argument:\n\n```shell\n./parser --help\n```\n\nExample call (using `fixtures/out.tokens` generated by lexer in the previous step):\n\n```shell\n./parser --grammar ./fixtures/parser.spec --tokens ./fixtures/out.tokens --executable fixtures/executable.js\n```\n\nWhere `./fixtures/parser.spec` contains the grammar and syntax-directed\ntranslation rules:\n\n![Parser Spec file](./docs/img/parser-spec.png)\n\nThe file is split into 3 sections (using `%%` as a separator):\n\n- First section defines a grammar and calls to syntax-directed translation\n  functions.\n- Second section allow to initialize the environment for the syntax-directed\n  translation (i.e, allocate a stack, define helper functions). Any JavaScript\n  code can be put in here.\n- Third section defines syntax-directed translation functions. Each definition\n  has it's own local scope in which you can write JavaScript.\n\nRunning the parser will generate JavaScript file that, when executed, will print\nthe result of the syntax-directed translation:\n\n![Generated Executable](./docs/img/executable.png)\n\n```shell\nnode ./fixtures/executable.js\n```\n\nOutput:\n\n```\nCalculation: 0.2\n```\n\n## Compiler and Interpreter\n\nYou might also be interested in [Alia](https://github.com/maxpatiiuk/alia) -\na compiler and interpreter for my programming language.\n\n## Unit Tests\n\nJest is used for unit testing.\n\nYou can run it like this:\n\n```shell\nnpm test\n```\n\n## Naming\n\nProject name comes from Leto Atreides II from the Dune science fiction series.","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmaxpatiiuk%2Fleto","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmaxpatiiuk%2Fleto","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmaxpatiiuk%2Fleto/lists"}