Jeremy Siek 2 سال پیش
والد
کامیت
82ea89bf53
1فایلهای تغییر یافته به همراه14 افزوده شده و 6 حذف شده
  1. 14 6
      book.tex

+ 14 - 6
book.tex

@@ -4346,7 +4346,7 @@ lang_int: (stmt NEWLINE)*   -> module
 \end{lstlisting}
 \end{minipage}
 \end{center}
-The resulting parse tree 
+Here is the resulting parse tree. 
 \begin{lstlisting}
 Tree('module',
   [Tree('expr', [Tree('add', [Tree('int', [Token('INT', '1')]),
@@ -4356,11 +4356,13 @@ Tree('module',
 
 \subsection{Ambiguous Grammars}
 
-A grammar is \emph{ambiguous}\index{subject}{ambiguous} when there are
-strings that can be parsed in more than one way. For example, consider
-the string \code{'1-2+3'}.  This string can parsed in two different
-ways using our draft grammar, resulting in the two parse trees shown
-in figure~\ref{fig:ambig-parse-tree}.
+A grammar is \emph{ambiguous}\index{subject}{ambiguous} when a string
+can be parsed in more than one way. For example, consider the string
+\code{'1-2+3'}.  This string can parsed in two different ways using
+our draft grammar, resulting in the two parse trees shown in
+figure~\ref{fig:ambig-parse-tree}. This example is problematic because
+interpreting the second parse tree would yield \code{-4} even through
+the correct answer is \code{2}.
 
 \begin{figure}[tbp]
 \begin{tcolorbox}[colback=white]
@@ -4371,6 +4373,12 @@ in figure~\ref{fig:ambig-parse-tree}.
 \label{fig:ambig-parse-tree}
 \end{figure}
 
+To deal with this problem we can change the grammar to become
+unambiguous by categorizing the syntax in a more fine grained
+fashion. In this case we want to disallow the application of the rule
+\code{exp: exp "-" exp} when the child on the right is an addition.
+
+