hw08.tex
author Christian Urban <christian dot urban at kcl dot ac dot uk>
Sat, 24 Nov 2012 15:10:43 +0000
changeset 79 fd894e017e12
parent 77 49c0beef79a1
permissions -rw-r--r--
added
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
59
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     1
\documentclass{article}
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     2
\usepackage{charter}
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     3
\usepackage{hyperref}
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     4
\usepackage{amssymb}
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     5
\usepackage{amsmath}
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     6
\usepackage{tikz}
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     7
\usetikzlibrary{automata}
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     8
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     9
\newcommand{\dn}{\stackrel{\mbox{\scriptsize def}}{=}}% for definitions
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    10
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    11
\begin{document}
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    12
75
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 60
diff changeset
    13
\section*{Homework 8}
59
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    14
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    15
\begin{enumerate}
75
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 60
diff changeset
    16
\item Suppose the following grammar for the WHILE-language:
59
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    17
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    18
\begin{center}
76
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 75
diff changeset
    19
\begin{tabular}{lcl}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 75
diff changeset
    20
$Stmt$ & $\rightarrow$ &  $\text{skip}$\\
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 75
diff changeset
    21
              & $|$ & $Id := AExp$\\
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 75
diff changeset
    22
              & $|$ & $\text{if}\; B\!Exp \;\text{then}\; Block \;\text{else}\; Block$\\
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 75
diff changeset
    23
              & $|$ & $\text{while}\; B\!Exp \;\text{do}\; Block$\medskip\\
77
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 76
diff changeset
    24
$Stmts$ & $\rightarrow$ &  $Stmt \;\text{;}\; Stmts$\\
76
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 75
diff changeset
    25
              & $|$ & $Stmt$\medskip\\
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 75
diff changeset
    26
$Block$ & $\rightarrow$ &  $\{ Stmts \}$\\
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 75
diff changeset
    27
                & $|$ & $Stmt$\medskip\\
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 75
diff changeset
    28
$AExp$ & $\rightarrow$ & $AExp + AExp$\\
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 75
diff changeset
    29
               & $|$ & $AExp * AExp$\\
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 75
diff changeset
    30
               & $|$ & $( AExp )$\\
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 75
diff changeset
    31
                & $|$ & $Num$\\
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 75
diff changeset
    32
                & $|$ & $Id$\medskip\\
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 75
diff changeset
    33
$BExp$ & $\rightarrow$ & $AExp = AExp$\\
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 75
diff changeset
    34
                 & $|$ & $AExp \not= AExp$\\
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 75
diff changeset
    35
                  & $|$ & $\text{false}$\\
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 75
diff changeset
    36
                  & $|$ & $\text{true}$\\
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 75
diff changeset
    37
75
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 60
diff changeset
    38
\end{tabular}
59
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    39
\end{center}
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    40
76
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 75
diff changeset
    41
Transform this grammar into Chomsky normalform.
59
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    42
77
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 76
diff changeset
    43
\item Write a program in the WHILE-language that calculates the factorial function.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 76
diff changeset
    44
59
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    45
\end{enumerate}
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    46
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    47
\end{document}
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    48
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    49
%%% Local Variables: 
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    50
%%% mode: latex
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    51
%%% TeX-master: t
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    52
%%% End: