# Choosing a production with $\lambda$ in Context-Free Grammars

Given the context-free grammar

\begin{align*} & S \rightarrow AA \\ & A \rightarrow xA \\ & A \rightarrow B \\ & B \rightarrow yB \\ & B \rightarrow \lambda \end{align*} What is the meaning of $\lambda$? $\lambda$ itself means the empty string and will match anything without consuming it, but in terms of the productions, how do you know which one to use? Do you use the last $B$ production only if $B \mapsto yB$ cannot be used? Or can both be used interchangably?

For example, parsing the string $xyy$ could give two different results:

Is there a formal way to prefer one of the two possible options? Which one is the "default"?

• A context-free grammar defines a language. A word is in the language if it can be produced using the productions of the grammar. You are free to use whichever productions you want. It is meaningless to ask "how do you know which one to use". The language is formed by trying all possibilities. – Yuval Filmus Feb 20 '17 at 19:50