{"id":23029722,"url":"https://github.com/antononcube/raku-mathematica-grammar","last_synced_at":"2025-06-11T18:04:01.265Z","repository":{"id":71383774,"uuid":"403146071","full_name":"antononcube/Raku-Mathematica-Grammar","owner":"antononcube","description":"Grammar for parsing Mathematica (aka Wolfram Language) expressions.","archived":false,"fork":false,"pushed_at":"2022-12-08T00:40:57.000Z","size":60,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-04-02T20:33:17.430Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Raku","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"artistic-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/antononcube.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}},"created_at":"2021-09-04T20:03:01.000Z","updated_at":"2023-03-30T17:30:17.000Z","dependencies_parsed_at":"2023-02-28T16:31:02.177Z","dependency_job_id":null,"html_url":"https://github.com/antononcube/Raku-Mathematica-Grammar","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/antononcube/Raku-Mathematica-Grammar","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/antononcube%2FRaku-Mathematica-Grammar","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/antononcube%2FRaku-Mathematica-Grammar/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/antononcube%2FRaku-Mathematica-Grammar/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/antononcube%2FRaku-Mathematica-Grammar/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/antononcube","download_url":"https://codeload.github.com/antononcube/Raku-Mathematica-Grammar/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/antononcube%2FRaku-Mathematica-Grammar/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":259311800,"owners_count":22838794,"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":[],"created_at":"2024-12-15T14:16:57.076Z","updated_at":"2025-06-11T18:04:01.259Z","avatar_url":"https://github.com/antononcube.png","language":"Raku","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Raku Mathematica::Grammar\n\nThis package provides grammar and action classes for parsing and interpretation \nof Mathematica (aka Wolfram Language) expressions.\n\n------\n\n## Usage examples\n\n***Currently only Mathematica\n[`FullForm`](https://reference.wolfram.com/language/ref/FullForm.html)\nexpressions parsing is implemented.***\n\n```perl6\nuse Mathematica::Grammar;\n\nsay Mathematica::Grammar.parse( 'Plus[List[a,b],List[2,3]]');\n```\nSee the file\n[\"Basic-WL-expressions-parsing.raku\"](./examples/Basic-WL-expressions-parsing.raku)\nor the [unit tests](./t) for more examples.\n\n------\n\n## Grammar derivation\n\nIn order to derive the grammars I did the following steps:\n\n1. Take [ANTLR4 grammars](https://github.com/rocky/FoxySheep2/tree/master/grammar)\nfrom Rocky Bernstein's Python package\n[FoxySheep2](https://github.com/rocky/FoxySheep2), [RB1].\n   \n   - For more details of the origins of the \"foxy sheep\" projects see Robert Jacobson's project\n     [FoxySheep](https://github.com/rljacobson/FoxySheep), [RJ1].\n\n2. Translate the g4 grammars from ANTLR4's BNF-like format to Raku using Jeff Goff's Raku package\n[ANTLR4::Grammar](https://github.com/drforr/perl6-ANTLR4), [JG1].\n   \n   - See the conversion code in the file\n     [Convert-FoxySheep2-ANTLR4-grammars.raku](./examples/Convert-FoxySheep2-ANTLR4-grammars.raku)\n     \n   - Comment out\n     in\n     [InputFormLexerRules.g4](https://github.com/rocky/FoxySheep2/blob/master/grammar/InputFormLexerRules.g4)\n     :\n\n```g4\noptions{\n  //We put target-language dependent code in a base class.\n  superClass=LexerBase;\n}\n```\n\n3. Minor grammar tweaks:\n   \n   - Convert some tokens into regexes\n     \n   - Convert `( ... )` groups into `[ ... ]`  \n   \n   - Translate applications of ANTLR4 sequence idiom into Raku's standard idiom, e.g. `\u003cexpr\u003e % \u003cCOMMA\u003e`\n    \n4. 'Fix' the left recursion of `\u003cexpr\u003e` in \n  [\"FullForm.rakumod\"](./lib/Mathematica/Grammar/FullForm.rakumod).\n   Compare the original ANTLR4-derived rule and its replacement:\n\n```perl6\n# Original\ntoken expr {\n    ||\t\u003cnumberLiteral\u003e\n    ||\t\u003cStringLiteral\u003e\n    ||\t\u003csymbol\u003e\n    ||\t\u003cexpr\u003e\n        \u003cLBRACKET\u003e\n        \u003cexpressionList\u003e\n        \u003cRBRACKET\u003e }\n```   \n\n```perl6\n# Replacement\ntoken expr-head {\n    ||\t\u003cnumberLiteral\u003e\n    ||\t\u003cStringLiteral\u003e\n    ||\t\u003csymbol\u003e\n}\n\nregex expr {\n    || \u003cexpr-head\u003e \\h* [ \u003cLBRACKET\u003e \\h* \u003cexpressionList\u003e \\h* \u003cRBRACKET\u003e ]+\n    || \u003cexpr-head\u003e\n}\n``` \n\nFor the actual ANTLR4-to-Raku conversion code see the file\n[\"Convert-FoxySheep2-ANTLR4-grammars.raku\"](./examples/Convert-FoxySheep2-ANTLR4-grammars.raku).\n\n------\n\n## TODO\n\nHighest priority items are put on top:\n\n1. [ ] Provide execution Raku actions.\n   \n2. [ ] Parsing `FullForm` expressions tests:\n   \n   - [X] Algebraic\n   - [ ] Arithmetic\n      - [ ] Standard\n      - [ ] BigNum\n      - [ ] Rationals\n   - [ ] `List`\n   - [ ] `Association`\n   - [ ] `Dataset`\n   - [ ] `VerificationTest`\n   - [ ] Function definitions\n    \n3. [ ] Make the `InputForm` work.\n\n4. [ ] Parsing `InputForm` expressions tests:\n    \n   - [X] Algebraic\n   - [ ] Arithmetic\n      - [ ] Standard\n      - [ ] BigNum\n      - [ ] Rationals\n   - [ ] `List`\n   - [ ] `Association`\n   - [ ] `Dataset`\n   - [ ] `VerificationTest`\n   - [ ] Function definitions\n   \n5. Provide execution actions for natural languages explanations\n \n   - [ ] English\n   - [ ] Bulgarian\n\n------\n\n## References\n\n[JG1] Jeff Goff,\n[ANTLR4::Grammar Raku package](https://github.com/drforr/perl6-ANTLR4),\n(2015),\n[GitHub/drforr](https://github.com/drforr).\n\n[RB1] Rocky Bernstein,\n[FoxySheep2 Python package](https://github.com/rocky/FoxySheep2),\n(2015),\n[GitHub/rocky](https://github.com/rocky).\n\n[RJ1] Robert Jacobson,\n[FoxySheep Python package](https://github.com/rljacobson/FoxySheep),\n(2015),\n[GitHub/rljacobson](https://github.com/rljacobson).\n\n[TP1] Terrance Parr, [ANTLR, https://www.antlr.org](https://www.antlr.org).\n\n[TP1] Terrance Parr,\n[The Definitive ANTLR 4 Reference](https://pragprog.com/titles/tpantlr2/the-definitive-antlr-4-reference/),\n(2013),\nPragmatic Bookshelf,\nISBN:978-1-934356-99-9.","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fantononcube%2Fraku-mathematica-grammar","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fantononcube%2Fraku-mathematica-grammar","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fantononcube%2Fraku-mathematica-grammar/lists"}