Chapter 8 - Transformations of Context-Free Grammars Flashcards
What are equivalent grammars?
Grammars are equivalent if the languages they represent are exactly equal
What are useless productions’ properties?
Unreachable - there is no other production that can reach this one, thereby making it impossible to do anything with
Unproductive - A production that basically gets stuck in an infinite loop i.e. B -> bB
When removing a useless production, what do you do?
Remove it from ALL instances where it is used or ‘called’ i.e.
S -> AB | A
B -> bB
Removing B will result in this:
S -> A
What is substitution in respect to productions?
Substitution is exactly as it sounds, you take a production, and replace its value with the production result i.e. A -> XBY
B -> C | D
After substitution, the result would be this:
A -> XCY | XDY
What is left factoring in respect to productions?
Left factoring involves replacing certain ‘common prefixes’ of a production with another one. To explain with an example:
A -> XYX | XYZZY
After left factoring, the result can look like this:
A -> BYX | BZZY
B -> XY
When making a CFG unambiguous, what does operator precedence mean?
Operator precedence means that for each operator within a production, you have an order of what takes more precedence, instead of just leaving it so that all operators are of the same precedence.
When eliminating left-recursion, what do you do?
Eliminating left recursion requires you to follow a couple of steps. First, select the non-terminal defined by left recursion. Then, split it into A and A’, whereby A looks like this - A -> (beta)A’
And A’ looks like this:
A’ -> (alpha)A’ | epsilon
Example:
A -> A(alpha)
A -> beta
It would then turn into this:
A -> (beta)A’
A’ -> (alpha)A’ | epsilon