{"id":15936938,"url":"https://github.com/cyberzhg/parse-toys","last_synced_at":"2025-04-03T19:44:07.737Z","repository":{"id":78867137,"uuid":"325935953","full_name":"CyberZHG/parse-toys","owner":"CyberZHG","description":"Parsing toys","archived":false,"fork":false,"pushed_at":"2021-02-16T08:07:31.000Z","size":28,"stargazers_count":2,"open_issues_count":0,"forks_count":1,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-02-09T08:16:58.547Z","etag":null,"topics":["cnf","cyk","unger"],"latest_commit_sha":null,"homepage":"","language":"Python","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/CyberZHG.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":"2021-01-01T07:28:29.000Z","updated_at":"2021-02-21T06:21:56.000Z","dependencies_parsed_at":"2023-05-24T12:30:59.871Z","dependency_job_id":null,"html_url":"https://github.com/CyberZHG/parse-toys","commit_stats":null,"previous_names":["lwislvislie/parse-toys","cyberzhg/parse-toys"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CyberZHG%2Fparse-toys","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CyberZHG%2Fparse-toys/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CyberZHG%2Fparse-toys/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CyberZHG%2Fparse-toys/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/CyberZHG","download_url":"https://codeload.github.com/CyberZHG/parse-toys/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247070780,"owners_count":20878581,"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":["cnf","cyk","unger"],"created_at":"2024-10-07T04:41:23.608Z","updated_at":"2025-04-03T19:44:07.721Z","avatar_url":"https://github.com/CyberZHG.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Parsing Toys\n\n[![Build Status](https://www.travis-ci.com/CyberZHG/parse-toys.svg?branch=master)](https://www.travis-ci.com/CyberZHG/parse-toys)\n[![Coverage](https://coveralls.io/repos/github/CyberZHG/parse-toys/badge.svg?branch=master)](https://coveralls.io/github/CyberZHG/parse-toys)\n\n## Install\n\n```bash\npip install git+https://github.com/cyberzhg/parse-toys\n```\n\n## Methods\n\n### General Non-Directional Parsing\n\n#### Unger Parsing\n\n```python\nfrom parse_toys import Grammar, parse_with_unger\n\ngrammar = Grammar()\ngrammar.parse(\"\"\"\n    Expr -\u003e Expr + Term | Term\n    Term -\u003e Term × Factor | Factor\n    Factor -\u003e ( Expr ) | i\n\"\"\")\nparsed = parse_with_unger(grammar, '(i+i)×i')\nprint(parsed)\n\"\"\"\n('Term',\n    ('Term × Factor',\n        ('Factor', \n            ('( Expr )',\n                '(',\n                ('Expr + Term', ('Term', ('Factor', ('i', 'i'))),\n                '+',\n                ('Factor', ('i', 'i'))),')')),\n        '×',\n        ('i', 'i'))))\n\"\"\"\n```\n\n#### Chomsky Normal Form\n\n```python\nfrom parse_toys import Grammar, to_chomsky_normal_form\n\ngrammar = Grammar()\ngrammar.parse(\"\"\"\nNumber -\u003e Integer | Real\nInteger -\u003e Digit | Integer Digit\nReal -\u003e Integer Fraction Scale\nFraction -\u003e . Integer\nScale -\u003e e Sign Integer | Empty\nDigit -\u003e 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9\nSign -\u003e + | -\nEmpty -\u003e ε\n        \"\"\")\ngrammar = to_chomsky_normal_form(grammar)\nprint(grammar)\n\"\"\"\n  Number -\u003e 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9\n          | Integer Digit\n          | Integer Fraction\n          | N_1 Scale_1\n Integer -\u003e 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9\n          | Integer Digit\nFraction -\u003e T_1 Integer\n   Digit -\u003e 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9\n    Sign -\u003e + | -\n Scale_1 -\u003e N_2 Integer\n     N_1 -\u003e Integer Fraction\n     T_1 -\u003e .\n     T_2 -\u003e e\n     N_2 -\u003e T_2 Sign\n\"\"\"\n```\n\n#### CYK Parsing\n\n```python\nfrom parse_toys import Grammar, parse_with_cyk\n\ngrammar = Grammar()\ngrammar.parse(\"\"\"\nNumber -\u003e Integer | Real\nInteger -\u003e Digit | Integer Digit\nReal -\u003e Integer Fraction Scale\nFraction -\u003e . Integer\nScale -\u003e e Sign Integer | Empty\nDigit -\u003e 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9\nSign -\u003e + | -\nEmpty -\u003e ε\n\"\"\")\n\nparsed = parse_with_cyk(grammar, '32.5')\nprint(parsed)\n\"\"\"\n('Real',\n    (('Integer Fraction Scale',\n        (('Integer Digit', (('Digit', (('3',),)), ('2',))),\n        ('. Integer', ('.', ('Digit', (('5',),)))),\n        ('Empty', (('ε',),)))),)))\n\"\"\"\n\nparsed = parse_with_cyk(grammar, '32.5e+1')\nprint(parsed)\n\"\"\"\n('Real',\n    (('Integer Fraction Scale',\n        (('Integer Digit', (('Digit', (('3',),)), ('2',))),\n        ('. Integer', ('.', ('Digit', (('5',),)))),\n        ('e Sign Integer', ('e', ('+',), ('Digit', (('1',),)))))),))\n\"\"\"\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcyberzhg%2Fparse-toys","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcyberzhg%2Fparse-toys","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcyberzhg%2Fparse-toys/lists"}