Skip to main content

11. Transformations of CFG

Expression is open or closed

SS0SCS \to S_0 | S_C S0if(E)Sif(E)ScelseS0S _0 \to if (E)S | if (E) S_c else S_0 ScSsif(E)ScelseScS_c\to S_s | if(E)S_c else S_c

Transformation of CFG

L(Gn)=L(G2)L(G_n) = L(G_2) Removal of useless pro...

SaABbS\to aAB | b AaAaA\to aA | a BBbB\to Bb

X:NX:N .....

BB is non-productive AA is unreachable

Substitution

AXBYA \to XBY BCDϵB \to C|D|\epsilon

AXCYXDYXYA\to XCY | XDY | XY

Eliminating left recursion

AAabA \to Aa|b XX is left-recursive, if X=>XxX =>* Xx AbAA\to bA' A>aAϵA' -> aA'\epsilon

SABS\to A | B AABcAAdaaaA \to ABc | AAd | a | aa

BBccbB\to Bcc | b

AaAaaAA\to aA' | aaA' ABcAAdAϵA' \to BcA' | AdA' | \epsilon BbBB\to bB' BccBϵB' \to cc B' | \epsilon

??

ABaBA\to BaB BAbbAcbϵB\to Abb|Acb|\epsilon A=>BaB=>AbbaBA=> BaB => AbbaB