{"id":20384346,"url":"https://github.com/gyakobo/recognizing-context-free-languages-with-a-pda","last_synced_at":"2026-06-06T17:32:56.859Z","repository":{"id":239535135,"uuid":"799796269","full_name":"Gyakobo/Recognizing-context-free-languages-with-a-PDA","owner":"Gyakobo","description":"The following project should define a PDA that in its turn would recognize a specific context-free language.","archived":false,"fork":false,"pushed_at":"2024-06-02T12:46:45.000Z","size":110,"stargazers_count":3,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-04T23:12:59.628Z","etag":null,"topics":["context-free-language","proofs","pushdown-automaton","python3","theoretical-computer-science"],"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/Gyakobo.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":"2024-05-13T05:53:23.000Z","updated_at":"2024-12-03T18:10:35.000Z","dependencies_parsed_at":"2024-11-15T02:29:59.522Z","dependency_job_id":"8c28b142-6bae-4c5e-ad11-57fe6b6c5964","html_url":"https://github.com/Gyakobo/Recognizing-context-free-languages-with-a-PDA","commit_stats":null,"previous_names":["gyakobo/recognizing_context_free_languages_with_a_pda","gyakobo/recognizing-context-free-languages-with-a-pda"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Gyakobo%2FRecognizing-context-free-languages-with-a-PDA","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Gyakobo%2FRecognizing-context-free-languages-with-a-PDA/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Gyakobo%2FRecognizing-context-free-languages-with-a-PDA/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Gyakobo%2FRecognizing-context-free-languages-with-a-PDA/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Gyakobo","download_url":"https://codeload.github.com/Gyakobo/Recognizing-context-free-languages-with-a-PDA/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":241935269,"owners_count":20044827,"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":["context-free-language","proofs","pushdown-automaton","python3","theoretical-computer-science"],"created_at":"2024-11-15T02:27:28.041Z","updated_at":"2026-06-06T17:32:56.819Z","avatar_url":"https://github.com/Gyakobo.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Language Recognition with a PDA(Pushdown Automaton)\r\n\r\n![image](https://img.shields.io/badge/Python-FFD43B?style=for-the-badge\u0026logo=python\u0026logoColor=blue)\r\n![image](https://img.shields.io/badge/windows%20terminal-4D4D4D?style=for-the-badge\u0026logo=windows%20terminal\u0026logoColor=white)\r\n\r\nAuthor: [Andrew Gyakobo](https://github.com/Gyakobo)\r\n\r\n## Introduction\r\nThe following project should define a PDA that in its turn would recognize a specific context-free language.\r\n\r\n## Let's have a look at Language A\r\n* A, in simple terms, is a language that defines all necessary arithmetic floating point numbers and valid operations on said decimal or whole numbers. \r\n\r\n* A select string of language A is of the form: \r\n  $ab^kaEab^ka, k\u003e=0$\r\n\r\n* Here is an example string: $abba(1.2*(1.-2.+3.1))abba$\r\n\r\n\u003e[!Note] \r\n\u003eLanguage A is not a regular language, however, it's a context-free language\r\n\r\n### Context Free Grammar for A\r\n\r\nLanguage A can be defined by a 4-tuple context-free grammar $G = (V, \\Sigma, R, S)$, where:\r\n\r\n* V = {S, T, C, H, Y, N} (set of variables, or non-terminals)\r\n\r\n* $\\Sigma$ = {., 0, 1, 2, ..., 9, +, -, *, /, (, ), a, b} (Mind you $\\Sigma$ is the alphabet of all available letters, digits, and characters)\r\n\r\n* S (start variable)\r\n\r\nSpeaking about R, the rules are as follows:\r\n\r\n* $S \\rightarrow aTa$\r\n* $T \\rightarrow bTb|aCa$\r\n* $C \\rightarrow C+C|C-C|C*C|C/C|(C)|H$\r\n* $H \\rightarrow Y.Y|Y.|.Y$ \r\n* $Y \\rightarrow NY|N$\r\n* $N \\rightarrow 0|1|2|3|4|5|6|7|8|9$\r\n\r\n## Let's now handle a sample example\r\n$S \\Rightarrow aTa \\Rightarrow abTba \\Rightarrow abbTbba \\Rightarrow abba(C)abba \\Rightarrow abba(C * C)abba$\r\n\r\n$\\Rightarrow abba(C* (C))abba \\Rightarrow abba(C * (C-C+C))abba$\r\n\r\n$\\Rightarrow abba(H * (C-C+C))abba \\Rightarrow abba(Y.Y * (C-C+C))abba \\Rightarrow abba(N.N * (C-C+C))abba$\r\n\r\n$\\Rightarrow abba(1.2*(C-C+C))abba \\Rightarrow abba(1.2*(H-C+C))abba \\Rightarrow abba(1.2 * (Y.-C+C))abba$\r\n\r\n$\\Rightarrow abba(1.2*(N.-C+C))abba \\Rightarrow abba(1.2*(1.-C+C))abba \\Rightarrow abba(1.2 * (1. - H + C))abba$\r\n\r\n$\\Rightarrow abba(1.2 * (1. - Y. + C))abba \\Rightarrow abba(1.2 * (1. - N. + C))abba \\Rightarrow abba(1.2 * (1. - 2. + C))$\r\n\r\n$\\Rightarrow abba(1.2 * (1. - 2. + H))abba \\Rightarrow abba(1.2 * (1. - 2. + Y.Y))abba \\Rightarrow abba(1.2 * (1. - 2. + 3.1))abba$\r\n\r\n### Pushdown Automaton 'M'\r\n\r\nHere's a simple graphic demonstration of the PDA:\r\n\r\n\u003cimg src=\"assets/PDF_img.png\" style=\"float: left; margin-bottom: 1rem;\"\u003e\r\n\r\n#### Examples\r\n\r\nLet's run the Pushdown Automaton M on the following string: \r\n\r\n\u003e[!Note] \r\n\u003eThe PDA also utilizes a stack data structure in order to keep track of the a's and b's in the said string. Basically it's using two main commands to do so: push and pop. Each of these commands either insert a value on the top of the stack or remove the said value also from the top of the stack. \r\n\r\n```\r\nw = abbba43.51386abbba\r\n```\r\n\r\n```\r\nEnter string 1 of 15: abbba43.51386abbba\r\nStarting on State Q1\r\n$: Q1\r\nRead '$'\r\nPopped 'ε' from stack\r\nPushed '$' to stack\r\nMoving to state Q2\r\n\r\na: Q2\r\nRead 'a'\r\nPopped 'ε' from stack\r\nPushed 'a' to stack\r\nMoving to state Q3\r\n\r\nb: Q3\r\nRead 'b'\r\nPopped 'ε' from stack\r\nPushed 'b' to stack\r\nMoving to state Q3\r\n\r\nb: Q3\r\nRead 'b'\r\nPopped 'ε' from stack\r\nPushed 'b' to stack\r\nMoving to state Q3\r\n\r\nb: Q3\r\nRead 'b'\r\nPopped 'ε' from stack\r\nPushed 'b' to stack\r\nMoving to state Q3\r\n\r\na: Q3\r\nRead 'a'\r\nPopped 'ε' from stack\r\nPushed 'a' to stack\r\nMoving to state Q4\r\n\r\n4: Q4\r\nRead '4'\r\nPopped 'ε' from stack\r\nPushed 'ε' to stack\r\nMoving to state Q5\r\n\r\n3: Q5\r\nRead '3'\r\nPopped 'ε' from stack\r\nPushed 'ε' to stack\r\nMoving to state Q5\r\n\r\n.: Q5\r\nRead '.'\r\nPopped 'ε' from stack\r\nPushed 'ε' to stack\r\nMoving to state Q7\r\n\r\n5: Q7\r\nRead '5'\r\nPopped 'ε' from stack\r\nPushed 'ε' to stack\r\nMoving to state Q7\r\n\r\n1: Q7\r\nRead '1'\r\nPopped 'ε' from stack\r\nPushed 'ε' to stack\r\nMoving to state Q7\r\n\r\n3: Q7\r\nRead '3'\r\nPopped 'ε' from stack\r\nPushed 'ε' to stack\r\nMoving to state Q7\r\n\r\n8: Q7\r\nRead '8'\r\nPopped 'ε' from stack\r\nPushed 'ε' to stack\r\nMoving to state Q7\r\n\r\n6: Q7\r\nRead '6'\r\nPopped 'ε' from stack\r\nPushed 'ε' to stack\r\nMoving to state Q7\r\n\r\na: Q7\r\nRead 'a'\r\nPopped 'a' from stack\r\nPushed 'ε' to stack\r\nMoving to state Q9\r\n\r\nb: Q9\r\nRead 'b'\r\nPopped 'b' from stack\r\nPushed 'ε' to stack\r\nMoving to state Q9\r\n\r\nb: Q9\r\nRead 'b'\r\nPopped 'b' from stack\r\nPushed 'ε' to stack\r\nMoving to state Q9\r\n\r\nb: Q9\r\nRead 'b'\r\nPopped 'b' from stack\r\nPushed 'ε' to stack\r\nMoving to state Q9\r\n\r\na: Q9\r\nRead 'a'\r\nPopped 'a' from stack\r\nPushed 'ε' to stack\r\nMoving to state Q10\r\n\r\nε: Q10\r\nRead 'ε'\r\nPopped '$' from stack\r\nPushed 'ε' to stack\r\n\r\nString is accepted!\r\n```\r\n\r\n## License\r\nMIT\r\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgyakobo%2Frecognizing-context-free-languages-with-a-pda","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgyakobo%2Frecognizing-context-free-languages-with-a-pda","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgyakobo%2Frecognizing-context-free-languages-with-a-pda/lists"}