{"id":35129601,"url":"https://github.com/codewitheshayoutube/content-free-grammar-project","last_synced_at":"2026-05-21T02:33:20.122Z","repository":{"id":290167203,"uuid":"973572489","full_name":"codewithEshaYoutube/Content-Free-Grammar-Project","owner":"codewithEshaYoutube","description":null,"archived":false,"fork":false,"pushed_at":"2025-05-13T15:27:33.000Z","size":14,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-05-13T16:44:18.419Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/codewithEshaYoutube.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":".github/CODEOWNERS","security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2025-04-27T09:25:47.000Z","updated_at":"2025-05-13T15:27:36.000Z","dependencies_parsed_at":null,"dependency_job_id":"ba5997ee-ba46-417d-b5bc-1744f34aa97d","html_url":"https://github.com/codewithEshaYoutube/Content-Free-Grammar-Project","commit_stats":null,"previous_names":["codewitheshayoutube/content-free-grammar-project"],"tags_count":0,"template":false,"template_full_name":"streamlit/blank-app-template","purl":"pkg:github/codewithEshaYoutube/Content-Free-Grammar-Project","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/codewithEshaYoutube%2FContent-Free-Grammar-Project","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/codewithEshaYoutube%2FContent-Free-Grammar-Project/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/codewithEshaYoutube%2FContent-Free-Grammar-Project/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/codewithEshaYoutube%2FContent-Free-Grammar-Project/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/codewithEshaYoutube","download_url":"https://codeload.github.com/codewithEshaYoutube/Content-Free-Grammar-Project/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/codewithEshaYoutube%2FContent-Free-Grammar-Project/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":33286045,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-20T15:12:43.734Z","status":"online","status_checked_at":"2026-05-21T02:00:07.181Z","response_time":62,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":"2025-12-28T04:57:48.427Z","updated_at":"2026-05-21T02:33:20.117Z","avatar_url":"https://github.com/codewithEshaYoutube.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# 📘 Context-Free Grammar (CFG) in Automata — Python Code Example\n\nThis guide explains **Context-Free Grammar (CFG)** in Automata theory and shows how to implement a parser in Python using the `lark` library.\n\n---\n\n```python\n# 📄 What is CFG?\n# CFG stands for Context-Free Grammar.\n# It defines the syntactic rules for a language using recursive productions.\n\n# A CFG is a 4-tuple: G = (V, Sigma, R, S)\n# - V: Set of variables (non-terminal symbols)\n# - Sigma: Set of terminals (input alphabet)\n# - R: Set of production rules\n# - S: Start symbol\n\n# 📄 Example: CFG for Balanced Parentheses\n# V = {S}\n# Sigma = {(, )}\n# R:\n#   S → (S)\n#   S → SS\n#   S → ε (empty string)\n\n# This grammar generates:\n# \"\", \"()\", \"(())\", \"()()\", \"(()())\", etc.\n\n# 📦 Step 1: Install the required library\n# Run this in your terminal if not already installed:\n# pip install lark\n\n# 🧠 Step 2: Python Code Implementation\n\nfrom lark import Lark\n\n# Define CFG grammar using Lark syntax\ncfg_grammar = \"\"\"\n    start: expr\n\n    expr: \"(\" expr \")\"        -\u003e parens\n        | expr expr           -\u003e concat\n        |                     -\u003e empty\n\"\"\"\n\n# Create a parser for the grammar\nparser = Lark(cfg_grammar, start='start')\n\n# Test input strings for validation\ntest_strings = [\"\", \"()\", \"(())\", \"()()\", \"(()())\", \"(()\", \"())(\"]\n\n# Check each string and print whether it is valid\nfor s in test_strings:\n    try:\n        parser.parse(s)\n        print(f\"✔ '{s}' is VALID\")\n    except:\n        print(f\"✘ '{s}' is INVALID\")\n\n# 📄 Output:\n# ✔ '' is VALID\n# ✔ '()' is VALID\n# ✔ '(())' is VALID\n# ✔ '()()' is VALID\n# ✔ '(()())' is VALID\n# ✘ '(()' is INVALID\n# ✘ '())(' is INVALID\n\n# ✅ Summary:\n# This script demonstrates how to use a context-free grammar to validate\n# balanced parentheses using the `lark` library in Python.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcodewitheshayoutube%2Fcontent-free-grammar-project","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcodewitheshayoutube%2Fcontent-free-grammar-project","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcodewitheshayoutube%2Fcontent-free-grammar-project/lists"}