formal grammar (grammar)

  • is a set of production rules for strings in a formal language
  • does not describe the meaning of the strings or what can be done with them in whatever context—only their form

formal language/expressions

  • are generated by the grammar

Formal Grammars - Formal Definition

a formal grammar G is defined as the tuple (N, Σ, P, S):

  • N - a finite set of nonterminal symbols, that is disjoint with the strings formed from G

  • Σ - a finite set of terminal symbols that is disjoint from N

  • P - (the grammar) a finite set of production rules, each rule of the form:

    • (ΣN)* N (ΣN)* → (ΣN)*
      where:that is, each production rule maps from one string of symbols to another, where the first string (the “head”) contains an arbitrary number of symbols provided at least one of them is a nonterminal. In the case that the second string (the “body”) consists solely of the empty string—i.e., that it contains no symbols at all—it may be denoted with a special notation (often Λ, e, or ϵ) in order to avoid confusion.
      • * is the Kleene star operator
      • ∪ denotes set union
  • S - a distinguished symbol in N that is the start symbol, also called the sentence symbol

Formal Grammars - Example

Formal Grammars - Mathematical Constructs

Formal Grammars - Chomsky Hierarchy

Formal Grammars - Chomsky Hierarchy Extended