# HG changeset patch # User Christian Urban # Date 1383321377 0 # Node ID 3c2653fc8b5a95a2f000e472e37c11c5688e4ea7 # Parent 5801e8c0e528f0758cb0bb9a1e737a9722045abe updated diff -r 5801e8c0e528 -r 3c2653fc8b5a handouts/ho06.pdf Binary file handouts/ho06.pdf has changed diff -r 5801e8c0e528 -r 3c2653fc8b5a handouts/ho06.tex --- a/handouts/ho06.tex Fri Nov 01 13:16:43 2013 +0000 +++ b/handouts/ho06.tex Fri Nov 01 15:56:17 2013 +0000 @@ -288,13 +288,31 @@ \noindent In particular in programming languages we will try to avoid ambiguous -grammars as two different parse-trees for a string means a program can -be interpreted in two different ways. Then we have to somehow make sure +grammars because two different parse-trees for a string mean a program can +be interpreted in two different ways. In such cases we have to somehow make sure the two different ways do not matter, or disambiguate the grammar in some way (for example making the $+$ left-associative). Unfortunately already the problem of deciding whether a grammar -is ambiguous or not is in general undecidable. But in concrete instances we can -often make a choice. +is ambiguous or not is in general undecidable. + +Let us now turn to the problem of generating a parse-tree for a grammar and string. +In what follows we explain \emph{parser combinators}, because they are easy +to implement and closely resemble grammar rules. Imagine that a grammar +describes the strings of natural numbers, such as the grammar $N$ shown above. +For all such strings we want to generate the parse-trees or later on we actually +want to extract the meaning of these strings, that is the integers ``behind'' these +strings. The parser will therefore be functions of type + +\begin{center} +\texttt{I $\Rightarrow$ (T, I)} +\end{center} + +\noindent +that is they take as input something of type \texttt{I}, typically a list of token or a string, +and return a pair. + + + \end{document}