handouts/ho04.tex
changeset 721 e3c64f22dd31
parent 720 ecbed0155f72
child 778 3e5f5d19f514
equal deleted inserted replaced
720:ecbed0155f72 721:e3c64f22dd31
   882 $[(name:\texttt{christian.urban}), 
   882 $[(name:\texttt{christian.urban}), 
   883   (domain:\texttt{kcl}), 
   883   (domain:\texttt{kcl}), 
   884   (top\_level:\texttt{ac.uk})]$
   884   (top\_level:\texttt{ac.uk})]$
   885 \end{center}
   885 \end{center}
   886 
   886 
   887 Recall that we want to lex a little programming language,
   887 Recall that we want to lex a little programming language, called the
   888 called the \emph{While}-language. A simple program in this
   888 \emph{While}-language. A simple program in this language is shown in
   889 language is shown in Figure~\ref{while}. The main keywords in
   889 Figure~\ref{while}. The main keywords in this language are
   890 this language are \pcode{while}, \pcode{if}, \pcode{then} and
   890 \pcode{while}, \pcode{if}, \pcode{then} and
   891 \pcode{else}. As usual we have syntactic categories for
   891 \pcode{else}.\footnote{Contrast this with the COBOL programming
   892 identifiers, operators, numbers and so on. For this we would
   892   language, which was developed around 1960 and thought to be dead for
   893 need to design the corresponding regular expressions to
   893   many decades---even your friendly lecturer is not old enough to have
   894 recognise these syntactic categories. I let you do this design
   894   been taught this language. Anyway, this language had over 600
   895 task. Having these regular expressions at our disposal, we can
   895   keywords (or what they called \emph{reserved words}). Interestingly
       
   896   though this language is still used in 2020: during the height of
       
   897   Corona crisis the State of New Jewrsey in the US was looking for
       
   898   COBOL programers who could fix the state's national insurance
       
   899   webpage. You were probably paid in gold and diamonds, if you were
       
   900   able to program in COBOL. If you fixed their webpage, surely you
       
   901   were allowed to marry the governer's son/daughter. } As usual we
       
   902 have syntactic categories for identifiers, operators, numbers and so
       
   903 on. For this we would need to design the corresponding regular
       
   904 expressions to recognise these syntactic categories. I let you do this
       
   905 design task. Having these regular expressions at our disposal, we can
   896 form the regular expression
   906 form the regular expression
   897 
   907 
   898 \begin{figure}[t]
   908 \begin{figure}[t]
   899 \begin{center}
   909 \begin{center}
   900 \mbox{\lstinputlisting[language=while]{../progs/fib.while}}
   910 \mbox{\lstinputlisting[language=while]{../progs/fib.while}}