{"id":24757757,"url":"https://github.com/hkoosha/toylang1","last_synced_at":"2025-03-23T09:11:35.025Z","repository":{"id":39629465,"uuid":"494811406","full_name":"hkoosha/toylang1","owner":"hkoosha","description":"A toy language (to be), from scratch, written in Rust","archived":false,"fork":false,"pushed_at":"2022-10-29T06:47:20.000Z","size":256,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-02-18T21:40:46.532Z","etag":null,"topics":["programming-language","programming-language-development","rust","rust-lang"],"latest_commit_sha":null,"homepage":"","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/hkoosha.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":"2022-05-21T14:48:38.000Z","updated_at":"2023-06-08T12:14:51.000Z","dependencies_parsed_at":"2023-01-19T18:03:24.835Z","dependency_job_id":null,"html_url":"https://github.com/hkoosha/toylang1","commit_stats":null,"previous_names":["hkoosha/toylang1","hkoosha/toylang"],"tags_count":null,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hkoosha%2Ftoylang1","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hkoosha%2Ftoylang1/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hkoosha%2Ftoylang1/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hkoosha%2Ftoylang1/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/hkoosha","download_url":"https://codeload.github.com/hkoosha/toylang1/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245078190,"owners_count":20557281,"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":["programming-language","programming-language-development","rust","rust-lang"],"created_at":"2025-01-28T15:35:04.964Z","updated_at":"2025-03-23T09:11:35.019Z","avatar_url":"https://github.com/hkoosha.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"A toy language, from scratch, based on the book [Engineering a Compiler][engineering_a_compiler].\n\n### Currently implemented\n\n- A lexer, with predefined token kinds (defined in token.rs).\n- A backtracking parser for an arbitrary grammar, but currently depends on the\n  lexer and it's predefined token kinds.\n- A backtrack-free, recursive descent parser for an arbitrary grammar, but\n  currently depends on the lexer and it's predefined token kinds.\n\n## Rules parser\n\nA sample grammar, simply defined as a string and parsed into grammar. The\ngrammar can have left recursion, the `Rules` parser can eliminate left\nrecursions.\n\nIt can also (almost) fix the grammar, so it becomes backtrack-free by\neliminating common left prefix from production definitions.\n\n```\nS               -\u003e fn_call_or_decl , S | fn_call_or_decl |\nfn_call_or_decl -\u003e fn_call | fn_declaration\nfn_call         -\u003e ID ( args ) ;\nargs            -\u003e arg , args | arg |\narg             -\u003e STRING | INT | ID\nfn_declaration  -\u003e FN ID ( params ) { statements }\nparams          -\u003e param , params | param |\nparam           -\u003e ID ID\nstatements      -\u003e statement statements | statement |\nstatement       -\u003e ID ID ; | ID = expressions ; | fn_call | ret \nexpressions     -\u003e terms + expressions | terms - expressions | terms\nterms           -\u003e factor * terms | factor / terms | factor\nfactor          -\u003e ( expressions ) | INT | ID\nret             -\u003e RETURN expressions ;\n```\n\n### Example Program\n\nA sample syntactically correct program for grammar above (semantically it will\nbe wrong, after implementing later stages of the compiler due to missing type\ndefinitions for x1, x2, ... ):\n\n```\nfn my_thing42(int j, string q) {\n    x1 = 1 * 30;\n    x2 = x3 / 10;\n    int y;\n    y = x4 + 2;\n    int z;\n    print(\"foo\\\"bar \\\\some thing\");\n    z = x5 * y;\n    print(z);\n    int x0;\n    return x0 + 0;\n};\n```\n\n[engineering_a_compiler]: https://www.elsevier.com/books/engineering-a-compiler/cooper/978-0-12-815412-0\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhkoosha%2Ftoylang1","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhkoosha%2Ftoylang1","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhkoosha%2Ftoylang1/lists"}