Math 2.0

Computer science Definition

Context-free grammar

Builds on Formal grammarFormal languageStringRooted tree

Definition

A context-free grammar is a formal grammar G=(N,Σ,P,S)G = (N, \Sigma, P, S) in which every rule has the form A→βA \to \beta with A∈NA \in N and β∈(N∪Σ)∗\beta \in (N \cup \Sigma)^*. The relation ⇒\Rightarrow, derivations and the language L(G)={w∈Σ∗:S⇒∗w}L(G) = \set{w \in \Sigma^* : S \Rightarrow^* w} are those of the formal grammar.

Remarks

Example: N={S}N = \set{S}, Σ={(,)}\Sigma = \set{(, )}, P={S→SS, S→(S), S→ε}P = \set{S \to SS, \ S \to (S), \ S \to \varepsilon}. Every left side is the single nonterminal SS, so this grammar is context-free; it generates the balanced strings of brackets. Non-example: a grammar with the rule aA→abaA \to ab is not context-free, because the left side has two symbols. A leftmost derivation rewrites the leftmost nonterminal at each step. A derivation of a string ww corresponds to a parse tree, a rooted tree with root SS. Its inner nodes are labelled by nonterminals, the children of a node are read off a rule, and the leaves spell ww from left to right. Parse trees of ww are in bijection with leftmost derivations of ww.

Reading path

To understand this page from the ground up, read these 5 pages in order. The foundations come first.

Show the path as a graph
Each page uses the pages above it. The colour of the bar on a box shows how strong the evidence is, and the box also gives it as text. The list has the same pages.
  • no evidence level
  1. Formal grammar concept
  2. Formal language concept
  3. Rooted tree concept
  4. String concept
  5. Context-free grammar definition

Further reading

  1. Web https://en.wikipedia.org/wiki/Context-free_grammar
About this page
Tag8R5ZPQ7893
URIm2://8R5ZPQ7893
Kinddefinition
WritingW0 stub
MSC68Q42, 68Q45
DefinesContext-free grammar
UsesFormal grammar, Formal language, String, Rooted tree
Changed3 November 2026

Markdown · JSON · Edit on GitHub

What this page needs for W1

  • a source with a locator (0 of 1)

The writing levels say how complete the text of a page is. They do not measure its truth.

What links here

No page links to this page yet.