Chapter 8 - Transformations of Context-Free Grammars Flashcards

1
Q

What are equivalent grammars?

A

Grammars are equivalent if the languages they represent are exactly equal

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What are useless productions’ properties?

A

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

When removing a useless production, what do you do?

A

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What is substitution in respect to productions?

A

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What is left factoring in respect to productions?

A

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

When making a CFG unambiguous, what does operator precedence mean?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

When eliminating left-recursion, what do you do?

A

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly