handouts/ho04.tex
changeset 490 4fee50f38305
parent 444 3056a4c071b0
child 492 39b7ff2cf1bc
equal deleted inserted replaced
489:e28d7a327870 490:4fee50f38305
    89 shown below. I have in my implementation the convention that
    89 shown below. I have in my implementation the convention that
    90 regular expressions are written entirely with upper-case
    90 regular expressions are written entirely with upper-case
    91 letters, while values just start with a single upper-case
    91 letters, while values just start with a single upper-case
    92 character and the rest are lower-case letters.
    92 character and the rest are lower-case letters.
    93  
    93  
    94 {\small\lstinputlisting[language=Scala,numbers=none]
    94 {\small\lstinputlisting[language=Scala,numbers=none,linebackgroundcolor=
       
    95                   {\ifodd\value{lstnumber}\color{capri!3}\fi}]
    95 {../progs/app01.scala}}
    96 {../progs/app01.scala}}
    96 
    97 
    97  
    98  
    98 {\small\lstinputlisting[language=Scala,numbers=none]
    99 {\small\lstinputlisting[language=Scala,numbers=none,linebackgroundcolor=
       
   100                   {\ifodd\value{lstnumber}\color{capri!3}\fi}]
    99 {../progs/app02.scala}}
   101 {../progs/app02.scala}}
   100 
   102 
   101 
   103 
   102 Graphically the algorithm by Sulzmann \& Lu can be illustrated
   104 Graphically the algorithm by Sulzmann \& Lu can be illustrated
   103 by the picture in Figure~\ref{Sulz} where the path from the
   105 by the picture in Figure~\ref{Sulz} where the path from the
   578 \caption{The simplification function that returns a simplified 
   580 \caption{The simplification function that returns a simplified 
   579 regular expression and a rectification function.\label{simp}}
   581 regular expression and a rectification function.\label{simp}}
   580 \end{figure}
   582 \end{figure}
   581 
   583 
   582 \begin{figure}[p]
   584 \begin{figure}[p]
   583 \lstinputlisting{../progs/app61.scala}
   585 \lstinputlisting[numbers=left,linebackgroundcolor=
       
   586    {\ifodd\value{lstnumber}\color{capri!3}\fi}]{../progs/app61.scala}
   584 
   587 
   585 \caption{The Scala code for the simplification function. The
   588 \caption{The Scala code for the simplification function. The
   586 first part defines some auxillary functions for the rectification.
   589 first part defines some auxillary functions for the rectification.
   587 The second part give the simplification function.
   590 The second part give the simplification function.
   588 \label{simprect}}
   591 \label{simprect}}
   637 $(x:r)$, where $x$ is just an identifier (in my implementation
   640 $(x:r)$, where $x$ is just an identifier (in my implementation
   638 a plain string) and $r$ is a regular expression. A record will
   641 a plain string) and $r$ is a regular expression. A record will
   639 be regarded as a regular expression. The extended definition
   642 be regarded as a regular expression. The extended definition
   640 in Scala therefore looks as follows:
   643 in Scala therefore looks as follows:
   641 
   644 
   642 {\small\lstinputlisting[language=Scala]
   645 {\small\lstinputlisting[language=Scala, numbers=none,linebackgroundcolor=
       
   646                   {\ifodd\value{lstnumber}\color{capri!3}\fi}]
   643 {../progs/app03.scala}}
   647 {../progs/app03.scala}}
   644 
   648 
   645 \noindent Since we regard records as regular expressions we
   649 \noindent Since we regard records as regular expressions we
   646 need to extend the functions $\textit{nullable}$ and $\textit{der}$. Similarly
   650 need to extend the functions $\textit{nullable}$ and $\textit{der}$. Similarly
   647 $\textit{mkeps}$ and $\textit{inj}$ need to be extended. This means we also need
   651 $\textit{mkeps}$ and $\textit{inj}$ need to be extended. This means we also need
   648 to extend the definition of values, which in Scala looks as
   652 to extend the definition of values, which in Scala looks as
   649 follows:
   653 follows:
   650 
   654 
   651 {\small\lstinputlisting[language=Scala]
   655 {\small\lstinputlisting[language=Scala, numbers=none,linebackgroundcolor=
       
   656                   {\ifodd\value{lstnumber}\color{capri!3}\fi}]
   652 {../progs/app04.scala}}
   657 {../progs/app04.scala}}
   653 
   658 
   654 \noindent Let us now look at the purpose of records more
   659 \noindent Let us now look at the purpose of records more
   655 closely and let us return to our question whether the string
   660 closely and let us return to our question whether the string
   656 terminated in a $b$ or $c$. We can do this as follows: we
   661 terminated in a $b$ or $c$. We can do this as follows: we