59
|
1 |
\documentclass{article}
|
|
2 |
\usepackage{charter}
|
|
3 |
\usepackage{hyperref}
|
|
4 |
\usepackage{amssymb}
|
|
5 |
\usepackage{amsmath}
|
|
6 |
\usepackage{tikz}
|
|
7 |
\usetikzlibrary{automata}
|
|
8 |
|
|
9 |
\newcommand{\dn}{\stackrel{\mbox{\scriptsize def}}{=}}% for definitions
|
|
10 |
|
|
11 |
\begin{document}
|
|
12 |
|
75
Christian Urban <christian dot urban at kcl dot ac dot uk>
diff
changeset
|
13 |
\section*{Homework 8}
|
59
|
14 |
|
|
15 |
\begin{enumerate}
|
75
Christian Urban <christian dot urban at kcl dot ac dot uk>
diff
changeset
|
16 |
\item Suppose the following grammar for the WHILE-language:
|
59
|
17 |
|
|
18 |
\begin{center}
|
76
Christian Urban <christian dot urban at kcl dot ac dot uk>
diff
changeset
|
19 |
\begin{tabular}{lcl}
|
Christian Urban <christian dot urban at kcl dot ac dot uk>
diff
changeset
|
20 |
$Stmt$ & $\rightarrow$ & $\text{skip}$\\
|
Christian Urban <christian dot urban at kcl dot ac dot uk>
diff
changeset
|
21 |
& $|$ & $Id := AExp$\\
|
Christian Urban <christian dot urban at kcl dot ac dot uk>
diff
changeset
|
22 |
& $|$ & $\text{if}\; B\!Exp \;\text{then}\; Block \;\text{else}\; Block$\\
|
Christian Urban <christian dot urban at kcl dot ac dot uk>
diff
changeset
|
23 |
& $|$ & $\text{while}\; B\!Exp \;\text{do}\; Block$\medskip\\
|
77
Christian Urban <christian dot urban at kcl dot ac dot uk>
diff
changeset
|
24 |
$Stmts$ & $\rightarrow$ & $Stmt \;\text{;}\; Stmts$\\
|
76
Christian Urban <christian dot urban at kcl dot ac dot uk>
diff
changeset
|
25 |
& $|$ & $Stmt$\medskip\\
|
Christian Urban <christian dot urban at kcl dot ac dot uk>
diff
changeset
|
26 |
$Block$ & $\rightarrow$ & $\{ Stmts \}$\\
|
Christian Urban <christian dot urban at kcl dot ac dot uk>
diff
changeset
|
27 |
& $|$ & $Stmt$\medskip\\
|
Christian Urban <christian dot urban at kcl dot ac dot uk>
diff
changeset
|
28 |
$AExp$ & $\rightarrow$ & $AExp + AExp$\\
|
Christian Urban <christian dot urban at kcl dot ac dot uk>
diff
changeset
|
29 |
& $|$ & $AExp * AExp$\\
|
Christian Urban <christian dot urban at kcl dot ac dot uk>
diff
changeset
|
30 |
& $|$ & $( AExp )$\\
|
Christian Urban <christian dot urban at kcl dot ac dot uk>
diff
changeset
|
31 |
& $|$ & $Num$\\
|
Christian Urban <christian dot urban at kcl dot ac dot uk>
diff
changeset
|
32 |
& $|$ & $Id$\medskip\\
|
Christian Urban <christian dot urban at kcl dot ac dot uk>
diff
changeset
|
33 |
$BExp$ & $\rightarrow$ & $AExp = AExp$\\
|
Christian Urban <christian dot urban at kcl dot ac dot uk>
diff
changeset
|
34 |
& $|$ & $AExp \not= AExp$\\
|
Christian Urban <christian dot urban at kcl dot ac dot uk>
diff
changeset
|
35 |
& $|$ & $\text{false}$\\
|
Christian Urban <christian dot urban at kcl dot ac dot uk>
diff
changeset
|
36 |
& $|$ & $\text{true}$\\
|
Christian Urban <christian dot urban at kcl dot ac dot uk>
diff
changeset
|
37 |
|
75
Christian Urban <christian dot urban at kcl dot ac dot uk>
diff
changeset
|
38 |
\end{tabular}
|
59
|
39 |
\end{center}
|
|
40 |
|
76
Christian Urban <christian dot urban at kcl dot ac dot uk>
diff
changeset
|
41 |
Transform this grammar into Chomsky normalform.
|
59
|
42 |
|
77
Christian Urban <christian dot urban at kcl dot ac dot uk>
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>
diff
changeset
|
44 |
|
59
|
45 |
\end{enumerate}
|
|
46 |
|
|
47 |
\end{document}
|
|
48 |
|
|
49 |
%%% Local Variables:
|
|
50 |
%%% mode: latex
|
|
51 |
%%% TeX-master: t
|
|
52 |
%%% End:
|