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


\subsection{Equations}\label{equations1}

See below for how to rewrite two rules for recursive descent parsers.
\begin{lstlisting}[language=grammar]
equation-section :
[ initial ] equation { some-equation ";" }
Expand All @@ -267,17 +267,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 +292,10 @@ \subsection{Equations}\label{equations1}
)
description

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

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

\begin{nonnormative}
The given constructs equation-or-procedure and statement-or-procedure are not suitable for recursive descent parsers.

A work-around is to use the following syntax with semantic checks to ensure that only the grammar above is accepted.

\begin{lstlisting}[language=grammar]
equation-or-procedure :
simple-expression ( "=" expression | function-call-args )

statement-or-procedure :
component-reference ( ":=" expression | function-call-args )
\end{lstlisting}
\end{nonnormative}

\subsection{Expressions}\label{expressions1}

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