-
Give a BNF definition of a syntactic category
<CaseList> for the list of cases,
where the list either consists of a single case,
of the form N : P, with N an integer and P a program,
or is of the form N : P
;; CL, where
CL is a CaseList. For example,
0 : 'z := 5 ;; 3 : 'z := 6 ;; 4 : 'y := 0
is a <CaseList>.
-
Extend the BNF syntax of the programming language with a clause
stating that Programs (<Pgm>) may also consist
of case conditionals of the form
case E of CL endcase
where E is an expression and CL a CaseList.
-
Define a semantic function for CaseLists
[[ CL ]] : Int State -> State
such that for a CaseList CL, integer N and State S,
[[ CL ]](N,S) gives the State that results from
choosing the
first program in CL with label N and running it in
state S.
For example, it should follow from your definition that
[[ 0 : 'z := 5 ;; 3 : 'z := 6 ;; 4 : 'y := 0 ]](3, S)
will return the state that results from running the program
'z := 6 in the State S.
-
Extend the program-denotational semantics
to give a semantics for case conditionals; i.e., define
[[ case E of CL endcase ]]
where E is an expression and CL a CaseList.
-
Use your answers to calculate the semantics
of the following program:
'x := 2 ;
case 'x + 1 of
0 : 'z := 5 ;;
3 : 'z := 6 ;;
4 : 'y := 0
endcase