-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy path4-interpretation.tex
80 lines (74 loc) · 3.65 KB
/
4-interpretation.tex
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
\definesection{Interpretation}
This section describes the procedure by which an \g{implementation} \glink{interpretation}{interprets} a \g{document}. This procedure is used as a reference to allow verification of correctness. An \g{implementation} does not necessarily have to follow this procedure as long as the output it produces is equivalent with an \g{implementation} that does.
\definesubsection{State}
The following state is kept and updated as the procedure advances.
\begin{itemize}
\item The input stream from which characters are read.
\item The parser state variables such as the \g{line break mode}.
\item A \g{cursor}.
\item A stack wherein each entry is composed of a \g{directive} and a \g{textual component}.
\item A list of \gpl{disabled directive}.
\item A table associating \gpl{label} to \gpl{textual component}.
\end{itemize}
\definesubsection{Procedure}
\begin{step}
\item A ``root-directive'' and a ``root-component'' are pushed onto the stack.
\item If the input stream has things to read:
\begin{step}
\item A \g{line} is read from the input stream.
\item The \g{cursor} is set to the beginning of the \g{line}.
\item The stack is traversed upwards from the bottom:
\begin{step}
\item The \g{directive} at the current stack entry attempts to \g{match}.
\item If the \g{match} succeeds:
\begin{step}
\item The \g{cursor} is advanced by the \glink{match}{matched} \gpl{character}.
\item The current stack entry is advanced upwards.
\item Go to 2.3.1.
\end{step}
\item The stack is unwound down to and including the current stack entry. See \sectionref{Stack Unwinding}.
\end{step}
\item The \g{directive} on top of the stack is invoked:
\begin{step}
\item If an \g{applicable directive} \glink{match}{matches}:
\begin{step}
\item The \glink{match}{matched} \g{directive} may enter \gpl{textual component} into the \g{current component}.
\item The \glink{match}{matched} \g{directive} may push itself and a \g{textual component} onto the stack or perform other changes to the state as specified.
\item The \g{cursor} is advanced by the \glink{match}{matched} \gpl{character}.
\item Go to 2.4.
\end{step}
\item The \g{character} at the \g{cursor} is added to the \g{current component}.
\item The \g{cursor} is advanced by the \g{character}.
\end{step}
\item If the \g{cursor} is not yet at the end of the \g{line}:
\begin{step}
\item Go to 2.4.
\end{step}
\item If the \g{line break mode} is \inline$show$, a \g{newline} is added to the \g{current component}.
\item Go to 2.
\end{step}
\item The stack is unwound fully. See \sectionref{Stack Unwinding}.
\item The interpretation is complete. The ``root-component'' represents the resulting \g{document}.
\end{step}
\definesubsubsection{Stack Unwinding}
\begin{step}
\item If the stack is taller than the desired height:
\begin{step}
\item If the directive on top of the stack is a \g{inline directive}:
\begin{step}
\item The \g{current component} is converted to one that has no \g{style}.
\item \Gpl{character} that have been consumed by the prefix match of the \g{directive} are prepended to the \g{current component}.
\item Other potentially necessary actions to undo the match of the \g{directive} are performed.
\end{step}
\item The top of the stack is popped off.
\item Go to 1.
\end{step}
\end{step}
\definesubsubsection{Root Directive}
The root directive always \glink{match}{matches} but is never considered an \g{applicable directive}.
%%% Local Variables:
%%% mode: latex
%%% TeX-master: "markless"
%%% TeX-engine: luatex
%%% TeX-command-extra-options: "-shell-escape"
%%% End: