{"id":3235,"date":"2021-12-30T17:30:06","date_gmt":"2021-12-30T12:00:06","guid":{"rendered":"https:\/\/binaryterms.com\/?p=3235"},"modified":"2022-01-10T11:07:31","modified_gmt":"2022-01-10T05:37:31","slug":"context-free-grammar","status":"publish","type":"post","link":"https:\/\/binaryterms.com\/context-free-grammar.html","title":{"rendered":"Context-free Grammar"},"content":{"rendered":"<p>Context-free grammar (CFG) is a set of production rules that generates context-free language. In this context, we will be learning about the ambiguity in the CFG, its simplification, and its applications.<\/p>\n<h2>Content: Context-free Grammar<\/h2>\n<ol>\n<li><a href=\"#WhatisContext-freeGrammar?\">What is Context-free Grammar?<\/a><\/li>\n<li><a href=\"#NotationalConventionsofCFG\">Notational Conventions of CFG<\/a><\/li>\n<li><a href=\"#AmbiguityinContext-freeGrammar\">Ambiguity in Context-free Grammar<\/a><\/li>\n<li><a href=\"#SimplificationofContext-freeGrammar\">Simplification of Context-free Grammar<\/a><\/li>\n<li><a href=\"#ApplicationsofContext-freeGrammar\">Applications of Context-free Grammar<\/a><\/li>\n<\/ol>\n<p><a name=\"WhatisContext-freeGrammar?\"><\/a><\/p>\n<h3>What is Context-free Grammar?<\/h3>\n<p>Grammar is a set of production rules that defines the syntax of a language. We can define context-free grammar under the following four components:<\/p>\n<ul>\n<li><strong>Terminals:<\/strong> A set of terminals which we also refer to as tokens, these set of tokens forms strings.<\/li>\n<li><strong>Non-Terminals:<\/strong> CFG has a set of non-terminals (variables). These variables represent the set of strings. Further, they contribute to the formation of a language generated by grammar.<\/li>\n<li><strong>Start Symbol:<\/strong> A grammar has a set of production rules that has only one start symbol. This start symbol is always a nonterminal. Starting from the start symbol we can generate the set of strings. And this set of strings contributes to generating a language.<\/li>\n<li><strong>Production:<\/strong> A grammar has a set of production rules. These rules specify how to combine terminals and non-terminals to form a string. The set of strings further helps in the formation of language. A production rule must have:\n<ul>\n<li>A nonterminal which is also referred to as the head always lies at the left side of the production.<\/li>\n<li>A production rule consists of the symbol (arrow) &#8216;-&gt;&#8217; or sometimes &#8216;: = &#8216;. The arrow points towards the body of the production rule for the particular non-terminal.<\/li>\n<li>The body of the production rule occurs at the right side of the production. We can have zero or more terminals and non-terminals in the body of any production. It is the body of the production rule that describes the formation of strings.<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<h4>Example of Context-free Grammar:<\/h4>\n<p>Let us consider a grammar production<\/p>\n<div id=\"bleft\"><em>stmt<\/em> -&gt; <strong>if<\/strong> <em>(expr) stmt<\/em> <strong>else<\/strong> <em>stmt<\/em><\/div>\n<p>The production rule above specifies the structure of a conditional statement. From the production rule above:<\/p>\n<ul>\n<li>The <em>\u2018stmt\u2019<\/em> and <em>\u2018expr\u2019<\/em> are the non-terminals in the production above.<\/li>\n<li>The keywords <strong>\u2018if\u2019<\/strong> and <strong>\u2018else\u2019,<\/strong> and the symbols \u2018<strong>(<\/strong>\u2019 and \u2018<strong>)<\/strong>\u2019 are the tokens or terminals in the production above.<\/li>\n<li>In the production rule above the start symbol is the nonterminal <em>\u2018stmt\u2019.<\/em><\/li>\n<\/ul>\n<p><a name=\"NotationalConventionsofCFG\"><\/a><\/p>\n<h3>Notational Conventions of CFG<\/h3>\n<p>It is not always specified that for the following grammar, these are \u2018terminals\u2019 and these are \u2018non-terminals\u2019. So, for convenience there must be some notational conventions as discussed below:<\/p>\n<p><strong>For Terminals:<\/strong><\/p>\n<ul>\n<li>We refer to the lowercase characters like a, b, c, etc. as the terminals.<\/li>\n<li>Operators symbols like \u2018+\u2019, \u2018*\u2019, \u2018-\u2019 etc are also terminals.<\/li>\n<li>The tokens such as the punctuation marks such as comma, parenthesis, semicolon etc.<br \/>\nDigits present in the grammar are also considered as tokens.<\/li>\n<li>Bold style strings such as <strong>\u2018id\u2019, \u2018if\u2019, \u2018else\u2019<\/strong> are also terminals.<\/li>\n<\/ul>\n<p><strong>For Non-Terminals:<\/strong><\/p>\n<ul>\n<li>We refer to the uppercase characters like \u2018V\u2019, \u2018T\u2019, \u2018S\u2019. as non-terminals.<\/li>\n<li>Usually, we refer to the letter \u2018S\u2019 as a start symbol in grammar.<\/li>\n<li>Lowercase italic string is such as <em>\u2018stmt\u2019<\/em> or <em>\u2018expr\u2019.<\/em><\/li>\n<\/ul>\n<p><a name=\"AmbiguityinContext-freeGrammar\"><\/a><\/p>\n<h3>Ambiguity in Context-free Grammar<\/h3>\n<p>In grammar, if one production rule produces more than one parse tree, then the grammar is ambiguous. The grammar is even ambiguous if it is able to produce more than one left-most derivation. We can even refer to the grammar as ambiguous if it produced more than one right-most derivation.<\/p>\n<p>To understand this let us overview an example, consider the arithmetic expression grammar:<\/p>\n<div id=\"bleft\">E -&gt; E + E | E * E | (E) | <strong>id<\/strong><\/div>\n<p>For the input statement, <strong>id<\/strong> + <strong>id<\/strong> * <strong>id<\/strong> the grammar is able to produce two distinct left-most derivations. Observe the figure below:<\/p>\n<p>The first leftmost derivation for the above grammar is:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-3268\" src=\"https:\/\/binaryterms.com\/wp-content\/uploads\/2021\/12\/Ambiguous-sentence-of-context-free-grammar-1-1.jpg\" alt=\"Ambiguous sentence of context free grammar 1-1\" width=\"490\" height=\"204\" srcset=\"https:\/\/binaryterms.com\/wp-content\/uploads\/2021\/12\/Ambiguous-sentence-of-context-free-grammar-1-1.jpg 490w, https:\/\/binaryterms.com\/wp-content\/uploads\/2021\/12\/Ambiguous-sentence-of-context-free-grammar-1-1-300x125.jpg 300w\" sizes=\"auto, (max-width: 490px) 100vw, 490px\" \/><br \/>\nThe second left-most derivation for the above grammar is:<br \/>\n<img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-3269\" src=\"https:\/\/binaryterms.com\/wp-content\/uploads\/2021\/12\/Ambiguous-sentence-of-context-free-grammar-1-2.jpg\" alt=\"Ambiguous sentence of context free grammar 1-2\" width=\"479\" height=\"214\" srcset=\"https:\/\/binaryterms.com\/wp-content\/uploads\/2021\/12\/Ambiguous-sentence-of-context-free-grammar-1-2.jpg 479w, https:\/\/binaryterms.com\/wp-content\/uploads\/2021\/12\/Ambiguous-sentence-of-context-free-grammar-1-2-300x134.jpg 300w\" sizes=\"auto, (max-width: 479px) 100vw, 479px\" \/><\/p>\n<p>Thus we can declare the grammar above is ambiguous. As the grammar is producing two distinct left-most derivations for one production rule.<\/p>\n<p>An unambiguous grammar is always advantageous for the parser. As there will be no need to identify which parse tree to consider for the given input statement.<\/p>\n<p>You can choose ambiguous grammar along with disambiguating rules. These rules help in eliminating the undesirable parse trees. Thus it leaves a single parse tree for an input statement.<\/p>\n<p><a name=\"SimplificationofContext-freeGrammar\"><\/a><\/p>\n<h3>Simplification of\u00a0CFG<\/h3>\n<p>The context-free grammar is not always optimized. There may be some productions in the grammar that are redundant and not useful at all. These redundant productions only increase the size of the grammar.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-3243\" src=\"https:\/\/binaryterms.com\/wp-content\/uploads\/2021\/12\/Simplification-of-CFG.jpg\" alt=\"Simplification of CFG\" width=\"514\" height=\"133\" srcset=\"https:\/\/binaryterms.com\/wp-content\/uploads\/2021\/12\/Simplification-of-CFG.jpg 514w, https:\/\/binaryterms.com\/wp-content\/uploads\/2021\/12\/Simplification-of-CFG-300x78.jpg 300w\" sizes=\"auto, (max-width: 514px) 100vw, 514px\" \/><\/p>\n<p>We can simplify the context-free grammar by eliminating these redundant productions. Such that the simplified CFG must be equivalent to the original CFG. The simplified CFG must have the following properties::<\/p>\n<ol>\n<li>Each non-terminal or terminal in simplified CFG must appear in the formation of some sentence from the language.<\/li>\n<li>Simplified CFG must not consist of the production where a non-terminal produces a non-terminal only such as A -&gt; B.<\/li>\n<li>If there is no \u2208 in the language then there should not be any product that tends to \u2208.<\/li>\n<\/ol>\n<h4>1. Eliminating Useless Symbols<\/h4>\n<p>We refer to a symbol or variable as useless if it doesn\u2019t appear on the right side of any production rule of the grammar. They are useless even if it doesn\u2019t contribute in deriving any string.<\/p>\n<p><em>Example:<\/em><\/p>\n<div id=\"bleft\">S -&gt; aB | adA |abT<br \/>\nA -&gt; aA<br \/>\nB -&gt; ab|d<br \/>\nC -&gt; ab<\/div>\n<p><span data-offset-key=\"9q2rs-0-0\">In the above grammar, we cannot use the variable \u2018C\u2019 in deriving any string. As we can not reach variable &#8216;C&#8217; from the starting symbol T. So we can <\/span><span class=\"complexword\"><span data-offset-key=\"9q2rs-1-0\">eliminate<\/span><\/span><span data-offset-key=\"9q2rs-2-0\"> the production C -&gt; ab.<\/span><\/p>\n<p>Observe that the variable A in the grammar above is useless. As there is no way to terminate the symbol &#8216;A&#8217;. Thus, it will never produce a string. So, we must eliminate production A -&gt; aA such that no variable should lead to a string consisting of variable A.<\/p>\n<p>So, the modified grammar is:<\/p>\n<div id=\"bleft\">S -&gt; aB | abT<br \/>\nB -&gt; ab|d<\/div>\n<h4>2. Eliminate Production with \u2208<\/h4>\n<p>To simplify CFG we need to eliminate the production such as A -&gt; \u2208 also referred to as null productions. We can eliminate such production if the grammar does not generate an empty string. It is possible for a grammar to contain null production and yet does not produce an empty string.<\/p>\n<p><em>Steps to remove null productions:<\/em><\/p>\n<ol>\n<li>Identify all the non-terminals that derive \u2208.<\/li>\n<li>Construct all the production for the non-terminals (identified in step 1) by substituting \u2208.<\/li>\n<li>Now integrate the results of step 2 with original grammar. And eliminate \u2208 from the production.<\/li>\n<\/ol>\n<p><em>Example:<\/em> Consider the grammar<\/p>\n<div id=\"bleft\">S\u00a0\u2192\u00a0ABA<br \/>\nA \u2192 aA | \u2208<br \/>\nB\u00a0\u2192\u00a0bB\u00a0|\u00a0\u2208<\/div>\n<p>From the productions above we have to eliminate A -&gt; \u2208 and B -&gt; \u2208 such that the meaning of the original CFG is still preserved. Let us take the first production with the starting symbol S:<\/p>\n<div id=\"bleft\">S -&gt; ABA<\/div>\n<p>First, we will substitute A -&gt; \u2208 at first A of the production body. It results in:<\/p>\n<div id=\"bleft\">S -&gt; BA<\/div>\n<p>Now, substitute A -&gt; \u2208 at last A of the production it would result in:<\/p>\n<div id=\"bleft\">S -&gt; AB<\/div>\n<p>Now if we substitute B -&gt; \u2208<\/p>\n<div id=\"bleft\">S -&gt; AA<\/div>\n<p>If A -&gt; \u2208 and B -&gt; \u2208 then<\/p>\n<div id=\"bleft\">S-&gt; A<\/div>\n<p>If both As are replaced by \u2208<\/p>\n<div id=\"bleft\">S -&gt; B<\/div>\n<p>Now we will integrate the result with the original production rule of variable S.<\/p>\n<div id=\"bleft\">S -&gt; AB| BA | AA | A | B<\/div>\n<p>Similarly, we will replace \u2208 in the production:<\/p>\n<div id=\"bleft\">A -&gt; aA<\/div>\n<p>If A -&gt; \u2208 then<\/p>\n<div id=\"bleft\">A -&gt; a<\/div>\n<p>So, the original production we will appear as<\/p>\n<div id=\"bleft\">A -&gt; aA | a<\/div>\n<p>Similarly, for B -&gt; bB<\/p>\n<div id=\"bleft\">B -&gt; bB | b<\/div>\n<p>At last the grammar after eliminating \u2208 from the original grammar it appears as:<\/p>\n<div id=\"bleft\">S -&gt; AB| BA | AA | A | B<br \/>\nA -&gt; aA | a<br \/>\nB -&gt; bB | b<\/div>\n<h4>3. Eliminating Unit Productions<\/h4>\n<p>In a unit production, a non-terminal tends to another non-terminal such as A -&gt; B.<\/p>\n<p><em>Example:<\/em><\/p>\n<div id=\"bleft\">S -&gt; Aa | B<br \/>\nA -&gt; b | B<br \/>\nB -&gt; A | a<\/div>\n<p>The unit productions that we have in the original grammar are:<\/p>\n<div id=\"bleft\">S -&gt; B<br \/>\nA -&gt; B<br \/>\nB -&gt; A<\/div>\n<p>To eliminate unit productions, replace the non-terminal at the right side of the production with terminals. It will result in:<\/p>\n<div id=\"bleft\">S -&gt; b | a \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0(Since S -&gt; B where B -&gt; A|a &amp; A -&gt; b)<br \/>\nA -&gt; a<br \/>\nB -&gt; b<\/div>\n<p>Now integrate the improvised unit production to the original grammar.<\/p>\n<div id=\"bleft\">S -&gt; Aa | a | b<br \/>\nA -&gt; b | a<br \/>\nB -&gt; b | a<\/div>\n<p>The symbol &#8216;B&#8217; in the above grammar is useless. Because, there is no way to reach symbol &#8216;B&#8217; from the starting symbol S. So, further we will eliminate symbol B.<br \/>\nThus, the resultant CFG would be:<\/p>\n<div id=\"bleft\">S -&gt; Aa | a | b<br \/>\nA -&gt; b | a<\/div>\n<p><a name=\"ApplicationsofContext-freeGrammar\"><\/a><\/p>\n<h3>Applications of CFG<\/h3>\n<ul>\n<li>As CFG can efficiently describe a programming language. We can turn context-free grammar into a parser.<\/li>\n<li>CFG is helpful in describing the document type definition DTD in XML.<\/li>\n<\/ul>\n<p>So, this is all about the context-free grammar CFG. We have learnt about CFG, ambiguous CFG, simplification of CFG and applications of CFG.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Context-free grammar (CFG) is a set of production rules that generates context-free language. In this context, we will be learning about the ambiguity in the CFG, its simplification, and its applications. Content: Context-free Grammar What is Context-free Grammar? Notational Conventions of CFG Ambiguity in Context-free Grammar Simplification of Context-free Grammar Applications of Context-free Grammar What [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_genesis_hide_title":false,"_genesis_hide_breadcrumbs":false,"_genesis_hide_singular_image":false,"_genesis_hide_footer_widgets":false,"_genesis_custom_body_class":"","_genesis_custom_post_class":"","_genesis_layout":"","footnotes":""},"categories":[13],"tags":[],"class_list":{"0":"post-3235","1":"post","2":"type-post","3":"status-publish","4":"format-standard","6":"category-compiler-design","7":"entry"},"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v26.6 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>What is Context-free Grammar: Definition, Example, Simplification, &amp; Applications - Binary Terms<\/title>\n<meta name=\"description\" content=\"Context-free grammar (CFG) is a set of production rules that helps in generating context-free language.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/binaryterms.com\/context-free-grammar.html\" \/>\n<meta property=\"og:locale\" content=\"en_GB\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"What is Context-free Grammar: Definition, Example, Simplification, &amp; Applications - Binary Terms\" \/>\n<meta property=\"og:description\" content=\"Context-free grammar (CFG) is a set of production rules that helps in generating context-free language.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/binaryterms.com\/context-free-grammar.html\" \/>\n<meta property=\"og:site_name\" content=\"Binary Terms\" \/>\n<meta property=\"article:published_time\" content=\"2021-12-30T12:00:06+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2022-01-10T05:37:31+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/binaryterms.com\/wp-content\/uploads\/2021\/12\/Ambiguous-sentence-of-context-free-grammar-1-1.jpg\" \/>\n<meta name=\"author\" content=\"Neha T\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Neha T\" \/>\n\t<meta name=\"twitter:label2\" content=\"Estimated reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"8 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/binaryterms.com\/context-free-grammar.html#article\",\"isPartOf\":{\"@id\":\"https:\/\/binaryterms.com\/context-free-grammar.html\"},\"author\":{\"name\":\"Neha T\",\"@id\":\"https:\/\/binaryterms.com\/#\/schema\/person\/e495f1d57f5c0a4c521cc3dba95661fe\"},\"headline\":\"Context-free Grammar\",\"datePublished\":\"2021-12-30T12:00:06+00:00\",\"dateModified\":\"2022-01-10T05:37:31+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/binaryterms.com\/context-free-grammar.html\"},\"wordCount\":1527,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/binaryterms.com\/#organization\"},\"image\":{\"@id\":\"https:\/\/binaryterms.com\/context-free-grammar.html#primaryimage\"},\"thumbnailUrl\":\"https:\/\/binaryterms.com\/wp-content\/uploads\/2021\/12\/Ambiguous-sentence-of-context-free-grammar-1-1.jpg\",\"articleSection\":[\"Compiler Design\"],\"inLanguage\":\"en-GB\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/binaryterms.com\/context-free-grammar.html#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/binaryterms.com\/context-free-grammar.html\",\"url\":\"https:\/\/binaryterms.com\/context-free-grammar.html\",\"name\":\"What is Context-free Grammar: Definition, Example, Simplification, & Applications - Binary Terms\",\"isPartOf\":{\"@id\":\"https:\/\/binaryterms.com\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/binaryterms.com\/context-free-grammar.html#primaryimage\"},\"image\":{\"@id\":\"https:\/\/binaryterms.com\/context-free-grammar.html#primaryimage\"},\"thumbnailUrl\":\"https:\/\/binaryterms.com\/wp-content\/uploads\/2021\/12\/Ambiguous-sentence-of-context-free-grammar-1-1.jpg\",\"datePublished\":\"2021-12-30T12:00:06+00:00\",\"dateModified\":\"2022-01-10T05:37:31+00:00\",\"description\":\"Context-free grammar (CFG) is a set of production rules that helps in generating context-free language.\",\"breadcrumb\":{\"@id\":\"https:\/\/binaryterms.com\/context-free-grammar.html#breadcrumb\"},\"inLanguage\":\"en-GB\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/binaryterms.com\/context-free-grammar.html\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-GB\",\"@id\":\"https:\/\/binaryterms.com\/context-free-grammar.html#primaryimage\",\"url\":\"https:\/\/binaryterms.com\/wp-content\/uploads\/2021\/12\/Ambiguous-sentence-of-context-free-grammar-1-1.jpg\",\"contentUrl\":\"https:\/\/binaryterms.com\/wp-content\/uploads\/2021\/12\/Ambiguous-sentence-of-context-free-grammar-1-1.jpg\",\"width\":490,\"height\":204,\"caption\":\"Ambiguous sentence of context free grammar 1-1\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/binaryterms.com\/context-free-grammar.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/binaryterms.com\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Context-free Grammar\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/binaryterms.com\/#website\",\"url\":\"https:\/\/binaryterms.com\/\",\"name\":\"Binary Terms\",\"description\":\"The Computer Science &amp; IT Guide\",\"publisher\":{\"@id\":\"https:\/\/binaryterms.com\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/binaryterms.com\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-GB\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/binaryterms.com\/#organization\",\"name\":\"Binary Terms\",\"url\":\"https:\/\/binaryterms.com\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-GB\",\"@id\":\"https:\/\/binaryterms.com\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/binaryterms.com\/wp-content\/uploads\/2020\/05\/binary-terms-logo1.png\",\"contentUrl\":\"https:\/\/binaryterms.com\/wp-content\/uploads\/2020\/05\/binary-terms-logo1.png\",\"width\":400,\"height\":63,\"caption\":\"Binary Terms\"},\"image\":{\"@id\":\"https:\/\/binaryterms.com\/#\/schema\/logo\/image\/\"}},{\"@type\":\"Person\",\"@id\":\"https:\/\/binaryterms.com\/#\/schema\/person\/e495f1d57f5c0a4c521cc3dba95661fe\",\"name\":\"Neha T\",\"url\":\"https:\/\/binaryterms.com\/author\/author\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"What is Context-free Grammar: Definition, Example, Simplification, & Applications - Binary Terms","description":"Context-free grammar (CFG) is a set of production rules that helps in generating context-free language.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/binaryterms.com\/context-free-grammar.html","og_locale":"en_GB","og_type":"article","og_title":"What is Context-free Grammar: Definition, Example, Simplification, & Applications - Binary Terms","og_description":"Context-free grammar (CFG) is a set of production rules that helps in generating context-free language.","og_url":"https:\/\/binaryterms.com\/context-free-grammar.html","og_site_name":"Binary Terms","article_published_time":"2021-12-30T12:00:06+00:00","article_modified_time":"2022-01-10T05:37:31+00:00","og_image":[{"url":"https:\/\/binaryterms.com\/wp-content\/uploads\/2021\/12\/Ambiguous-sentence-of-context-free-grammar-1-1.jpg","type":"","width":"","height":""}],"author":"Neha T","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Neha T","Estimated reading time":"8 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/binaryterms.com\/context-free-grammar.html#article","isPartOf":{"@id":"https:\/\/binaryterms.com\/context-free-grammar.html"},"author":{"name":"Neha T","@id":"https:\/\/binaryterms.com\/#\/schema\/person\/e495f1d57f5c0a4c521cc3dba95661fe"},"headline":"Context-free Grammar","datePublished":"2021-12-30T12:00:06+00:00","dateModified":"2022-01-10T05:37:31+00:00","mainEntityOfPage":{"@id":"https:\/\/binaryterms.com\/context-free-grammar.html"},"wordCount":1527,"commentCount":0,"publisher":{"@id":"https:\/\/binaryterms.com\/#organization"},"image":{"@id":"https:\/\/binaryterms.com\/context-free-grammar.html#primaryimage"},"thumbnailUrl":"https:\/\/binaryterms.com\/wp-content\/uploads\/2021\/12\/Ambiguous-sentence-of-context-free-grammar-1-1.jpg","articleSection":["Compiler Design"],"inLanguage":"en-GB","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/binaryterms.com\/context-free-grammar.html#respond"]}]},{"@type":"WebPage","@id":"https:\/\/binaryterms.com\/context-free-grammar.html","url":"https:\/\/binaryterms.com\/context-free-grammar.html","name":"What is Context-free Grammar: Definition, Example, Simplification, & Applications - Binary Terms","isPartOf":{"@id":"https:\/\/binaryterms.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/binaryterms.com\/context-free-grammar.html#primaryimage"},"image":{"@id":"https:\/\/binaryterms.com\/context-free-grammar.html#primaryimage"},"thumbnailUrl":"https:\/\/binaryterms.com\/wp-content\/uploads\/2021\/12\/Ambiguous-sentence-of-context-free-grammar-1-1.jpg","datePublished":"2021-12-30T12:00:06+00:00","dateModified":"2022-01-10T05:37:31+00:00","description":"Context-free grammar (CFG) is a set of production rules that helps in generating context-free language.","breadcrumb":{"@id":"https:\/\/binaryterms.com\/context-free-grammar.html#breadcrumb"},"inLanguage":"en-GB","potentialAction":[{"@type":"ReadAction","target":["https:\/\/binaryterms.com\/context-free-grammar.html"]}]},{"@type":"ImageObject","inLanguage":"en-GB","@id":"https:\/\/binaryterms.com\/context-free-grammar.html#primaryimage","url":"https:\/\/binaryterms.com\/wp-content\/uploads\/2021\/12\/Ambiguous-sentence-of-context-free-grammar-1-1.jpg","contentUrl":"https:\/\/binaryterms.com\/wp-content\/uploads\/2021\/12\/Ambiguous-sentence-of-context-free-grammar-1-1.jpg","width":490,"height":204,"caption":"Ambiguous sentence of context free grammar 1-1"},{"@type":"BreadcrumbList","@id":"https:\/\/binaryterms.com\/context-free-grammar.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/binaryterms.com\/"},{"@type":"ListItem","position":2,"name":"Context-free Grammar"}]},{"@type":"WebSite","@id":"https:\/\/binaryterms.com\/#website","url":"https:\/\/binaryterms.com\/","name":"Binary Terms","description":"The Computer Science &amp; IT Guide","publisher":{"@id":"https:\/\/binaryterms.com\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/binaryterms.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-GB"},{"@type":"Organization","@id":"https:\/\/binaryterms.com\/#organization","name":"Binary Terms","url":"https:\/\/binaryterms.com\/","logo":{"@type":"ImageObject","inLanguage":"en-GB","@id":"https:\/\/binaryterms.com\/#\/schema\/logo\/image\/","url":"https:\/\/binaryterms.com\/wp-content\/uploads\/2020\/05\/binary-terms-logo1.png","contentUrl":"https:\/\/binaryterms.com\/wp-content\/uploads\/2020\/05\/binary-terms-logo1.png","width":400,"height":63,"caption":"Binary Terms"},"image":{"@id":"https:\/\/binaryterms.com\/#\/schema\/logo\/image\/"}},{"@type":"Person","@id":"https:\/\/binaryterms.com\/#\/schema\/person\/e495f1d57f5c0a4c521cc3dba95661fe","name":"Neha T","url":"https:\/\/binaryterms.com\/author\/author"}]}},"_links":{"self":[{"href":"https:\/\/binaryterms.com\/wp-json\/wp\/v2\/posts\/3235","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/binaryterms.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/binaryterms.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/binaryterms.com\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/binaryterms.com\/wp-json\/wp\/v2\/comments?post=3235"}],"version-history":[{"count":21,"href":"https:\/\/binaryterms.com\/wp-json\/wp\/v2\/posts\/3235\/revisions"}],"predecessor-version":[{"id":3275,"href":"https:\/\/binaryterms.com\/wp-json\/wp\/v2\/posts\/3235\/revisions\/3275"}],"wp:attachment":[{"href":"https:\/\/binaryterms.com\/wp-json\/wp\/v2\/media?parent=3235"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/binaryterms.com\/wp-json\/wp\/v2\/categories?post=3235"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/binaryterms.com\/wp-json\/wp\/v2\/tags?post=3235"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}