1. Gyanastra
  2. Theory of Computation
  3. Normal Forms of CFG
  4. Greibach Normal Form (GNF)
Free lesson, no account needed 5 min read 2 practice questions after it
Asked in past papers3 times
  • UGC NET201920132012

Theory of Computation · Normal Forms of CFG

Greibach Normal Form (GNF)

Overview

Greibach Normal Form (GNF) is a restricted representation of a context-free grammar, named after the scientist Greibach.
It matters because every production adds exactly one terminal per derivation step, so a string of WW terminals is derived in exactly WW steps — faster than with CNF.

Key concepts

  • Greibach Normal Form (GNF): a context-free grammar is in GNF if all its productions have the form A→aαA \to a\alpha, where α∈V∗\alpha \in V^*.
  • Variable (non-terminal) AA: the left-hand side of every production.
  • Terminal aa: the right-hand side must begin with exactly one terminal.
  • α∈V∗\alpha \in V^*: the remainder of the right-hand side is a string of zero or more variables — no terminals after the first one. The number of variables may be four, three, two, one, or even zero.
  • Fast derivation: every production A→aαA \to a\alpha adds exactly one terminal at each derivation step, because the right-hand side always starts with a single terminal followed only by variables.
  • Step count: if the string to be generated has WW terminals, the number of derivation steps needed is exactly WW.

How it works

  1. Each derivation step uses a production A→aαA \to a\alpha, which contributes exactly one terminal (the leading aa).
  2. The number of terminals in the sentential form therefore increases by exactly one per step.
  3. Starting from 0 terminals (the start symbol alone) and reaching WW terminals, one terminal per step, the total number of steps is WW.
  4. Since every step derives a terminal, deriving a string in GNF is faster than in CNF — it takes fewer steps.

Formulas

  • A→aαA \to a\alpha — general form of a GNF production; AA = a variable (non-terminal), aa = a single terminal, α∈V∗\alpha \in V^* = a string of zero or more variables.
  • steps=∣w∣=W\text{steps} = |w| = W — number of derivation steps to generate a string ww, where WW = number of terminals in the string.

Worked examples

Example grammar (in GNF):

  • A→aBA \to aB
  • B→bB \to b

Check: A→aBA \to aB has terminal aa followed by one variable BB; B→bB \to b has terminal bb followed by zero variables. Every production is of the form A→aαA \to a\alpha, so the grammar is in GNF.

Derivation of the string abab, step by step:

StepSentential formProduction usedTerminals so far
0AA— (start)0
1aBaBA→aBA \to aB1 (terminal aa)
2ababB→bB \to b2 (terminals aa, bb)

Step 1 derives one terminal (aa); step 2 derives one more terminal (bb). The number of terminals increases by one at every step. Starting from 0 and going up to W=2W = 2, the number of steps required is W=2W = 2.

Comparison

AspectGNFCNF
Production formA→aαA \to a\alpha, α∈V∗\alpha \in V^* (one terminal, then any number of variables)A→BCA \to BC or A→aA \to a (binary/terminal productions)
Terminals added per stepExactly one terminal per stepNot necessarily one terminal per step
Steps to derive a string of length WWWW stepsMore than WW steps
Speed of derivationFaster (fewer steps)Slower compared to GNF

Revision summary

  • GNF is named after the scientist Greibach; it is a restricted form of context-free grammar.
  • A CFG is in GNF only if every production is of the form A→aαA \to a\alpha with aa a terminal and α∈V∗\alpha \in V^*.
  • The right-hand side must start with exactly one terminal; only variables may follow it.
  • α\alpha may contain zero, one, two, or any number of variables — zero variables is allowed.
  • Each step adds exactly one terminal, so a string of WW terminals takes exactly WW steps.
  • GNF derivations are faster (fewer steps) than CNF derivations.

Previous-year exam insights

  • A CFG in GNF may not contain λ-productions (except possibly S → λ if λ is in the language) and may not contain unit productions A → B; every production must start with a terminal.
    Asked inUGC NET 2012
  • To test whether a grammar is in GNF, check every production: the right-hand side must begin with a terminal, not a variable; a production like A → B... or A → aA | AB with a leading variable violates GNF.
    Asked inUGC NET 2012
  • Every context-free grammar without λ (or with λ only via S → λ) can be converted to an equivalent GNF; the standard construction first converts to CNF, orders variables, and eliminates left recursion and leading variables.
    Asked inUGC NET 2013
  • In GNF, a production may have any number of variables after the leading terminal, including zero (A → a), and the leading terminal is exactly one terminal symbol.
    Asked inUGC NET 2012UGC NET 2013
  • CNF has productions A → BC and A → a only; the maximum number of productions in an equivalent CNF grammar for a grammar with |P| productions, maximum RHS length K, and |T| terminals is (K-1)|P| + |T|.
    Asked inUGC NET 2019
  • GNF is useful for top-down parsing because each step deterministically consumes one input terminal, giving a leftmost derivation in the order of the input string.
Pages 1–2 of 2