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 terminals is derived in exactly 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 , where .
- Variable (non-terminal) : the left-hand side of every production.
- Terminal : the right-hand side must begin with exactly one terminal.
- : 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 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 terminals, the number of derivation steps needed is exactly .
How it works
- Each derivation step uses a production , which contributes exactly one terminal (the leading ).
- The number of terminals in the sentential form therefore increases by exactly one per step.
- Starting from 0 terminals (the start symbol alone) and reaching terminals, one terminal per step, the total number of steps is .
- Since every step derives a terminal, deriving a string in GNF is faster than in CNF — it takes fewer steps.
Formulas
- — general form of a GNF production; = a variable (non-terminal), = a single terminal, = a string of zero or more variables.
- — number of derivation steps to generate a string , where = number of terminals in the string.
Worked examples
Example grammar (in GNF):
Check: has terminal followed by one variable ; has terminal followed by zero variables. Every production is of the form , so the grammar is in GNF.
Derivation of the string , step by step:
| Step | Sentential form | Production used | Terminals so far |
|---|---|---|---|
| 0 | — (start) | 0 | |
| 1 | 1 (terminal ) | ||
| 2 | 2 (terminals , ) |
Step 1 derives one terminal (); step 2 derives one more terminal (). The number of terminals increases by one at every step. Starting from 0 and going up to , the number of steps required is .
Comparison
| Aspect | GNF | CNF |
|---|---|---|
| Production form | , (one terminal, then any number of variables) | or (binary/terminal productions) |
| Terminals added per step | Exactly one terminal per step | Not necessarily one terminal per step |
| Steps to derive a string of length | steps | More than steps |
| Speed of derivation | Faster (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 with a terminal and .
- The right-hand side must start with exactly one terminal; only variables may follow it.
- may contain zero, one, two, or any number of variables — zero variables is allowed.
- Each step adds exactly one terminal, so a string of terminals takes exactly 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.