Skip to content
20 changes: 17 additions & 3 deletions chapters/syntax.tex
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,7 @@ \subsection{Modification}\label{modification}


\subsection{Equations}\label{equations1}
See below for how to rewrite rules \lstinline[language=grammar]!equation-or-procedure! and \lstinline[language=grammar]!statement-or-procedure! for recursive descent parsers.

\begin{lstlisting}[language=grammar]
equation-section :
Expand All @@ -267,17 +268,20 @@ \subsection{Equations}\label{equations1}
[ initial ] algorithm { statement ";" }

some-equation :
( simple-expression "=" expression
( equation-or-procedure
| if-equation
| for-equation
| connect-equation
| when-equation
| component-reference function-call-args
)
description

equation-or-procedure :
simple-expression "=" expression
| component-reference function-call-args

statement :
( component-reference ( ":=" expression | function-call-args )
( statement-or-procedure
| "(" output-expression-list ")" ":="
component-reference function-call-args
| break
Expand All @@ -289,6 +293,10 @@ \subsection{Equations}\label{equations1}
)
description

statement-or-procedure :
component-reference ":=" expression
| component-reference function-call-args

if-equation :
if expression then
{ some-equation ";" }
Expand Down Expand Up @@ -352,6 +360,12 @@ \subsection{Equations}\label{equations1}
connect "(" component-reference "," component-reference ")"
\end{lstlisting}

\begin{nonnormative}
The productions \lstinline[language=grammar]!equation-or-procedure! and \lstinline[language=grammar]!statement-or-procedure! are not suitable for recursive descent parsers.

A work-around is to left-factor them and for \lstinline[language=grammar]!equation-or-procedure! introduce semantic checks to ensure that only the grammar above is accepted.
\end{nonnormative}

\subsection{Expressions}\label{expressions1}

\begin{lstlisting}[language=grammar]
Expand Down