Math 2.0

Computer science Definition

Formal grammar

Builds on AlphabetStringFormal languageKleene star

Definition

A formal grammar is a tuple G=(N,Σ,P,S)G = (N, \Sigma, P, S) where:

  1. NN is a finite set of nonterminal symbols.
  2. Σ\Sigma is a finite alphabet of terminal symbols, disjoint from NN.
  3. PP is a finite set of production rules α→β\alpha \to \beta, where α,β\alpha, \beta are strings in (N∪Σ)∗(N \cup \Sigma)^* and α\alpha contains at least one nonterminal.
  4. S∈NS \in N is the start symbol.

Here (N∪Σ)∗(N \cup \Sigma)^* is the Kleene star of N∪ΣN \cup \Sigma. For strings x,yx, y over N∪ΣN \cup \Sigma, one writes x⇒yx \Rightarrow y if x=uαvx = u \alpha v and y=uβvy = u \beta v for some rule α→β\alpha \to \beta in PP and some strings u,vu, v. Let ⇒∗\Rightarrow^* be the reflexive and transitive closure of ⇒\Rightarrow; a chain x⇒⋯⇒yx \Rightarrow \cdots \Rightarrow y is a derivation. The language generated by GG is the formal language L(G)={w∈Σ∗:S⇒∗w}.L(G) = \set{w \in \Sigma^* : S \Rightarrow^* w}.

Remarks

Example: N={S}N = \set{S}, Σ={a,b}\Sigma = \set{a, b}, P={S→aSb, S→ε}P = \set{S \to aSb, \ S \to \varepsilon}. Each derivation step either adds one aa and one bb around SS or removes SS, so L(G)={anbn:n≥0}L(G) = \set{a^n b^n : n \ge 0}. Non-example: a "rule" ab→baab \to ba over Σ={a,b}\Sigma = \set{a, b} is not allowed, because its left side has no nonterminal. Two grammars are equivalent if they generate the same language. Often NN is called VV and PP is called RR.

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. Alphabet concept
  2. Formal language concept
  3. Kleene star concept
  4. String concept
  5. Formal grammar definition

Further reading

  1. Web https://en.wikipedia.org/wiki/Formal_grammar
About this page
TagKB1791Y0P8
URIm2://KB1791Y0P8
Kinddefinition
WritingW0 stub
MSC68Q42, 68Q45, 03D05
DefinesFormal grammar
UsesAlphabet, String, Formal language, Kleene star
Changed3 November 2026

Markdown · JSON · Edit on GitHub

What this page needs for W1

  • an inventory row: the row of the inventory that the node accounts for (0 of 1)
  • 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.