Live Variables in Context Free Grammar

1.5k Views Asked by At

A variable $A$ in a context free grammar $G= \langle V, \Sigma, S, P\rangle$ is live if $A \Rightarrow^* x$ for some $x \in \Sigma^*$. Give a recursive algorithm for finding all live variables in a certain context free grammar.

I don't necessarily need an answer to this. Mostly I am having a very difficult time deciphering what this question is asking. More specifically its definition of live variables.

1

There are 1 best solutions below

0
On

Consider this example:

S → A | B
A → aA | a
B → bB
C → c

This is a grammar for the set of all nonempty strings of a.

The symbol B is not live, because it is never involved in the production of a terminal string; you can generate it from S or from B, but you can never finish the production because you can never get rid of it. So productions involving B are useless, and you can delete from the grammar them without changing the language that is generated:

S → A
A → aA | a
C → c

Another way that a symbol might fail to be live is if there is no way to produce it from the start symbol. C is an example here, and again, productions involving C can be deleted from the grammar without changing the language:

S → A
A → aA | a

Your job is to describe an algorithm that decides which of the symbols in a grammar are live.