Commit 89ad7a67 authored by POTTIER Francois's avatar POTTIER Francois

Documented on-error-reduce priorities.

parent b3c88513
......@@ -557,24 +557,29 @@ A declaration of the form:
\end{quote}
marks the nonterminal symbols $\nt{lid}_1, \ldots, \nt{lid}_n$ as
potentially eligible for reduction when an invalid token is found.
This may cause one or more extra reduction steps to be performed
before the error is detected.
More precisely, this declaration affects the automaton as follows. Let us say
that a production $\nt{lid} \rightarrow \ldots$ is ``reducible on error'' if
its left-hand symbol~\nt{lid} appears in a \donerrorreduce declaration. After
the automaton has been constructed and after any conflicts have been resolved,
in every state~$s$, the following rule is applied:
\begin{quote}
If the set of all productions that are ready to be reduced in state~$s$ and
are reducible on error is a singleton set $\{ p \}$, then in state~$s$ every
error action is replaced with a reduction of the production~$p$.
\end{quote}
In other words, for every terminal symbol~$t$, if the automaton's action table
in every state~$s$, the following algorithm is applied:
\begin{enumerate}
\item Construct the set of all productions that are ready to be reduced in
state~$s$ and are reducible on error;
\item Test if one of them, say $p$, has higher ``on-error-reduce-priority''
than every other production in this set;
\item If so, in state~$s$, replace every error action with a reduction of the
production~$p$.
(In other words, for every terminal symbol~$t$, if the action table
says: ``in state~$s$, when the next input symbol is~$t$, fail'', then this
table entry is replaced with: ``in state~$s$, when the next input symbol
is~$t$, reduce production~$p$''.
entry is replaced with: ``in state~$s$, when the next input symbol
is~$t$, reduce production~$p$''.)
\end{enumerate}
If this rule fires in state~$s$, then an error can never be detected in
state~$s$, since all error actions in state~$s$ are replaced with reduce
If step 3 above is executed in state~$s$, then an error can never be detected
in state~$s$, since all error actions in state~$s$ are replaced with reduce
actions. Error detection is deferred: at least one reduction takes place
before the error is detected. It is a ``spurious'' reduction: in a canonical
LR(1) automaton, it would not take place.
......@@ -594,6 +599,15 @@ a nonterminal symbol, such as, say, \texttt{expression}, but also a fully
applied parameterized nonterminal symbol, such as \texttt{list(expression)} or
\texttt{separated\_list(COMMA, option(expression))}.
The ``on-error-reduce-priority'' of a production is that of its left-hand
symbol. The ``on-error-reduce-priority'' of a nonterminal symbol is determined
implicitly by the order of \donerrorreduce declarations. In the declaration
$\donerrorreduce\;\nt{lid}_1 \ldots \nt{lid}_n$, the symbols $\nt{lid}_1, \ldots,
\nt{lid}_n$ have the same ``on-error-reduce-priority''. They have higher
``on-error-reduce-priority'' than the symbols listed in previous
\donerrorreduce declarations, and lower ``on-error-reduce-priority''
than those listed in later \donerrorreduce declarations.
\subsection{Rules}
Following the mandatory \percentpercent keyword, a sequence of rules is
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment