src/Doc/ProgProve/Logic.thy
changeset 54218 07c0c121a8dc
parent 54217 2fa338fd0a28
child 54231 2975658d49cd
--- a/src/Doc/ProgProve/Logic.thy	Wed Oct 30 17:20:59 2013 +0100
+++ b/src/Doc/ProgProve/Logic.thy	Thu Oct 31 11:48:45 2013 +0100
@@ -805,6 +805,29 @@
 if the assumption about the inductive predicate is not the first assumption.
 \endexercise
 
+\begin{exercise}
+A context-free grammar can be seen as an inductive definition where each
+nonterminal $A$ is an inductively defined predicate on lists of terminal
+symbols: $A(w)$ mans that $w$ is in the language generated by $A$.
+For example, the production $S \to a S b$ can be viewed as the implication
+@{prop"S w \<Longrightarrow> S (a # w @ [b])"} where @{text a} and @{text b} are terminal symbols,
+i.e., elements of some alphabet. The alphabet can be defined like this:
+\isacom{datatype} @{text"alpha = a | b | \<dots>"}
+
+Define the two grammars (where $\varepsilon$ is the empty word)
+\[
+\begin{array}{r@ {\quad}c@ {\quad}l}
+S &\to& \varepsilon \quad\mid\quad aSb \quad\mid\quad SS \\
+T &\to& \varepsilon \quad\mid\quad TaTb
+\end{array}
+\]
+as two inductive predicates.
+If you think of @{text a} and @{text b} as ``@{text "("}'' and  ``@{text ")"}'',
+the grammars defines strings of balanced parentheses.
+Prove @{prop"T w \<Longrightarrow> S w"} and @{prop "S w \<Longrightarrow> T w"} separately and conclude
+@{prop "S w = T w"}.
+\end{exercise}
+
 \ifsem
 \begin{exercise}
 In \autoref{sec:AExp} we defined a recursive evaluation function