# Today I Learned

Some of the things I've learned every day since Oct 10, 2016

## 15: Context-Free Grammars

context-free grammar is a formal grammar in which the rewrite rules (or ‘productions’) of the grammar are all from single variables. That is, as implied in the name, the rewrite rules of a given variable in a context-free grammar are dependent only on that variable and not on any other ‘context’.

Example:

This is a valid subset of rewrite rules in a context-free grammar

$X \rightarrow a$

$Y \rightarrow ab$

while this is not

$X \rightarrow a$

$Y \rightarrow ab$

$XY \rightarrow c$

The violation of freedom-from-context in the latter example is due to the last rule, where the thing being rewritten is not a single variable.

Advertisements