How unit 3 is examined
Grammar types, CFG design and proofs, derivation trees, ambiguity, simplification and the CNF and GNF conversions; CFG, ambiguity, derivation trees and CNF carry the marks.
Types of grammar
Not asked since 2022
Definition. A grammar is $G=(V,T,P,S)$: variables, terminals, productions $\alpha\to\beta$ and a start symbol; it generates the language $L(G)=\{w\in T^*\mid S\Rightarrow^* w\}$.
Key points.
- Chomsky classified grammars by the shape of productions into Type 0 (unrestricted), Type 1 (context sensitive), Type 2 (context free) and Type 3 (regular).
- Each type is a proper subset of the one before, so $3\subset2\subset1\subset0$.
A grammar is a four-tuple (V, T, P, S) and its language is every terminal string derivable from S.
Context sensitive grammar
Not asked since 2022
Definition. A context sensitive grammar (Type 1) has productions $\alpha A\beta\to\alpha\gamma\beta$ with $\gamma\neq\varepsilon$, so $|\text{left}|\le|\text{right}|$ and no production shrinks the string.
Key points.
- $A\to\gamma$ applies only in the context $\alpha\_\beta$, hence the name.
- It is accepted by a linear bounded automaton, a Turing machine limited to the input's length.
- $S\to\varepsilon$ is allowed only if $S$ never appears on a right side.
- Example: $a^nb^nc^n$ uses $S\to aSBC\mid aBC$, $CB\to BC$, $aB\to ab$, $bB\to bb$, $bC\to bc$, $cC\to cc$.
Context sensitive productions never decrease length, and LBAs accept exactly these languages.
Context free grammar
High weight
Definition. A CFG is $G=(V,T,P,S)$ where every production has the form $A\to\alpha$, one variable on the left and $\alpha\in(V\cup T)^*$ on the right.
Key points.
- $V$ is the finite set of variables, $T$ the terminals, $P$ the productions and $S\in V$ the start symbol.
- Example $S\to aSb\mid\varepsilon$ generates $\{a^nb^n\mid n\ge0\}$, e.g. $S\Rightarrow aSb\Rightarrow aaSbb\Rightarrow aabb$.
- Design by matching: a recursion $S\to aSb$ pairs two counts, and independent parts get their own variable.
- For a union of languages add $S\to S_1\mid S_2$; for a concatenation add $S\to S_1S_2$.
- Context-free languages are closed under union, concatenation and star but not intersection.
Design answers (verified by listing strings).
- $a^nb^mc^n$, $m,n\ge1$: $S\to aSc\mid aBc$, $B\to bB\mid b$. Integer: $S\to GN\mid N$, $G\to +\mid -$, $N\to DN\mid D$, $D\to0\mid1\mid\dots\mid9$.
- $(011+1)^*(01)^*$: $S\to AB$, $A\to 011A\mid1A\mid\varepsilon$, $B\to01B\mid\varepsilon$.
- $a^{n+2}b^{n+1}$ ($n=m$): $S\to aaAb$, $A\to aAb\mid\varepsilon$.
- At least two a's: $V=\{S,X\}$, $T=\{a,b\}$, $S\to XaXaX$, $X\to aX\mid bX\mid\varepsilon$. No $bbb$: $S\to aS\mid bA\mid\varepsilon$, $A\to aS\mid bB\mid\varepsilon$, $B\to aS\mid\varepsilon$ ($S,A,B$ = 0,1,2 b's just read).
- $a^ib^jc^k$, $i\ne j$ or $j\ne k$: $S\to S_1C\mid AS_2$, $S_1\to aS_1b\mid aP\mid bQ$, $P\to aP\mid\varepsilon$, $Q\to bQ\mid\varepsilon$, $C\to cC\mid\varepsilon$, $A\to aA\mid\varepsilon$, $S_2\to bS_2c\mid bR\mid cT$, $R\to bR\mid\varepsilon$, $T\to cT\mid\varepsilon$. And $a^ib^{2i}$: $S\to aSbb\mid\varepsilon$.
Union closure. Let $G_1,G_2$ generate $A,B$ with start symbols $S_1,S_2$ (variables renamed apart). Add a new start $S\to S_1\mid S_2$. Any derivation from $S$ first picks $S_1$ or $S_2$ and then stays in that grammar, so $L(G)=A\cup B$, which is context free.
Pumping lemma. If $L$ is a CFL there is $p$ such that every $z\in L$ with $|z|\ge p$ splits as $uvwxy$ with $|vwx|\le p$, $|vx|\ge1$ and $uv^iwx^iy\in L$ for all $i\ge0$.
- $a^nb^nc^n$ is not CFL: take $z=a^pb^pc^p$. Since $|vwx|\le p$, $vwx$ misses at least one of $a,b,c$, so pumping to $i=2$ raises at most two counts and the third stays $p$; counts differ, $uv^2wx^2y\notin L$, a contradiction.
- $a^ib^{2i}a^i$ is not CFL: take $z=a^pb^{2p}a^p$. As $|vwx|\le p<2p$, $vwx$ cannot touch both $a$-blocks; pumping with $i=2$ then breaks first $a$ count $=$ last $a$ count or $b$ count $=2\times a$ count. Contradiction.
A context-free grammar has productions $A\to\alpha$ with a single variable on the left.
Answer frame. Open with the 4-tuple definition; for a design question write the language in the form $a^nb^n$ core plus fixed parts, then productions, then one derivation of a short string; for a proof write assume CFL, choose $z$, split $uvwxy$, pump, contradiction.
Pitfall: In $a^nb^mc^n$ the $b$ count is independent, so it needs its own variable $B$, not the $S\to aSb$ pairing.
Asked: [14 marks] (Nov 2023) Construct CFG for (i) $a^nb^mc^n$, $m,n\ge1$ (ii) a integer Asked: [8 marks] (Dec 2024) Show that $L=\{a^nb^nc^n\mid n\ge1\}$ is not a context-free language Asked: [7 marks] (Nov 2019) Prove that the union of two context free languages is context free Asked: [7 marks] (Dec 2020, Jun 2020) Give CFG for R.E. $(011+1)^*(01)^*$ Asked: [7 marks] (Nov 2022) Construct CFG for $L=\{a^{n+2}b^{m+1}\mid n=m\}$ Asked: [7 marks] (Nov 2022) Show that $L=\{a^ib^{2i}a^i\mid i\ge0\}$ is not context free Asked: [7 marks] (Nov 2023) Define CFG in 4-tuple form for (i) at least two a's (ii) no triple b's Asked: [7 marks] (May 2023) Design a CFG for (i) $a^ib^jc^k$, $i\ne j$ or $j\ne k$ (ii) $a^ib^{2i}$ Asked: [7 marks] (May 2023) Define a context free grammar with example Asked: [7 marks] (Dec 2025) Explain context free grammar and derivation trees
Regular grammar
High weight
Definition. A regular grammar is right-linear (every production $A\to xB$ or $A\to x$, $x\in T^*$) or left-linear ($A\to Bx$ or $A\to x$); it generates exactly the regular languages.
Key points.
- Regular expressions, finite automata and regular grammars are equivalent in power.
- To build a grammar from a regular expression, give each sub-expression a variable and use one rule per operator.
- For $\emptyset$ add no production, for $\varepsilon$ add $S\to\varepsilon$, and for a symbol $a$ add $S\to a$.
- Union $r_1+r_2$: $S\to S_1\mid S_2$.
- Concatenation $r_1r_2$: in $G_1$ replace each terminating $A\to x$ by $A\to xS_2$.
- Star $r_1^*$: $S\to S_1\mid\varepsilon$ and each terminating $A\to x$ becomes $A\to xS$.
- Example $a(a+b)^*$: $S\to aA$, $A\to aA\mid bA\mid\varepsilon$; each rule mirrors one operator, so the grammar generates exactly $L(r)$.
Identify the language. $B\to b^n$ ($n\ge1$), so $A\to a\mid b^n$ and $S\to Aa$ gives $aa$ or $b^na$: $L=\{aa\}\cup\{b^na\mid n\ge1\}$.
Exactly one $a$, at most two $b$'s. Strings: $a,ab,abb,ba,bab,bba$. $S\to aQ\mid bP$, $P\to aR\mid bU$, $U\to a$, $Q\to bR\mid\varepsilon$, $R\to b\mid\varepsilon$ ($P,U$ = one, two $b$'s before the $a$; $Q,R$ = zero, one after).
A regular grammar has only right-linear (or only left-linear) productions and equals a regular expression in power.
Answer frame. For RE to grammar: open with the equivalence, state the rules for union, concatenation and star, work $a(a+b)^*$, close with correctness. For design: list the strings, name a variable per stage, write productions, check two strings.
Asked: [7 marks] (Dec 2020, Jun 2020) How can we construct regular grammar from regular expression? Explain Asked: [7 marks] (Nov 2022) Identify the language generated by $G=(\{S,A,B\},\{a,b\},\{S\to Aa,A\to a\mid B,B\to bB\mid b\},S)$ Asked: [7 marks] (Nov 2022) Find a regular grammar for strings on $\{a,b\}$ with exactly one $a$ and no more than two $b$'s
Derivation trees
High weight
Definition. A derivation (parse) tree has root $S$, an interior node for each variable expanded by a production, its children the right side in order, and leaves (left to right) forming the derived string, the yield.
Key points.
- A leftmost derivation always expands the leftmost variable, and a rightmost derivation the rightmost variable.
- Every string of a CFG has a parse tree, and a leftmost and a rightmost derivation for each tree.
- Different derivation orders of one tree give the same tree, so only different trees show ambiguity.
Example. $S\to aSb\mid ab$ for $aabb$: $S\Rightarrow aSb\Rightarrow aabb$ (leftmost and rightmost coincide).
List grammar $S\to a\mid\wedge\mid(T)$, $T\to T,S\mid S$. As printed, $(((a,a),\wedge(a)),a)$ is not derivable, since $\wedge(a)$ needs a comma; the intended string is $(((a,a),\wedge,(a)),a)$.
Leftmost:
S=>(T)=>(T,S)=>(S,S)=>((T),S)=>((T,S),S)=>((T,S,S),S)=>((S,S,S),S)
=>(((T),S,S),S)=>(((T,S),S,S),S)=>(((S,S),S,S),S)=>(((a,S),S,S),S)
=>(((a,a),S,S),S)=>(((a,a),^,S),S)=>(((a,a),^,(T)),S)=>(((a,a),^,(S)),S)
=>(((a,a),^,(a)),S)=>(((a,a),^,(a)),a) [^ stands for the wedge]
Rightmost:
S=>(T)=>(T,S)=>(T,a)=>(S,a)=>((T),a)=>((T,S),a)=>((T,(T)),a)=>((T,(S)),a)
=>((T,(a)),a)=>((T,S,(a)),a)=>((T,^,(a)),a)=>((S,^,(a)),a)=>(((T),^,(a)),a)
=>(((T,S),^,(a)),a)=>(((T,a),^,(a)),a)=>(((S,a),^,(a)),a)=>(((a,a),^,(a)),a)
A leftmost derivation expands the leftmost variable at every step and a rightmost derivation the rightmost.
Answer frame. For leftmost/rightmost: define both, give $E\to E+E\mid id$ style grammar with a short string, write both derivations, draw the tree. For a given string: write productions used, the derivation line by line, then the tree with root $S$, closing with the yield.
Asked: [7 marks] (Dec 2024, Dec 2025) For the grammar $S\to aSb\mid ab$, derive "aabb" and draw its parse tree Asked: [7 marks] (Jun 2020) What are leftmost and rightmost derivations? Explain with suitable example Asked: [6 marks] (Dec 2024) For $S\to a/\wedge/(T)$, $T\to T,S/S$ find leftmost derivation, rightmost derivation and parse tree for $(((a,a),\wedge(a)),a)$
Ambiguity in grammar
High weight
Definition. A CFG is ambiguous if some string in $L(G)$ has two or more distinct parse trees, equivalently two distinct leftmost derivations.
Key points.
- Ambiguity is a property of the grammar, not the language, since another grammar for the same language may be unambiguous.
- To prove ambiguity, pick one string and show two different trees or two different leftmost derivations.
- To show unambiguity you must argue every string has one tree; there is no general algorithm to decide it.
- Ambiguity is harmful because the tree fixes the meaning: $id+id*id$ could mean $(id+id)*id$.
- Remedy one: rewrite to force precedence, with higher-precedence operators at lower levels.
- Remedy two: force associativity by recursing only on the side of the operator, e.g. left recursion for left-associative.
- Remedy three: choose one rule (e.g. dangling else binds to the nearest if).
- Some languages are inherently ambiguous: every grammar for them is ambiguous.
Removal. $E\to E+T\mid T$, $T\to T*F\mid F$, $F\to id\mid(E)$ has one tree for every string, with $*$ binding tighter than $+$.
Show $S\to aSbS\mid bSaS\mid\varepsilon$ ambiguous with $abab$:
1: S=>aSbS=>abS=>abaSbS=>ababS=>abab (first S -> e, second S -> aSbS)
2: S=>aSbS=>abSaSbS=>abaSbS=>ababS=>abab (first S -> bSaS, inner S -> e)
Two different leftmost derivations of $abab$ (two parse trees), so the grammar is ambiguous.
Test $S\to SS\mid a\mid b$ with $aab$: $S\Rightarrow SS\Rightarrow SSS\Rightarrow aSS\Rightarrow aaS\Rightarrow aab$ (tree $(aa)b$) and $S\Rightarrow SS\Rightarrow aS\Rightarrow aSS\Rightarrow aaS\Rightarrow aab$ (tree $a(ab)$). Two trees, so ambiguous.
A grammar is ambiguous if one string has two different parse trees or two different leftmost derivations.
Answer frame. Open with the definition; give $E\to E+E\mid E*E\mid id$, draw the two trees for $id+id*id$; then explain the remedies precedence, associativity, rewriting, in that order; close with the unambiguous grammar. For "show ambiguous" give definition, string, two derivations, conclusion.
Asked: [7 marks] (Dec 2020, Jun 2020) Show that $S\to aSbS\mid bSaS\mid\epsilon$ is ambiguous Asked: [7 marks] (Nov 2023) What is meant by ambiguous grammar? Test whether $S\to SS/a/b$ is ambiguous Asked: [7 marks] (May 2023) What is Ambiguity? Explain taking any two examples Asked: [7 marks] (Dec 2025, Jun 2025) Explain ambiguity in grammar and methods to remove it Asked: [7 marks] (Jun 2025) Explain ambiguity in context-free grammars with an example. How can it be resolved?
Simplification of context free grammar
Medium weight
Definition. Simplifying a CFG removes useless symbols, null productions and unit productions without changing the language (apart from $\varepsilon$).
Key points.
- A symbol is generating if it derives a terminal string, and reachable if it appears in a sentential form derived from $S$.
- Useless symbols are non-generating or unreachable, and are removed with their productions.
- Remove non-generating symbols first, then unreachable ones; the reverse order can leave junk.
- Null and unit productions are then removed (next topics).
Solved. $S\to AB\mid Ca$, $B\to BC\mid AB$, $A\to a$, $C\to aB\mid b$. Generating: $A$ ($a$), $C$ ($b$), $S$ ($Ca$); $B$ never ends, so drop $B$: $S\to Ca$, $A\to a$, $C\to b$. Reachable from $S$: $S,C$; drop $A$. Result: $S\to Ca$, $C\to b$.
Solved. $S\to AC\mid B$, $A\to a$, $C\to c\mid BC$, $E\to aA\mid e$. $B$ has no production so it is non-generating: $S\to AC$, $C\to c$. $E$ is unreachable, so its null rule $E\to e$ goes with it; the unit $S\to B$ went with $B$. Result: $S\to AC$, $A\to a$, $C\to c$.
Remove non-generating symbols first and unreachable symbols second to get a reduced grammar.
Answer frame. Open with generating and reachable; list the generating set, delete, list the reachable set, delete; close with the reduced grammar and its language.
Asked: [7 marks] (Nov 2023, Dec 2024) Find the CFG with no useless symbols equivalent to $S\to AB/Ca$, $B\to BC/AB$, $A\to a$, $C\to aB/b$ Asked: [8 marks] (Dec 2024) Find a reduced grammar for $P:\{S\to AC/B, A\to a, C\to c/BC, E\to aA/e\}$
Conversion of grammar to automata machine and vice versa
Low weight
Definition. A right-linear grammar and a finite automaton are interconvertible: variables become states and each production becomes a transition.
Key points.
- Grammar to NFA (right-linear): $A\to aB$ gives $A\xrightarrow{a}B$, and $A\to a$ gives a move to a final state.
- Automaton to grammar: for each $\delta(p,a)=q$ write $p\to aq$, and for each final $f$ write $f\to\varepsilon$.
- A left-linear grammar is handled directly: $A\to Bx$ is $B\xrightarrow{x}A$, $A\to x$ is $q_0\xrightarrow{x}A$, and $S$ is final.
Solved. $S\to Ab\mid ab$, $A\to Ab\mid Bb$, $B\to Ba\mid a$ is left-linear; $P$ splits $ab$.
| From | on a | on b |
|---|---|---|
| $q_0$ (start) | $B$, $P$ | none |
| $B$ | $B$ | $A$ |
| $P$ | none | $S$ |
| $A$ | none | $A$, $S$ |
| $S$ (final) | none | none |
Accepts $ab$ and $a^mb^n$ with $m\ge1$, $n\ge2$.
Right-linear productions map to NFA transitions, one production per move.
Asked: [7 marks] (Dec 2020) Construct NFA for the grammar $S\to Ab/ab$, $A\to Ab/Bb$, $B\to Ba/a$
Chomsky hierarchy of grammar
Low weight
Definition. The Chomsky hierarchy orders grammars into four classes, each properly inside the previous, each with a matching machine.
| Type | Grammar | Rule form | Automaton | Example |
|---|---|---|---|---|
| 0 | Unrestricted | $\alpha\to\beta$, $\alpha$ has a variable | Turing machine | halting-problem languages |
| 1 | Context sensitive | $\lvert\alpha\rvert\le\lvert\beta\rvert$ | Linear bounded automaton | $a^nb^nc^n$ |
| 2 | Context free | $A\to\alpha$ | Pushdown automaton | $a^nb^n$ |
| 3 | Regular | $A\to aB\mid a$ | Finite automaton | $a^*b^*$ |
Type 0, 1, 2, 3 are accepted by TM, LBA, PDA and FA, each class inside the one above.
Asked: [8 marks] (Dec 2024) Discuss the Chomsky hierarchy of languages with their grammar constraints and corresponding automata
Killing null and unit productions
Not asked since 2022
Definition. A null production is $A\to\varepsilon$ and a unit production is $A\to B$ with $B$ a variable.
Key points.
- Null removal: find nullable variables ($A\Rightarrow^*\varepsilon$), then for each rule add every copy with nullable symbols omitted and delete $A\to\varepsilon$.
- Unit removal: for each $A\to B$ and each non-unit rule $B\to\alpha$, add $A\to\alpha$, then delete all unit rules.
- Do null first, then unit, then useless symbols; $\varepsilon$ itself cannot be kept unless $S\to\varepsilon$ is retained.
Remove null productions first, then unit productions, then useless symbols.
Chomsky normal form
High weight
Definition. A CFG is in CNF if every production is $A\to BC$ (two variables) or $A\to a$ (one terminal), with $\varepsilon$ excluded.
Key points.
- Every CFL without $\varepsilon$ has a CNF grammar.
- Steps: remove null productions, remove unit productions, remove useless symbols, replace terminals in long rules by new variables, and break rules longer than two variables.
- A CNF derivation of a length-$n$ string takes $2n-1$ steps, and its parse trees are binary.
Solved. $S\to ABA$, $A\to aA\mid\varepsilon$, $B\to bB\mid\varepsilon$.
- Nullable: $A,B,S$. Drop nulls: $S\to ABA\mid AB\mid BA\mid AA\mid A\mid B$, $A\to aA\mid a$, $B\to bB\mid b$.
- Units $S\to A\mid B$ replaced: $S\to aA\mid a\mid bB\mid b$ added.
- Terminals: $X\to a$, $Y\to b$. Break $ABA$: $D\to BA$.
Result:
S -> AD | AB | BA | AA | XA | YB | a | b
D -> BA
A -> XA | a B -> YB | b X -> a Y -> b
Solved. $S\to aSb\mid SS\mid\varepsilon$: drop null: $S\to aSb\mid SS\mid ab$ ($S\to S$ is discarded). No unit rules. Terminals $X\to a$, $Y\to b$; break $XSY$ with $D\to SY$.
Result: $S\to XD\mid SS\mid XY$, $D\to SY$, $X\to a$, $Y\to b$. For $\varepsilon$ add a new start $S_0\to S\mid\varepsilon$.
CNF allows only rules $A\to BC$ and $A\to a$ (no $\varepsilon$).
Answer frame. Open with the CNF definition; list the five steps in order; apply them one by one on the given grammar, showing the grammar after each step; close with the final table and a note on $\varepsilon$.
Asked: [7 marks] (Nov 2019, Dec 2025, Jun 2025) Find the CNF for $S\to ABA$, $A\to aA\mid\varepsilon$, $B\to bB\mid\varepsilon$ Asked: [7 marks] (Jun 2025) Convert $S\to aSb\mid SS\mid\varepsilon$ to CNF
Greibach normal form
Medium weight
Definition. A CFG is in GNF if every production is $A\to a\alpha$, with terminal $a$ first and $\alpha$ a string of variables.
Key points.
- Every CFL without $\varepsilon$ has a GNF grammar, and each derivation step then produces one terminal.
- Number the variables $A_1,\dots,A_n$ and make every rule $A_i\to A_j\gamma$ satisfy $j>i$ by substitution.
- Left recursion $A\to A\alpha\mid\beta$ is replaced by $A\to\beta\mid\beta Z$, $Z\to\alpha\mid\alpha Z$.
- Back-substitute from the last variable upward so every rule starts with a terminal.
Solved. $A_1\to A_2A_3$, $A_2\to A_3A_1\mid b$, $A_3\to A_1A_2\mid a$ (checked to the same strings up to length 7).
- $A_3\to A_1A_2\Rightarrow A_2A_3A_2\Rightarrow A_3A_1A_3A_2\mid bA_3A_2$, so $A_3\to A_3A_1A_3A_2\mid bA_3A_2\mid a$.
- Remove left recursion: $A_3\to bA_3A_2\mid a\mid bA_3A_2Z\mid aZ$, $Z\to A_1A_3A_2\mid A_1A_3A_2Z$.
- Back-substitute: $A_2\to bA_3A_2A_1\mid aA_1\mid bA_3A_2ZA_1\mid aZA_1\mid b$.
- $A_1\to\alpha A_3$ for each $\alpha$ among those five $A_2$ rules, and $Z\to\alpha A_3A_3A_2\mid\alpha A_3A_3A_2Z$ for the same five $\alpha$.
Solved. $S\to AB$, $A\to BS\mid b$, $B\to SA\mid a$ with $S,A,B$ as 1, 2, 3.
- $B\to SA\Rightarrow ABA\Rightarrow BSBA\mid bBA$, so $B\to BSBA\mid bBA\mid a$; remove left recursion: $B\to bBA\mid a\mid bBAZ\mid aZ$, $Z\to SBA\mid SBAZ$.
- $A\to bBAS\mid aS\mid bBAZS\mid aZS\mid b$.
- $S\to\gamma$ for each $\gamma=\alpha B$ with $\alpha$ among those five $A$ rules, so $S\to bBASB\mid aSB\mid bBAZSB\mid aZSB\mid bB$; $Z\to\gamma BA\mid\gamma BAZ$ for the same five $\gamma$.
GNF makes every production start with one terminal followed only by variables.
Answer frame. Open with the definition; state the ordering rule $A_i\to A_j\gamma$, $j>i$; substitute, remove left recursion with $Z$, back-substitute; close by listing every rule and noting it starts with a terminal.
Asked: [7 marks] (Nov 2019, Dec 2024) Convert $A_1\to A_2A_3$, $A_2\to A_3A_1\mid b$, $A_3\to A_1A_2\mid a$ to GNF Asked: [6 marks] (Dec 2024) Convert $S\to AB$, $A\to BS/b$, $B\to SA/a$ into GNF
Last-minute revision
- CFG is $(V,T,P,S)$ with every rule $A\to\alpha$; regular grammar is right- or left-linear only.
- Chomsky types 0, 1, 2, 3 match TM, LBA, PDA, FA.
- Union of CFLs: new start $S\to S_1\mid S_2$; CFLs are not closed under intersection.
- Pumping lemma for CFL: $z=uvwxy$, $|vwx|\le p$, $|vx|\ge1$, $uv^iwx^iy\in L$; use $a^pb^pc^p$.
- Leftmost expands the leftmost variable; rightmost the rightmost; the tree yield is the string.
- Ambiguous means one string, two trees; fix by precedence layering, associativity, rewriting.
- $S\to SS\mid a\mid b$ and $S\to aSbS\mid bSaS\mid\varepsilon$ are ambiguous, shown with $aab$ and $abab$.
- Reduce a grammar: remove non-generating, then unreachable, then null, then unit symbols.
- CNF is $A\to BC\mid a$; GNF is $A\to a\alpha$.
- CNF of $S\to ABA$ gives $S\to AD\mid AB\mid BA\mid AA\mid XA\mid YB\mid a\mid b$.
- Left recursion $A\to A\alpha\mid\beta$ becomes $A\to\beta\mid\beta Z$, $Z\to\alpha\mid\alpha Z$.
Memory hooks
- Types 0 to 3: Turing, Linear bounded, Pushdown, Finite (TLPF).
- Ambiguity is two maps for one place: two trees for one string.
- Reduction order: Generate, then Reach.
- Simplify order: Null, Unit, Useless (N-U-U).
Coverage checklist
- Types of grammar: no past questions; covered.
- context sensitive grammar: no past questions; covered.
- context free grammar: CFG designs, 4-tuple definitions, union proof, two pumping-lemma proofs, R.E. to CFG, definition with derivation trees.
- regular grammar: RE to grammar, identify the language, one a and at most two b's.
- Derivation trees: aabb tree, leftmost and rightmost, list grammar.
- ambiguity in grammar: $aSbS$, $SS$, two examples, removal.
- simplification of context free grammar: two useless-symbol questions.
- conversion of grammar to automata machine and vice versa: NFA for the left-linear grammar.
- Chomsky hierarchy of grammar: hierarchy table.
- killing null and unit productions: no past questions; covered.
- Chomsky normal form: $S\to ABA$ and $S\to aSb\mid SS\mid\varepsilon$.
- Greibach normal form: both GNF conversions.