doc-src/Exercises/2002/a3/a3.thy
author kleing
Thu, 05 Dec 2002 17:12:07 +0100
changeset 13739 f5d0a66c8124
permissions -rw-r--r--
exercise collection
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
13739
f5d0a66c8124 exercise collection
kleing
parents:
diff changeset
     1
(*<*)
f5d0a66c8124 exercise collection
kleing
parents:
diff changeset
     2
theory a3 = Main:
f5d0a66c8124 exercise collection
kleing
parents:
diff changeset
     3
(*>*)
f5d0a66c8124 exercise collection
kleing
parents:
diff changeset
     4
f5d0a66c8124 exercise collection
kleing
parents:
diff changeset
     5
subsection{* Compilation *}
f5d0a66c8124 exercise collection
kleing
parents:
diff changeset
     6
f5d0a66c8124 exercise collection
kleing
parents:
diff changeset
     7
text {* This exercise deals with the compiler example in section~3.3
f5d0a66c8124 exercise collection
kleing
parents:
diff changeset
     8
of \cite{isabelle-tutorial}. The simple side effect free expressions
f5d0a66c8124 exercise collection
kleing
parents:
diff changeset
     9
are extended with side effects.
f5d0a66c8124 exercise collection
kleing
parents:
diff changeset
    10
\begin{enumerate}
f5d0a66c8124 exercise collection
kleing
parents:
diff changeset
    11
f5d0a66c8124 exercise collection
kleing
parents:
diff changeset
    12
\item Read sections 3.3 and 8.2 of \cite{isabelle-tutorial}.  Study
f5d0a66c8124 exercise collection
kleing
parents:
diff changeset
    13
the section about @{text fun_upd} in theory @{text Fun} of HOL:
f5d0a66c8124 exercise collection
kleing
parents:
diff changeset
    14
@{text"fun_upd f x y"}, written @{text"f(x:=y)"}, is @{text f}
f5d0a66c8124 exercise collection
kleing
parents:
diff changeset
    15
updated at @{text x} with new value @{text y}.
f5d0a66c8124 exercise collection
kleing
parents:
diff changeset
    16
f5d0a66c8124 exercise collection
kleing
parents:
diff changeset
    17
\item Extend data type @{text "('a, 'v) expr"} with a new alternative
f5d0a66c8124 exercise collection
kleing
parents:
diff changeset
    18
@{text "Assign x e"} that shall represent an assignment @{text "x =
f5d0a66c8124 exercise collection
kleing
parents:
diff changeset
    19
e"} of the value of the expression @{text e} to the variable @{text x}.
f5d0a66c8124 exercise collection
kleing
parents:
diff changeset
    20
The value of an assignment shall be the value of @{text e}.
f5d0a66c8124 exercise collection
kleing
parents:
diff changeset
    21
f5d0a66c8124 exercise collection
kleing
parents:
diff changeset
    22
\item Modify the evaluation function @{text value} such that it can
f5d0a66c8124 exercise collection
kleing
parents:
diff changeset
    23
deal with assignments. Note that since the evaluation of an expression
f5d0a66c8124 exercise collection
kleing
parents:
diff changeset
    24
may now change the environment, it no longer suffices to return only
f5d0a66c8124 exercise collection
kleing
parents:
diff changeset
    25
the value from the evaluation of an expression.
f5d0a66c8124 exercise collection
kleing
parents:
diff changeset
    26
f5d0a66c8124 exercise collection
kleing
parents:
diff changeset
    27
Define a function @{text "se_free :: expr \<Rightarrow> bool"} that
f5d0a66c8124 exercise collection
kleing
parents:
diff changeset
    28
identifies side effect free expressions. Show that @{text "se_free e"}
f5d0a66c8124 exercise collection
kleing
parents:
diff changeset
    29
implies that evaluation of @{text e} does not change the environment.
f5d0a66c8124 exercise collection
kleing
parents:
diff changeset
    30
f5d0a66c8124 exercise collection
kleing
parents:
diff changeset
    31
\item Extend data type @{text "('a, 'v) instr"} with a new instruction
f5d0a66c8124 exercise collection
kleing
parents:
diff changeset
    32
@{text "Store x"} that stores the topmost element on the stack in
f5d0a66c8124 exercise collection
kleing
parents:
diff changeset
    33
address/variable @{text x}, without removing it from the stack.
f5d0a66c8124 exercise collection
kleing
parents:
diff changeset
    34
Update the machine semantics @{text exec} accordingly. You will face
f5d0a66c8124 exercise collection
kleing
parents:
diff changeset
    35
the same problem as in the extension of @{text value}.
f5d0a66c8124 exercise collection
kleing
parents:
diff changeset
    36
f5d0a66c8124 exercise collection
kleing
parents:
diff changeset
    37
\item Modify the compiler @{text comp} and its correctness proof to
f5d0a66c8124 exercise collection
kleing
parents:
diff changeset
    38
accommodate the above changes.
f5d0a66c8124 exercise collection
kleing
parents:
diff changeset
    39
\end{enumerate}
f5d0a66c8124 exercise collection
kleing
parents:
diff changeset
    40
*}
f5d0a66c8124 exercise collection
kleing
parents:
diff changeset
    41
(*<*)
f5d0a66c8124 exercise collection
kleing
parents:
diff changeset
    42
end
f5d0a66c8124 exercise collection
kleing
parents:
diff changeset
    43
(*>*)