3.2 Commands of L
3.2.1 Syntax of the Commands
The commands of L are defined as a set of commandsC
0 of which only a subset is needed to model processor instructions. This is to simplify the development of the language and its prop- erties. The setC
0 is inductively defined from labelling, conditional and assignment commands.
Definition 3.16 Syntax of the commands ofL There is an inductively defined setC
0and functions: if then else :(E C 0 C 0 )!C 0 :=
;
:(AlistEl)!C 0 : :(LabelsC 0 )!C 03.2 Commands ofL 60 The setC 0 is defined:
e
2Ec
1;c
2 2C 0 (ife
thenc
1elsec
2 )2C 0al
2Alistl
2El :=(al;l
)2C 0l
2Labelsc
2C 0 (l
:c
)2C 0 The assignment command ofLis:=(al;l
), the conditional command is ifb
thenc
1else
c
2 and the labelling command is(l
:c
)whereal
2Alist;l
2El;b
2Eb andc;c
1
;c
22C0. The label of a labelled command(
l
:c
)isl
, label(l
:c
)def
=
l
. The successor expression of assignment command :=(al;l
)isl
(a label expression).An assignment command made up of a simple list will be written using infix notation. e.g. The command:=((
x
1
;e
1)(
x
n;e
n)nil;l
)will be writtenx
1
;::: ;x
n :=e
1
;::: ;e
n;l
.2 All commands ofC
0 contain at least one assignment command and every assignment com- mand assigns a value to the program counter, to select the next command for execution. An assignment command
c
is made up of an assignment listal
and a label expressionl
. The com- mand assigns the label expressionl
to the program counter pc simultaneously with assignments ofal
. The full list of assignments made by the commandc
is therefore the list (pc;l
)al
. (In effect, the assignment commandx
:=y;l
is short-hand forx;
pc:=y;l
.)The commands ofL used to model the instructions of an object code program are labelled commands inC
0. The set containing these commands is denoted
C. Commands of the setC 0 can be labelled with two or more different labels. If a command has two distinct labels,
l
1: (
l
2:
c
) andl
16=
l
2, then the command cannot be executed: A command is selected by the value of the name pc and the name pc cannot have two values. These commands are excluded from the setC.Definition 3.17 Commands ofL A command
c
2C0is regular if all labelled commands occurring in
c
have the same label.regular?:C 0 !boolean regular?(
c
) def = 8(l
1;l
2 :Labels;c
1;c
2 :C 0 ): (l
1 :c
1 )c
^(l
2 :c
2 )c
)l
1 =l
2 The setC is the subset ofC0containing only labelled, regular commands: C def = f(
l
:c
)j (l
:c
)2C 0 ^regular?(l
:c
)g 2 A commandc
which is selected in a states
can fail if it attempts an impossible assignment or it is labelled with two distinct labels. The labels of a command can be distinguished by syntactic equality and commands with distinct labels are excluded from set C. This ensures that if a command inC fails, it does so because of an incorrect assignment.3.2 Commands ofL 61
value ::= any element of the set Values name ::= any element of the set Names label ::= any element of the set Labels value function ::= any element of the setFv name function ::= any element of the setFn label function ::= any element of the setF
l
E ::= hvaluei j hvalue functioni(hEi
;::: ;
hEi) j hEni j hEli j hEi/
hAlistiEn ::= hnamei j hname functioni(hEi
;::: ;
hEi) j hEni/
hAlisti El ::= hlabeli j hlabel functioni(hEi;::: ;
hEi) j hEli/
hAlistiAlist ::= nil j (hEni
;
hEi)hAlisti j hAlistihAlisti com ::= ifhEithenhcomielsehcomi j :=hAlisti;
hEliC 0
::= hcomijhlabeli:hcomi C ::= hlabeli:hcomi
Figure 3.4: Summary of Syntax for Expressions and Commands ofL
Example 3.15 Assume assignment lists
al;bl
2 Alist, distinct labelsl
1;l
22 Labels, label ex- pression
l
2Eand Boolean expressionb
2Eb.The commands ofC 0include: :=(
al;l
);
:=(bl;l
1 );
:=((pc;l
1 )al;l
2 ) ifb
thenl
1 :(:=(al;l
))else :=(bl;l
1 )l
2 :ifb
thenl
1 :(:=(al;l
))elsel
2 :(:= (bl;l
1 ))l
1 :l
2 :(:= (al;l
))l
1 :(:=(al;l
));l
2 :(:= (bl;l
1 )) Of these, the regular commands are::=(
al;l
);
:=(bl;l
1 );
:=((pc;l
1 )al;l
2 ) ifb
thenl
1 :(:=(al;l
))else :=(bl;l
1 )l
1 :(:=(al;l
));l
2 :(:=(bl;l
1 )) The commands which are also inC arel
1 :(:=(
al;l
))andl
2 :(:=(bl;l
1 )). 23.2 Commands ofL 62
Basic Commands of
LA summary of the syntax of the commands and expressions ofL is given in Figure (3.4). The syntactic category C describes the commands of the set C, which will be used to model the instructions of an object code program. These are the commands labelled with a single label. The syntactic category C
0 of Figure (3.4) describes the commands of the set
C0, which will be used when deriving and manipulating commands ofL.