{"id":21347065,"url":"https://github.com/yann39/cyk-grammar-parser","last_synced_at":"2025-10-25T06:33:22.422Z","repository":{"id":223737319,"uuid":"753068590","full_name":"Yann39/cyk-grammar-parser","owner":"Yann39","description":"Java Swing application to demonstrate grammar parsing using the Cocke–Younger–Kasami algorithm","archived":false,"fork":false,"pushed_at":"2024-02-21T19:47:35.000Z","size":72,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-09T00:42:00.059Z","etag":null,"topics":["cocke-younger-kasami-algorithm","cyk-algorithm","grammar-parser","graphics2d","java","swing"],"latest_commit_sha":null,"homepage":"","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Yann39.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}},"created_at":"2024-02-05T12:08:01.000Z","updated_at":"2024-02-21T19:51:24.000Z","dependencies_parsed_at":"2024-02-21T20:48:04.990Z","dependency_job_id":null,"html_url":"https://github.com/Yann39/cyk-grammar-parser","commit_stats":null,"previous_names":["yann39/cyk-grammar-parser"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Yann39%2Fcyk-grammar-parser","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Yann39%2Fcyk-grammar-parser/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Yann39%2Fcyk-grammar-parser/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Yann39%2Fcyk-grammar-parser/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Yann39","download_url":"https://codeload.github.com/Yann39/cyk-grammar-parser/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243822277,"owners_count":20353499,"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":["cocke-younger-kasami-algorithm","cyk-algorithm","grammar-parser","graphics2d","java","swing"],"created_at":"2024-11-22T02:12:32.032Z","updated_at":"2025-10-25T06:33:22.322Z","avatar_url":"https://github.com/Yann39.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Cocke–Younger–Kasami (CYK) Algorithm\n\nBasic **Java Swing** application to demonstrate **grammar parsing** using the **Cocke–Younger–Kasami** algorithm.\n\n![Version](https://img.shields.io/badge/Version-1.0.0-2AAB92.svg)\n![Static Badge](https://img.shields.io/badge/Last%20update-12%20Apr%202008-blue)\n![Version](https://img.shields.io/badge/Java-6-red.svg)\n\n---\n\n# Table of Contents\n\n* [About the project](#about-the-project)\n* [Usage](#usage)\n    * [Grammar](#grammar)\n    * [Expression](#expression)\n    * [File](#file)\n* [Technical details](#technical-details)\n    * [Pyramid base calculation](#pyramid-base-calculation)\n    * [Pyramid upper part calculation](#pyramid-upper-part-calculation)\n    * [Tree calculation](#tree-calculation)\n* [License](#license)\n\n## About the project\n\n\u003cimg alt=\"Java logo\" src=\"doc/logo-java.svg\" height=\"92\"/\u003e\n\nThis is a simple GUI application (in French) that demonstrate grammar parsing using the **Cocke–Younger–Kasami** algorithm.\n\nApplication has been built on **April 2008** using **Netbeans IDE 5.5**.\n\nIt uses the **Swing Application Framework** and was compiled with **Java 6**.\n\nDrawings were built using the **Graphics2D** library.\n\n# Usage\n\nRun the provided `.jar` file :\n\n```bash\njava -jar \"dist/ProjetLangageFormel.jar\"\n```\n\nThen just use the UI.\nThe interface consists of two input areas for entering the **grammar** and the **expression** to check.\n\n![Main interface picture](doc/main_interface.png?raw=true \"Main interface\")\n\nOnce the information is entered, just click on the \"Vérifier\" (check) button to check if the expression is valid.\n\nIf it is valid, a success message will be displayed in the \"Résultat\" (Result) area as well as two buttons to display the **pyramid** and a preview of the **tree**.\n\n![Pyramid interface picture](doc/pyramid_interface.png?raw=true \"Pyramid interface\")\n\n![Tree interface picture](doc/tree_interface.png?raw=true \"Tree interface\")\n\nThere is also a button \"Importer un fichier\" (Import a file) which allows to import a grammar and an expression in the program from a file.\nThis avoids entering the grammar and expression manually every time. The file must have a specific format described in the next section.\nFour example files have been provided in the `samples` directory.\n\n## Grammar\n\nA rule must be entered without spaces or line breaks, and with the following syntax: `left term\u003e right terms`\n\nFor example for `S\u003e AB`, `S` is the left term, `A` and `B` are the right terms.\n\nThe program does not allow to enter terms of more than 1 character, indeed in the example above, `AB` cannot be considered as a single term but only as two distinct terms `A`\nand `B`.\n\nThe complete grammar must be entered with a new line after each term, without spaces, by using the following syntax:\n\n```\nleft term\u003e right terms\nleft term\u003e right terms\nleft term\u003e right terms\n```\n\n## Expression\n\nThe expression to be checked must be entered without spaces or line breaks. Only one expression must be specified.\n\nExample: `abbabaaba`\n\n## File\n\nImportable files in the application must have the following format:\n\n```\n#########\nGrammar\n#########\nS\u003e AA\nS\u003e AS\nS\u003e b\nA\u003e SA\nA\u003e AS\nA\u003e has\n##########\nExpression\n##########\nabbabab\n```\n\nThe grammar and expression input rules apply as well as if they were entered directly in the input fields.\n\n## Technical details\n\n### Pyramid base calculation\n\nThe pyramid is actually represented in memory via a two-dimensional array (`String[][]`), following the below scheme about indices :\n\n![Pyramid indices picture](doc/pyramid_indices.png?raw=true \"Pyramid indices\")\n\nTo calculate the base of the pyramid, we call, for each letter in the expression, a function that takes as arguments :\n\n- the list of left terms\n- the list of right terms\n- the letter\n\nand returns a comma separated list of terms. We store each time the result in the corresponding cell of the pyramid.\n\n### Pyramid upper part calculation\n\nTo calculate the upper part of the pyramid, we go trough all the lines (except the base) and all the cells, and apply the following algorithm :\n\n```\nfor i:=2 to n do\n    for j:=1 à n-i+1 do\n        for m:=1 à i-1 do\n            if B exists in cell (m,j) and C exists in cell (i-m,j+m) so that A-\u003eBC € R\n                put A in cell (i,j)\n        done\n    done\ndone\n```\n\nFor that we have to :\n\n- find all possible pairs of two strings of type `A, B, C, D`.\n- find each of the right terms (separated by commas) that generate a couple.\n- remove all duplicates in a string of type `A, B, C, D` in order not to have several times the same value in a cell of the pyramid.\n\n### Tree calculation\n\nActually it does not generate a real tree but another pyramid with highlighted terms that represent the tree.\n\nNumbers will be displayed in the upper right corner of each cell to indicate the pairs of cells which made possible to find a node of the tree (2 cells with the same number\nindicates that they have been used together to find the next node).\n\nThis functionality is done using a recursive function, it is applied first to the top of the pyramid, then it is called recursively as soon as it finds a couple of suitable cells.\n\n**Example** :\n\nFollowing grammar :\n\n```\nS\u003eAB A\u003ea C\u003eBA\nS\u003eBB B\u003eBB C\u003eAA\nA\u003eCC B\u003eCA C\u003eb\nA\u003eAB B\u003eb\n```\n\nwith following expression :\n\n```\nbbbabbaaba\n```\n\nGive the following pyramid :\n\n![Pyramid example picture](doc/pyramid_example.png?raw=true \"Pyramid example\")\n\nwhich corresponds to the following tree :\n\n![Tree example picture](doc/tree_example.png?raw=true \"Tree example\")\n\nThere are multiple possible trees for some grammars, however the program will show always the same tree, as the algorithm always takes the first value that it finds for a couple of\nterms.\n\n# License\n\n[General Public License (GPL) v3](https://www.gnu.org/licenses/gpl-3.0.en.html)\n\nThis program is free software: you can redistribute it and/or modify it under the terms of the GNU\nGeneral Public License as published by the Free Software Foundation, either version 3 of the\nLicense, or (at your option) any later version.\n\nThis program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without\neven the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\nGeneral Public License for more details.\n\nYou should have received a copy of the GNU General Public License along with this program. If not,\nsee \u003chttp://www.gnu.org/licenses/\u003e.","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyann39%2Fcyk-grammar-parser","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fyann39%2Fcyk-grammar-parser","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyann39%2Fcyk-grammar-parser/lists"}