author | Christian Urban <christian dot urban at kcl dot ac dot uk> |
Thu, 26 Sep 2013 10:41:47 +0100 | |
changeset 102 | 1ab41c59e3d3 |
parent 93 | hw/hw08.tex@4794759139ea |
child 206 | 85b961f1eee9 |
permissions | -rw-r--r-- |
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
898c25a4e399
tuned
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
60
diff
changeset
|
13 |
\section*{Homework 8} |
59 | 14 |
|
15 |
\begin{enumerate} |
|
75
898c25a4e399
tuned
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 | 17 |
|
18 |
\begin{center} |
|
76
373cf55a3ca5
tuned
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
75
diff
changeset
|
19 |
\begin{tabular}{lcl} |
373cf55a3ca5
tuned
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
75
diff
changeset
|
20 |
$Stmt$ & $\rightarrow$ & $\text{skip}$\\ |
373cf55a3ca5
tuned
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
75
diff
changeset
|
21 |
& $|$ & $Id := AExp$\\ |
373cf55a3ca5
tuned
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$\\ |
373cf55a3ca5
tuned
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
49c0beef79a1
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
76
diff
changeset
|
24 |
$Stmts$ & $\rightarrow$ & $Stmt \;\text{;}\; Stmts$\\ |
76
373cf55a3ca5
tuned
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
75
diff
changeset
|
25 |
& $|$ & $Stmt$\medskip\\ |
373cf55a3ca5
tuned
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
75
diff
changeset
|
26 |
$Block$ & $\rightarrow$ & $\{ Stmts \}$\\ |
373cf55a3ca5
tuned
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
75
diff
changeset
|
27 |
& $|$ & $Stmt$\medskip\\ |
373cf55a3ca5
tuned
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
75
diff
changeset
|
28 |
$AExp$ & $\rightarrow$ & $AExp + AExp$\\ |
373cf55a3ca5
tuned
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
75
diff
changeset
|
29 |
& $|$ & $AExp * AExp$\\ |
373cf55a3ca5
tuned
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
75
diff
changeset
|
30 |
& $|$ & $( AExp )$\\ |
373cf55a3ca5
tuned
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
75
diff
changeset
|
31 |
& $|$ & $Num$\\ |
373cf55a3ca5
tuned
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
75
diff
changeset
|
32 |
& $|$ & $Id$\medskip\\ |
373cf55a3ca5
tuned
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
75
diff
changeset
|
33 |
$BExp$ & $\rightarrow$ & $AExp = AExp$\\ |
373cf55a3ca5
tuned
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
75
diff
changeset
|
34 |
& $|$ & $AExp \not= AExp$\\ |
373cf55a3ca5
tuned
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
75
diff
changeset
|
35 |
& $|$ & $\text{false}$\\ |
373cf55a3ca5
tuned
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
75
diff
changeset
|
36 |
& $|$ & $\text{true}$\\ |
373cf55a3ca5
tuned
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
75
diff
changeset
|
37 |
|
75
898c25a4e399
tuned
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
60
diff
changeset
|
38 |
\end{tabular} |
59 | 39 |
\end{center} |
40 |
||
76
373cf55a3ca5
tuned
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
75
diff
changeset
|
41 |
Transform this grammar into Chomsky normalform. |
59 | 42 |
|
77
49c0beef79a1
added
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. |
49c0beef79a1
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
76
diff
changeset
|
44 |
|
59 | 45 |
\end{enumerate} |
46 |
||
47 |
\end{document} |
|
48 |
||
49 |
%%% Local Variables: |
|
50 |
%%% mode: latex |
|
51 |
%%% TeX-master: t |
|
52 |
%%% End: |