LIBRARY OF THE UNIVERSITY OF ILLINOIS AT URBANA-CHAMPAIGN 510.84 TfiGr ™>.7?0-775 cop .£- 1 he person charging this material is re- sponsible for its return to the library from which it was withdrawn on or before the Latest Date stamped below. Theft, mutilation, and underlining of books are reasons for disciplinary action and may result in dismissal from the University. UNIVERSITY OF ILLINOIS LIBRARY AT URBANA-CHAMPAIGN i 4 NEC L161 — O1096 Digitized by the Internet Archive in 2013 http://archive.org/details/semanticdefiniti773ukas January, 1976 A Semantics Definition System (A Preliminary Description) DEPARTMENT OF COMPUTER SCIENCE UNIVERSITY OF ILLINOIS AT URBANA-CHAMPAIGN URBANA, ILLINOIS .-. tIBRARV OF UNIVERSITY OF UIUCDCS-R-76-773 A Semantics Definition System (A Preliminary Description) by Leon Lukaszewicz (On leave, Polish Academy of Science, Warsaw) January, 1976 Department of Computer Science University of Illinois at Urbana- Champaign Urbana, Illinois Abstract A simple and universal system for the semantics definition of programming languages is presented. The- system includes a state set, an interpreter, an instruction stack set and a transition function. A few examples of semantics definitions are given. The definitions are easy to read, allow an intuitive -understanding of the languages and provide a base for a feasible language implementation. Ill Acknowledgment The author wishes to express his gratitude to the Department of Computer Science, University of Illinois for providing him with the opportunity to spend a fruitful and, also, pleasant semester there. The author would like to thank many people of the Department for their critical comments and specifically Professor Wilfred J. Hansen for his careful reading and valuable suggestions for the improvement of the original manuscript. Thanks also go to Mrs. June Wingler for her excellent typing of this paper. XV Table of Contents Page Introduction 1 1. Notational Conventions 3 1. 1 Propositions 3 1. 2 Predicates k 1. 3 Sets 6 l.k Relations 7 1. 5 Standard Names 9 1. 6 Conditional Expressions 10 1. 7 The Representation Operator 11 2. Abstract Objects 13 2 . 1 The Definition 13 2.2 Selectors 19 2.3 Classes of Objects 22 2.k Lists 28 2.5 Stacks 32 2 . 6 Assignment 3^- 2 . 7 Substitutions 38 2 . 8 Structural Induction kO 3. The System k6 3 . 1 The Definition k6 V 3.2 Processes kl 3 . 3 Interpreters h9 3.3-1 The Definition *+9 3.3.2 The Basic PDL 52 3 . k The Transition Function 5k 3.^.1 Argument Values ^k 3.^.2 The Instruction Stack 55 3.^.3 Instruction Types 56 3.^.3. 1 Assignment Instruction 57 3.^.3.2 Conditional Instructions 58 3.^-.3.3 Compound Instructions 59 3.^.3.^ Choice Instructions 60 3.^.3.5 Label Instruction 60 3.^.3.6 Skip Instruction 6l 3.^.3.7 Procedure Calls 62 3. k. k The Formal Definition 63 3.5 A Process Definition Language 65 3.5-1 Instructions 65 3.5.1.1 Special Instructions 65 3.5.1.2 Assignment Instruction. 66 3. 5. 1. 3 Compound Instructions 66 3.5.1.*+ Conditional Instructions 66 3.5.1.5 Loop Instruction 69 3.5.1.6 Collateral Instruction 69 3.5.2 Standard Functions 70 3.5.2.1 Selector Applications 70 3-5-3 Standard Operations 72 3. 5.*+ Other Conventions 7I4. 3-5.4.1 Content Expressions 74 3. 5- 4.2 Comments 74 4. Simple Applications 75 4.1 A Computer 75 4.2 Arithmetic Expressions 80 4.2.1 Expression Values 80 4.2.2 A Deterministic Computation 82 4.2.3 A Nondeterministic Computation 85 References 87 Introduction In this report a system is presented for the definition of semantics of programming languages. Special attempt has been made to keep the system as simple as possible to make it accessible not only to mathematicians but also to many programmers and engineers. To this end the mathematical foundations of the system have been confined to the elementary notions of the set theory and predicate calculus. The system is a quadruple of a state set, an interpreter, an instruction stack set and a transition function. The states contain objects interpreted by the system, for instance, a program data for the program and a storage stack. The interpreter is a set of prcoedures describing the interpretation of the states. The procedures are written in the Process Definition Language PDL, which has the form of a simple programming language. The instruction stack serves as the execution environment of the interpreter. The states, interpreter and instruction stacks are defined as abstract objects , introduced by the Vienna Group. This framework is sufficiently general to describe the semantics of even very large programming languages. With abstract objects it is straightforward and easy to describe tree shaped structures such as expressions, programs, directories and most date structures. The descriptions of structures such as rings or plexes are more complicated but possible. The semantics definition of programming languages based on transitions of states was first presented by J. McCarthy (1962, I96U) and widely developed by the Vienna Group in their formal PL/ I definition (P. Lucas and K. Walk, 1969). The ideas presented in this report are based mainly on these works. In some other approaches to the semantic definition, the meaning of the programming language is defined by axioms and rules of inference (C. A. R. Hoare) or it may be associated with some mathematical constructs (D. Scott). The procedural definition, however, described in this report, is often preferred by those accustomed to programming. The present report is composed of four chapters. In Chapter 1 some notational conventions are presented. In Chapter 2 the concept of abstract objects is reviewed. The notation is slightly different from the one used by the Vienna Group. In Chapter 3 the semantics definition system is defined. In particular, the grammar, notation and semantics of the Process Definition Language are described. Finally, in Chapter k a few examples of the application of the system are presented. 1. Notational Conventions This chapter contains notational conventions used throughout this report without further comment. Some conventions are generally used in the symbolic logic or set theory; others have been introduced especially for the needs of this report. In the following, all definitions, theorems, lemmas, proofs, examples and remarks are terminated by the symbol ■ . 1.1 Propositions Assertions which are either true or false are called propositions . Truth and falsity are called truth values; they are denoted by true and false . Given propositions p and q we can form a new proposition using logical operators . The following notation will be used t p (not p) p ^ q (p or q) p ^ q (p and q) p ■$ q (if p then q (else true )) p<=£q (p if and only if q) Expressions made up of propositional variables and logical operators according to certain formation rules are called propositional formulas . A valid formula or tautology in propositional logic is a formula which is true for all substitutions of truth values for propositional variables. 1.2 Predicates An expression which contains n variables defined on given domains and which becomes a proposition for any choice of a value of the variables is called an n-place predicate . One-place predicates "x is p" will often be written as is-p(x). It is important that the domains of the predicate variables always be defined. Sometimes the domains are called a universe of discourse . The ■universe of discourse often used below are sets of abstract objects defined later. If, for a given x, the predicate is-p(x) is true then we say that x satisfies Is-p or that x has the property is-p. Example 1.2.1 In the domain of integer numbers, let is-odd(x) (x is odd) Then the integer 7 satisfies is-odd or 7 has the property is-odd. The integer k does not satisfy is-odd. B A different way of obtaining propositions from predicates is by using the universal quantifier V or the existential 3 . The expression x n , ..., x [is-p(x 1 , a . „,x )] 1 7 n 1 n ' is true if and only if for all n- tuples x , . ..,x (in the domains of the variables) is-p(x , ...,x ) is true, otherwise the expression is false. The expression 3x,, .... x [is-p(x_, . . .,x )] 1' ' n 1 n' is true if and only if there exists at least one n-tuple x , ...,x (in the domains of the variables) such that is-p(x , . ..,x ) is true, otherwise the expression is false. In the expressions above x , . . . ,x are called bound variables . Any other variables appearing in the predicate is-p are called free variables . It is important that the domains of the bound variables in an expression containing a quantifier always be defined. Expressions made up of quantifiers, propositional variables and n-place predicates with bound variables are called predicate formulas . As in the case of propositional formulas certain formation rules must be observed. In a predicate formula, for the sake of brevity, the outermost universal quantifier is often omitted in cases where no confusion can arise. Example 1.2.2 Given a predicate is-p, the predicate formula 3 x [is-p(x)] * Vx,y[is-p(x) ~ is-p(y) => x=y] k asserts that there exists exactly one object with the property is-p. We can use the iota operator ^ to select this object out of the universe of discourse. (•Px)[is-p(x)] which reads "the one and only one x such that is-p(x) is true. " If there is no such value or more than one value that satisfies is-p, the value of the expression is not defined. I 1.3 Sets A set may be given explicitly, for instance {a,b,c} The a, b and c are elements of the set. The empty set is denoted by null . A set may be also given implictly, for instance {t|is-p(t)} is a set of all t which satisfy is-p. The t is called the bound variable of the expression. The set defined by a predicate is-p will always be denoted as p-set. Thus, for any symbol p, the names is-p and p-set are always bound by the relation p-set = {t|is-p(t)} Given a p-set, we shall assume that the names P. p'» V Q , Pp denote variables ranging over the p-set. Example 1.3.1 In example 1.2.1 we defined the predicate is-odd. Thus, odd- set = {x|is-odd(x)} and odd, odd,-,* odd* denote variables ranging over the odd- set. • Given a-set and b-set we can form a new set using set operators. The following notation will be used ~ a-set = {t|- is-a(t)} a-set U b-set - {t|is-a(t) v- is-b(t)} a-set fl b-set = {t|is-a(t) ^ is-b(t)} Moreover x e a-set ^ is - a (x) x j. a-set $$■ t(x e a-set) a-set <= b-set £» V t[is-a(t) =?> is-b(t)] Two sets a-set and b-set are called disjoint if and only if a-set fl b-set = null . Let W be a set of sets. Then a set Y is the smallest element of W if and only if Y e W and U € W => Y c u. l.k Relations An ordered pair of elements a, and a~ from a set is written (a, ,a, ), We always assume (a 1 ,a 2 ) - (b 1 ,b 2 )^ (a^b^ * (a 2 =b 2 ) In the similar way we define an n- tuple (a , ...,& ). The one-tuple (a) is identified with a. 8 In the expression denoting a set, in place of the bound variable a composite construct such as an n-tuple may be written. For instance, the cartesian product of a-set and b-set is defined by a-set X b-set = {(x,y)|x e a-set ^ y e b-set} The x and y are bound variables of the expression. A binary relation R between a-set and b-set is a nonempty subset of a-set x b-set. If the ordered pair (a, b) is a member of R we may write a R b and so a R b 4» (a,b) e R Example l.U.l Let a-set = b-set = int-set, where int-set is the set of all integers. Then the relation < may be defined by [(a, b) e <] 4=s> (a is less than b) The relation < is, therefore, a set of pairs (a,b) such that a is less than b. If (a,b) e < we write a < b. ■ A function or mapping f from x-set to y-set is a subset of x-set x y-set with the property that for each x there exists one and only one y such that (x, y) e f. x-set is the domain of the function, y-set is the range . For the mapping we may write f : x-set -> y-set If (x, y) e f, we write f(x) = y or y = f(x), and f(x) is called the value of f for the argument x. A function is often defined by defining its value for all elements of the x-set. If the f is not defined for all elements of x-set, then we call it a partial function over x-set. Example 1.U.2 Any one-place predicate is-p may be considered as a mapping is-p: x-set -> { false , true ] where x-set is the domain of the predicate. Thus, the value of is-p (x) is either false if is-p (x) is false or true if is-p (x) is true. 1.5 Standard Names A few names given below have the same meaning throughout this report. bool-set = { false, true ) n-set = {int|int > 0) In any context where n is fixed we denote: i-set = {1,2, . . . ,n] j-set = {1,2, . ..,n) In this report, therefore, comments like n > 1 or 1< i < n are usually omitted. Further on we assume id-set = (a nonempty set of identifiers) 10 The identifiers are supposed to be symbols. Their exact appearance is not specified because it is usually not essential. op-set = [+, -, *,/,=,<,...} The op- set contains operator symbols. The exact list of all op- set elements depends on a given application. Quotations around identifiers and operator symbols are always omitted. For any q-set and p-q-set we assume q-p-set cz p-set Thus, a prefix ' q-' added to the name of a set denotes a subset of the set. Hence, comments like proc-id-set cz id- set are in this report omitted. 1.6 Conditional Expressions In this report conditional expressions have a LISP- like form [prop -> expr-,, prop 2 -» expr 2 , prop -» expr ] n n This expression has the value of expr., where i is the integer for which prop, is true and for all < j < i prop, are false. If there is no such integer, the value of the expression is undefined. 11 Conditional expressions are often used to define the value of a function as in the examples below. Example 1.6.1 max (n^ i^) = [r^ > n g -> n.^ true -» n^] div(n 1 ,n 2 ) = [n 1 < n g -» 0; true -* div^-ng,^) + 1] p ^ q = [p -> q, true -» false ] P ® q = [p -* - q> true -> q] ■ 1.7 The Representation Operator The representation operator =: is used in expressions of the following form y =: f(x) which reads "y can be represented by f (x). " Given y-set, x-set and the function f, the expression has the value 3x[y=f(x)] Moreover, by convention, x denotes the one and only one solution of y=f(x) whenever such a solution exists. Thus, using the iota operator, defined in example 1.2.2 x = (ii») [y=f(x')] Note that in the expressions in this section y is a free variable and x, x* are bound ones. Example 1.7.1 In the domain of real numbers R the function &n may be defined as follows Hy) = [y =: e x - x] 12 Note that for y < the function &n is not defined. For y > there exists exactly one value x such that y=e and it contributes the value of My). The representation operator may be also used in expressions of the form y =: f(x x , ...,x n ) Given y-set, x-set and f the expression has the value 3 x ± , . .., x n [y = f(x x , . ..,x n )] or, if n is not fixed 3n[3x 1 ,...,x n [y = f (x^ . . .,x n )] ] Moreover, by convention, we denote ( Xl ,...,x n ) = fr(xj_,...,x^))[y = f(x^...,x^)] Example 1.7.2 Let k-set = {2,3,^,...) and y e int-set. Then consider the expression , 2 n 2 y =: k n + ... + k 1 n For y=10 the expression is false because there exists no (k , ...,k ) 2 2 such that y = k n + ... + k . 1 n For y=k the expression is true and (k , . ..,k ) denotes the one-tuple 2. For y=25 the expression is true and there are three solutions: (3>^)> (U,3) and 5. Thus, in this case the value of (k , ...,k ) is undefined. ' 13 2. Abstract Objects 2.1 The Definition The underlying motivation of abstract objects is the old idea that discussion of a complex object is usually simplified if the object can be decomposed into a finite number of components and each of them discussed separately. The components may in turn be objects, which we decompose again. We assume, however, that after a finite number of steps we always reach objects so simple that we do not decompose them further. We can, therefore, distinguish components according to their level; those on the first level are called direct components . The nonde compos able components are called elementary objects . To identify components of an object only by their names may be insufficient because two direct components of an object may have identical names. Therefore, to every component we append a tag called a simple selector and require that the selectors of direct components of any object be mutually distinct. In the following definition of abstract objects we assume as given a set of elmentary objects eo-set and a set of simple selectors ss-set. Selectors are supposed to be symbols and no restrictions on the nature of elementary objects are made, eo-set and ss-set may have elements in common. Starting with eo-set and ss-set we can use them to build the set of abstract objects ao-set and the set of composite objects co-set. The definition is 11+ recursive in that an abstract object, ao, is either an elementary object eo or a composite object, co; and any composite object, co, is either the empty set or a set of abstract objects tagged by selectors. Definition 2.1.1 Let ao-set and ss-set be nonempty countable sets and let elements of ss-set be symbols. Then ao-set, defined over eo-set and ss-set, is ao-set = eo-set U co-set where co-set is the smallest set such that null e co-set and if x =: ((ss^ao ), ..., (ss^ao^} and ss ,...,ss are mutually distinct then x e co-set. f Since co-set is the smallest set satisfying the definition, the composite objects are finite both in width and in depth. To denote abstract objects the following definitions are introduced. Definition 2.1.2 df ( s ss:ao = (ss,aoj The pair ss:ao is called a tagged object. Definition 2.1.3 If i f j =» ss. £ ss . then ' l ' .1 ( ss n :ao n , . . ., ss :ao ) = 1 1 n n f ss, :ao n , . . ., ss :ao } •-11 n n J E 15 Thus, the form (ss :ao n , . . ., ss :ao ) is meaningful only if all ss. ' 2 1 n n J l are distinct. The order of tagged objects inside the form is, of course, irrelevant. Definition 2.1.1+ If ao =: (ss.. :ao .,,..., ss :ao ) then every ao. is called a direct 1 1 7 n n l component or the s. component of ao. ■ Definition 2.1.5 ao' is called a component of ao if ao' is either a direct component of ao or a component of a direct component of ao. ■ Definition 2.1.6 If ao' = ao or ao' is a component of ao then ao' is called a sub-object of ao. ■ Convention The universe of discussion assumed in this report is a set of abstract objects ao-set defined over some given sets of elementary objects and simple selectors specified for each context. Thus, if nothing is said to the contrary, the domain of the predicate variables is ao-set. H Remark Symbols starting with 's-', for instance, s-code, denote usually simple selectors. Since simple selectors are identifiers, quotations enclosing selectors are not used. B 16 Example 2. 1.1 To represent a computer instruction as an object, let us assume eo-set = code-set U addr-set U bit-set code- set = { L, A, ST, BZ, HLT, . . . } bit-set = {0,1} addr-set = {0,1,.. . ,max-addr} ss-set = { s-code, s-addr, s-x-bit} The code-set is composed of instruction symbols. The max-addr denotes the greatest address used in the instructions. Now, the abstract object instr n = (s-code :L, s-addr :80) may represent a compute instruction. Here the code L and address 80 are the instruction components. They are uniquely tagged and their ordering has been avoided. ' Example 2.1.2 Arithmetic expressions may be readily represented as abstract objects. Let eo-set = int-set U var-id-set U op-set var-id-set = {X, Y, . . . } op- set = ■{+,*,...) ss-set = {s-op, s-1, spr) Then the object expr„ = (s-op:*, s-l:X, s-r : (s-op:+, s-l:Y, s-r :7)) 17 may represent the arithmetical expression, denoted usually as X*(Y+7) • The object has 3 direct components. The component tagged by s-r is a composite object. The Tree Notation It is sometimes convenient to think of abstract objects as trees. For that purpose the following notation is introduced: (1) An elementary object eo is represented by a small circle, for instance, o eo (2) An abstract object ao is generally represented by a greater circle, for instance (ao) (3) A composite object co = (ss, :ao.., . . ., ss :ao ) 1 l 7 n n is represented by ss. ss n 18 where, for the respective tree representation may be inserted. Abstract objects are, therefore, represented by trees with selectors naming the braches and elementary objects attached to the terminal nodes. The order of branches in a tree is irrelevant. Example 2.1.3 The object expr n from example 2.1.2.2 may be represented by the following tree s-op expr„ = •- s-1 -o * X s-r s-op -o + s-1 -o Y s-r A tree structure of an object can be also reflected in usual notation by writing only one argument per line and indenting it properly. Example 2.1.3+ The object expr from the last example may be presented in the form: expr = (s-op : ■*, s-1 : X, s-r : ( s-op : +, s-1 : Y, s-r : 7 ) ) and the tree structure of expr„ is readily seen. ft 19 2.2 Selectors Simple selectors enable us to pick out uniquely every direct component of a given composite object. If co = (ss n :ao 1 ,...,ss :ao ) 1 1' ' n n then co • ss. = ao. i i The symbol • is called, the selection operator and co • ss. can be read "the selector ss. applied to co." The meaning of ao • ss can be extended to any ao and ss. If there is no direct component of ao tagged by ss then we assume that the value of ao • ss is null . In particular, for any ss null • ss = null and for any eo and ss eo • = null . With this extension, the value of ao • ss is always defined. Thus, we have Definition 2.2.1 df ao • ss a(ao,ss) a : (ao,ss) - set ■+ ao-set cr(ao,ss) = [ao e eo-set v ao = null -» null ; ao =: (ss., :ao n , . . . ,ss :ao ) -* 1 1' ' n n [3 i[ss=ss. 1 -* ao. ; i i true -* null ] ] The operator • may, therefore, be seen as a function mapping (ao,ss)-set into ao-set. 20 Example 2.2.1 For the object instr of example 2.1.1 we have instr n • s-code = L However instr n • s-addr = 80 instr o s -x-bit = ntill because instr n has no component tagged by s-x-bit. Composite Selectors The value of ao • ss, is always an object so we can apply to it another selector, say s p , which results in an object (ao • ss p ) • ss . This notation may be abbreviated to ao • ss, • ss p and in general we adopt the following convention. Definition 2.2.2 d_f ao • c-I ~ ao df, . ao^ ss_ • ... • ss ,= ( ao • ss, • ... • ss ) • ss , 2 n+1 1 n y n+1 where c-I is a special symbol, called identity selector . Example 2.2.2 For the expr from example 2.1.2 we have expr n • c-I = expr expr n • s-r • s-1 = Y expr„ • s-1 • s-r = null E 21 Definition 2.2.3 Given s-set, a composite selector is either the symbol c-I or an expression ss, • ... • ss 1 n The composite selectors we shall call simply selectors . The set of all composite selectors build over elements of ss-set will always be denoted as sel-set. H Thus, in the following, sel, sel , sel' will always denote composite SI selectors. The identity selector c-I may be seen as a boundary case for ss, • ... • ss with n=0. 1 n In some applications the following definitions are useful. Definition 2.2.U The expression sel , which reads "the selector sel to the power k" is defined by Example 2.2.3 n Odf _ ,n+ldf _n sel = c-I, sel = sel • sel 2 s-tail = s-tail • s-tail Definition 2.2.5 The length of a given selector sel, denoted by |sel| is defined by Example 2.2. k c-I = ss • sel = 1 + sel |s-stack • s-tail | = 3 22 Definition 2.2.6 Two selectors sel and sel* we call equivalent and write sel ~ sel' if and only if V ao[ao • sel = ao • sel 1 ] ■ It is readily seen that c-I • sel ~ sel sel • c-I ~ sel The symbol c-I is, therefore, the unit element in respect to selection operator • . 2.3 Classes of Objects In section 2.1 we have defined ao-set as a set of all abstract objects built from the sets eo-set and s-set. Now we shall show how particular subsets of ao-set, called object classes, may be defined. Example 2.3.1 Let eo-set, ss-set and ao-set have the meaning given in example 2.1.1 (computer instruction objects) and let instr = (s-code : code, s-addr : addr) Then the class instr-set is the set of all values the variable instr can assume when variables code and addr range over code-set- and addr-set respectively. The predicate is-instr is true for all objects instr and false for all other elements of the ao-set. * In this report classes of objects will be most often defined in terms of predicates and sets, as this enables us to use the notations of the predicate calculus and the set theory. 23 First, the application of logical connectives is extended to apply not only to propositions but also to predicates. Definition 2.3.1 Given predicates is-p and is-q, the predicate expression is-p v is-q denotes a new predicate defined by (is-p v is-q)(t) £» is-p(t) v is-q(t) In terms of sets the new predicate is defined by p-set U q-set Example 2.3.2 If eo-set = int-set U var-id-set U op- set then the predicate is-primary = is-int v- is-var-id is satisfied by any element of int-set U var-id-set. If a predicate expression contains other logical connectives other than 'v' or parentheses it is defined in a similar way. Example 2.3.3 Assume the following definitions valid over the domain of positive integers : odd-set = {n|3n f [n = 2n' + 1]} 2 uare-set = {n|3n'[n = (n' ) ]} cube-set = {n|3n'[n = (n 1 ) 3 ]} 2k Then the predicate is-p = -| is-odd ^ (is-square v- is-cube) is defined by the identity is-p(t) 4$ -! is-odd(t) a (is-square(t ) v is-cube(t)) To simplify the notation of predicate expressions and related sets, the following abbreviations may be used. Definition 2.3.2 is-(p ^ q) = is-p v is-q df (p v q)-set (xis-(p v q)(x)} The above definition is easily extended for any predicate expression. Example 2.3.1+ Let us assume the denotations of the previous example. Then (-! odd ^ (square v cube))-set denotes the set (~ odd-set fl (square-set U cube-set)) = {^,8, ...} and the predicate is-(-i odd ^ (square v cube)) is true for all numbers of the set and false for all other positive integers. I 25 Now we shall define a predicate expression facilitating the definition of classes of composite objects. Definition 2.3.3 Given n predicates is-p-1, . . . , is-p-n and mutually different selectors ss,,...,ss , the expression is-(ss :is-p-l, . . ,,ss :is-p-n) denotes a new predicate, true for all objects (ss 1 :p-l, ...,ss n :p-n) and false otherwise. I The new predicate is, therefore, satisfied by all composed objects with ss. -component satisfying is-p-i for i=l, ...,n and with no other direct component s . Example 2. 3. 5 With the denotation of example 2.1.1, the predicate is-(s :code:is-code, s-addr :is-addr ) is satisfied by all objects (s-code:code, s-addr :addr) and in particular by the object (s-code:L, s-addr :80) To simplify the notation of some predicates we introduce the following. Definition 2.3.1+ Inside predicate expressions of the form defined in 2.3.3 the following abbreviation may be used ££ p s-p:is-p Example 2.3.6 The notation of is-(s-code:is-code, s-addr :is-addr) may be abbreviated to is-(code,addr) Another definition of a predicate related to a class of composite objects is Definition 2.3.5 Given two predicates is-q over s-set is-p over ao-set then the expression is-({is-q:is-p} ) denotes a new predicate defined by is- ({is-q: is-p} )(t) 4=> t = null ^ t =: ( q x :?-]_, ...,q n :p n ) 26 27 The predicate is-({is-q:is-p} ) is, therefore, satisfied by the object null and by any object in which all direct components are from p-set and have tags from q-set. The objects are always finite, but the number of their components may be unbounded. Example 2.3.7 The predicate is-store = is-({s-addr :is-cont} ) is satisfied, for instance, by the object store = (s-addr-, :cont,, . . ., s-addr :cont ) 1 1' ' n n y The object may represent a state of a computer store. Then n is the size of the store, the addresses s-addr. are addresses of the store i cells and the objects cont. are the cells contents. As we have store • addr. = cont. l i any cell content may be retrieved from the store by a simple selector application. Remark 2.3.1 The previous definitions can be combined. The meaning of the predicate is-(ss, :is-p-l, . . ., ss :is-p-n, {is-q-l:is-r-l), . . . , {is-q-m:is-r-m} ) is obvious. 28 Example 2.3.8 In this example we shall define a class of abstract objects expr-set which we shall call a class of arithmetical expressions . The class is given by the following set of definitions: (1) ss-set = {s-op, s-1, s-r} (2) eo-set = int-set U var-id-set (3) var-id-set = (X,Y, ...} (k) op-set = {+,*} (5) is-bin-expr = is- (op, s-l:is-expr, s-r:is-expr) (6) is-expr = is-int ^ is-var-id v is-bin-expr The definitions constitute an abstract grammar of the arithemtical expressions. The definitions are recursive, because is-expr is defined by- using is-bin-expr and is-bin-expr is defined by using is-expr. The class expr-set is infinite. The object expr = (s-op:*, s-l:X, s-r : (s-op:+, s-r :Y, s-l:7) ) satisfies is-expr. The demonstration is left to the reader. I 2.1+ Lists In many applications it is necessary to define an object, whose direct components are ordered, so that we can talk on the 1-st, 2-nd, ... object component. Objects having this property are usually called lists . The simplest way to order direct components of an object is to tag them with selectors which form an ordered set. For this purpose, a function s-elem is introduced s-elem:n-set -> s-set 29 with the property s-elem(i) / s-elem(j) for i fi j The specific value of s-elem(i) is left open by the definition. To denote an empty list a symbol nil is introduced. We assume that nil is always an element of eo-set. By is-nil we denote the predicate,, satisfied only by the symbol nil . Now it is possible to define a list. Definition 2.^.1 A list is either the symbol nil or any object (s-elem(l) :ao , . . . , s-elem(n) :ao ) I For lists the following notation is used. Definition 2.U.2 < > = nil = (s-elem-l:ao_, . . . , s-elem-n:ao ) In 1 n Symbols s-elem-i may be abbreviated using Definition 2.U.3 [i] = s-elem(i) If, therefore, 1 is a list, 1 • [i] denotes i-th direct component of the list. Example 2.U.1 The object al = «3,5>,< >,*+> B 30 is a list whose 1-st and 2-nd components are again lists. We have al - [1] - <3,5> al • [1] • [2] = 5 al • [2] = nil al • [10] = null Functions Defined on Lists A number of typical functions and operations on lists as arguments are defined below. leng(l) = [1 = < >-* • 1 =: -> n> n . , ao > -> ao . 1 n 1 J . , ao > -* n . . ao >] n cone (1,1 ) = [1 =: <>-> 1«: 1» =:<>-* 1: 1 =: ^ 1 n 1 m 1 n 1 m ] For the list concatenation the following notation is introduced: dt 1 V 2 = conc(l 1 ,l 2 ) 1 ^ 1 ^ (1 ^ n 1 v 2 V Note ^\ that (l x 1 2 ) I3 = 1-l 1 2 I3 and 1 nil = nil 1=1. 31 Example 2.U.2 Let 1 = and 1« = Then leng(l) = 3 head(l) = 1 tail(l) = <3,5> i^i» = Classes of Lists Often we need to denote a predicate satisfied any list which is either empty or every component of the list satisfies a predicate is-p. By convention, the new predicate is denoted by is-p-list, that is by extending the name 'is-p' by the suffix '-list'. The definition of the new predicate is Definition 2.U.3 is-p-list(t) = (t = nil v t =:

) Example 2.1+.3 The predicate is-int-list is satisfied by < > and <3, h, 5> and not satisfied by <3, <^,5» 32 2.5 Stacks Stacks are structures often used in formal definitions of programming languages. A stack consists of a chain of elements for which the rule holds that elements are deleted (popped up) from the stack in the inverse of the order in which they were added (pushed down). Therefore, the element last added (top element) is always deleted first. The retrieval to the top element is usually simplest. Given a predicate is-p, a new predicate is-p- stack is defined by convention as follows. Definition 2.5.1 is-p-stack = is-null ^ (s-top : is-p, s-tail : is-p-stack) I The definition is recursive and p-stack-set is infinite. Example 2.5.1 The following objects satisfy is-int-stack: (a) null (b) (s-top : 5> s-tail : null ) (c) (s-top : 3 s-tail : (s-top : 5 s-tail : null ) ) Definition 2.5.2 I ao ao = (s-top : ao , s-tail : ao ) df ao ., ... ao = ao n n+1 n n+1 (ao ... ao_ ) n 1 33 Now it can be readily shown that any p- stack may be expressed either by null or by p ... p.. null n 1 Example 2.5.2 Stacks from example 2.5. 1 may be expressed respectively by: (a) null (b) 5 null (c) 3 " 5 " null ■ Given p-stack, its k-th element from the top may be readily retrieved by k-1 p-stack ■ s-tail • s-top (k > l) For k=l we obtain the top element itself. To simplify notation we introduce Definition 2.5.2 c-top(k) = s-tail • s-top For k=l we have c-top(l) = c-I * s-top and therefore c-top(l) ~ s-top (see Definition 2.2.6). Therefore, for any ao ao • c-top(l) = ao • s-top 3^ Example 2.5.3 For int- stack =7 5 2 null we have int-stack • c-top(l) = 7 int-stack • c-top(3) = 2 I 2.6 Assignment In same applications we need to describe an assignment of an object ao to the address ss in the object ao. Such an assignment may be described by the function assn defined in this section. The value of the function assn(ao, ss,ao) is always an object. To define it, several cases may be singled out. Let ao have a component tagged by ss. Then assn(ao, ss,ao) is an object resulting from ao by replacing this component by a copy of ao. Example 2.6.1 Let instr n = (s-code : L, s-addr : 80) Then assn(instr , s-code } ST) = (s-code : ST, s-addr , 80) assn(instr n , s-addr , 20) = (s-code : L, s-addr , 20) I Now let ao e co-set and let ao have no component tagged by ss. Then assn(ao, ss,ao) is an object resulting from ao by adding the new pair ss :ao to it. 35 Example 2.6.2 For the object instr n from the previous example we have assn(instr n , s-x-bit, l) = (s-code : L, s-addr : 80, s-x-bit : l) Example 2.6.3 If ao = null then for all ss we have assn( null , ss, ao) = (ss : ao) ■ For the case ao e eo-set we define assn(eo, ss, ao) = (ss : ao) This definition provides that for any ao the object assn(ao, ss, ao) has the ss component equal ao and for all ss' ^ ss if ao has ss' component then it remains unchanged. All definition cases discussed above may be now assembled into Definition 2.6.1 assn : (ao, ss, ao)-set -> ao-set assn(ao, ss, ao) = [ao e eo-set \/ ao = null -» (ss : ao), ao =: (ss.. : ao , ..., ss : ao ) -> v 1 1 n n y [3 i (ss = ss. ) -> i (ss.. : ao.., ..., ss. : ao, ..., ss : ao ), 1 1 i n n true -* (ss n : ao n , ..., ss : ao , ss : ao)l 1 1 ' n n ' ] ■ 36 The properties of the assign function may be expressed by the following : Theorem 2.6.1 For all ao ; ao, ss and ss' we have ao if ss = ss' assn(ao, s : ao) • ss' = ao • ss f if ss ^ ss f The simple proof of the theorem is left to the reader. It may be also shown that the relation stated in the theorem uniquely determines assign that is if assign and assign' satisfy the relation then assign = assign'. An Extension for the Function assign The function assign defined so far can easily express replacement of a direct component of a composite object or an addition of a new component to it. In case we need to express replacement or addition of an indirect component we can do this by appropriate composition of assign functions. Example 2.6.h Let ao = (ss, : (ss p : ao 2 , ss~ : ao )) and suppose we wish to replace the component ao of ao by an object ao. The resulting object ao' should, therefore, be ao* = (ss : (ss p : ao, ss : ao )) 37 This transformation may be expressed by the following composition of assign functions ao' = assn(ao, ss,, assn(ao • ss , ss„, ao)) Indeed, we have now ao* • ss p • ss = ao and the other components of ao remain unchanged. To facilitate notation of assign function composition we can represent them by the extended assign function defined iteratively by Definition 2.6.2 assn(ao, c-I, ao; = ao assn(ao, ss ■ sel, ao) = assn(ao, ss, assn(ao • ss, sel, ao) ) Now the function assn(ao, sel, ao) is defined for any component selector sel. The function assn is, therefore, a function mapping (ao, sel, ao)-set int ao-set. Example 2.6.3 For the objects ao and ao 1 of example 2.6.k we have ao' = assn(ao, ss, • ss p : ao) Moreover, for s ^ s , k=l,2,3 we have assn(ao, ss, • ss, ao) = (ss.. : (ss : ao , ss„ : ao , ss : ao)) assn(ao, ss • ss,, ao) = ((ss_ : ao , ss„ : ao ), ss : (ss : ao)) In both cases, a new component ao has been added to ao. 38 We can also think of the assign function as an assignment operator. The value assn(ao, sel, ao) represents the result of an assignment of the object ao to the address sel in the object ao. If ao • sel ^ null then the function replaces an old component by ao, otherwise, it allocates a new component ao in ao. For the extended assn function the following identities hold assn (ao, sel, ao) • sel = ao assn(ao, sel • sel, ao) = assn(ao, sel, assn(ao * sel, sel, ao)) These identities are easily proved by induction on the length of sel. 2.7 Substitutions An important transformation of objects may be described by a substitution function subst. The value of subst(ao, eo, ao) results from ao by substituting a copy of ao for any sub-object of ao equal to eo. The function subst differs, therefore, from the function assn because now the content of a sub-object and not its address determines if it is to be replaced by ao. Definition 2.7.1 subst : (ao, eo, ao)-set -» ao-set subst (ao, eo, ao) = [ao g eo-set -> [ao = eo -> ao, true -» ao], ao = null -» null , ao = : ( s n :ao n , ..., s : ao ) ^ 1 1 n n 39 (s : subst (ao,, eo, ao), s : subst (ao,, eo, ao) n 1' ' ) ] Example 2.7.1 From the definition of the function subst we obtain subst(eo , eo , ao) = ao a a subst ( null , eo , ao) = null a Example 2.7.2 Let eo ^ eo and Then ao = (ss, : eo , ss~ : (ss„ : eo , ss, : eo ) ) 1 x 2 3 a 4 x subst(ao, eo , ao) = (ss, : subst (eo , eo , ao), 1 x' X " ss_ : subst((ss : eo , ss, : eo ), eo , ao) 2 3 a 4 x x ' ) = (ss : ao, ss~ : (ss,, : subst(eo , eo , ao), 3 ax 7 ssi : subst(eo , eo , ao) 4 xx ) ) = (ss, : ao, sSp : (ss„ : eo , ss. : ao) ko Thus in all the examples above subst(ao, eo, ao) is an object which results from ao by substituting ao for any eo occurring in ao. In example 2.8.6 we shall prove this is generally true for all ao, eo and eo. 2.8 Structural Induction In this section we shall discuss a technique for proving theorems based on a structural induction principle. The principle may be seen as the well known induction principle generalized to apply to ordered sets. To simplify presentation the structured, induction principle will be presented in this section in terms of abstract objects. The problem to solve is the following: Given x-set and p-set both subsets of ao-set, prove that every x satisfies is-p, i.e., V x[is-p(x)] If x-set is defined recursively the proof can be often simplified using the structural induction principle. Example 2.8.1 Let is-odd-eo be a predicate satisfied by any abstract object ao having an odd number of elementary objects, that is is-odd-eo(ao) - [ao e eo-set -» true ao = null -> false ao =: (s, : ao.,, ..., s : ao ) 1 1 n n is-odd-eo(ao ) © . . . © is-odd-eo(ao ) ] The symbol® is the disjunctive-or operator defined in example 1.6.1. kl Let us consider now the expr-set defined in example 2.3.8. It is readily seen that if expr e int-set or expr e var-id-set then is-odd-eo(expr ), Also we can check that i s- odd- eo( expr ). The proof that V expr[is-odd-eo(expr)] will be carried out in example 2.8.10 using the structural induction principle. • To prove the principle, two definitions and one lemma are needed. Definition 2.8.1 We say that ao' is less than ao and write ao' < ao if and only if ao f is a proper component of ao. ■ Example 2.8.2 For expr we have (s-op : + t s-1 : Y; s-r : 7) < expr, -I (9 < expr Q ) Definition 2.8.2 x is said to be a minimal element of x-set cz ao-set if and only if there is no x r such that x' < x. I If x-set contains elementary objects or null then they are obviously minimal elements of the set. Example 2.8.3 In expr-set defined in example 2.8.3 the set of minimal elements is int-set U var-id-set. I Example 2.8.U Assuming denotations of example 2.8.3* all elements of the set {5, Y, expr } are minimal. ■ Lemma 2.8.1 Every nonempty x-set <= ao-set has a minimal element. ■ Proof Suppose the lemma is false. Then for every x there exists x' such that x* < x. Thus for any x it is possible to build an infinite sequence x,., X.. , x^. . .. such that x n . is a component of x 1 for k > 0. Hence x_ 0' 1 2 k+1 * k - has infinite number of different components; this, however, is impossible because abstract objects are finite structures. Therefore, the lemma is true. E Now we have arrived at the structural induction theorem. Theorem 2.8.1 Let x-set, p-set c ao-set and is-p(x) whenever is-p(x') for all x' C where A = V x [Vx'[x' < x=> is-p(x')] => is-p(x)] C = V x[is-p(x)] Suppose A is true and C is false. Then the set {x|t is-p(x)} is not empty and, according to Lemma 2.8.1, it has a minimal element, for instance, x . . For that element is-p(x . ) is false, because mm -^ mm k3 x . e fxl-i is-p(x)}, and Vx f [x' < x . => is-p(x' )] is true, because min l ' r\ / >> l min x . is a minimal element of x-set for which is-p(x) is false. Thus the min formula Vx'[x f is-p(x f )] => is-p(x . ) mm ' mm' However, for any x . and all x' the relation x f < x . is false, mm mm ' therefore, Vx'[x' is-p(x')l is true so that is-p(x . ) is true. H mm tr\ /j xrv min ' To prove that is-p(x) for all x it is, therefore, sufficient to show that is-p(x . ) for all x . and that, for all x>x . , is-p(x) mm' mxn ' mm' ^ v ' follows when is-p(x' ) for all components x' of x. Example 2.8.5 With the notation of 2.8.1 let us prove that all expr have the property is-odd-eo. (s-op : op, s-1 : expr, , s-r : expr ) 1* Proof From the grammar of expr- set it is clear that any object expr satisfies one of the following formulae: (1) expr =: int (2) expr =: var-id (3) expr =: In cases (l) and (2), expr consists of exactly one elementary object and, therefore, satisfies is-odd-eo. In case (3) we have is-odd-eo(op) and if is-odd-eo (expr ) and is-odd(expr ) then obviously is-odd-eo (expr). Thus is-odd-eo (expr) for all expr. The structural induction theorem may be used to prove assertions about functions defined over objects. For example, if f is such a function and is-q is an assertion about it we can introduce the predicate is-p(ao) = is-q(f(ao)) and apply the theorem to is -p. Moreover, if is-p has many arguments, say ao and ao' then we can regard is-p(ao, ao* ) as a prediate with one argument ao and a fixed parameter ao'. If the assumptions of structural induction theorem with respect to ao are valid for all values of the parameter ao* then is-p(ao, ao 1 ) for all ao and all ao 1 . k5 Example 2.8.6 Let is-yes (ao, eo, ao) be true if and only if subst(ao, eo, ao) results from ao by substituting ao for any sub-object of ao equal to eo. We shall prove that is-yes is satisfied by any ao, eo and ao. Proof Let eo and ao be any fixed values, and let us consider the following cases : (1) ao e eo-set (2) ao = null (3) ao =: (s 1 : ao^ . .., s n : ao n ) It is readily seen that in cases (l) and (2) is-yes (ao, eo, ao) is always true. In case (3) we have, according to Theorem 2.6.1 subst(ao, eo, ao) = (s 1 : subst(ao , eo, ao), s : subst (ao , eo, ao) n n Suppose is-yes(ao', eo, ao) for all ao' < ao. Then is-yes(ao. , eo, ao) that is, in every direct component of ao all the sub-objects equal to eo have been replaced by ao. Thus every sub-object of ao equal to eo has been replaced by ao and is-yes (ao, eo, ao) is true. Hence, by structural induction, is-yes (ao, eo, ao) for all ao and, as the choice of eo and ao was not restricted is-yes is satisfied by any ao, eo and ao so that our theorem is proved. ■ k6 3. THE SYSTEM 3.1 The Definition The Semantics Definition System described in this report is a quadruple : (state-set, interpreter, instr-stack-set, tr-func) The states, interpreter and instr-stacks are abstract objects defined over some given eo-set and ss-set, so that state, interpreter, instr- stack e ao-set tr-func denotes a transition function. The above system components may be described briefly as follows. The state- set contains objects which are interpreted by the system. For example, if the system is used for semantic definition of a programming languages a state may consist of a program, input and output data and an environment needed to execute the program. For the description of states, we assume the existences of a set of elementary objects, state-eo-set, and a set of selectors, state-ss-set. In the following, state -set will be a subset of state-ao-set, where state-ao-set is the set of abstract objects over state-eo-set and state-ss-set. The set of all composite selectors over state-ss-set will be denoted by state- sel- set. hi The interpreter is an abstract object fixed for each application and describing the interpretation of states. The interpreter is usually- defined using the Process Definition Language PDL. The instruction- stack , instr-stack, provides an execution environment for the interpreter. Stacks have been defined in section 2.5 and instructions will be defined in section 3.3.1. tr-func is a transition function tr-func : (conf, interpreter) -set -* (conf-set)-set where conf denotes a configuration of the system: conf = (state, instr- stack) Thus, the value of tr-func is always a set of configurations: tr-func (conf, interpreter) = {conf, conf", ...} tr-func may be a partial function, that is, undefined for some interpreters or configurations. The definitions of instr- stack- set and tr-func, given in this report, are independent of any particular system application. Thus, for the semantic definition of a given language only state-set and the interpreter need to be defined. 3.2 Processes Any given Semantics Definition System determines a set of processes defined as follows. 48 Definition 3.2.1 A process generated in a system is a sequence of configurations conf, conf , conf , . . . such that conf is any element of the conf- set and conf n .. e tr-func(conf n ) for k > k+1 k — The generation of a process may be visualized as follows. The process is started with an initial value conf . Usually, the selection of conf is limited to some initial- conf- set, which depends on a particular system application. The successor configuration, conf,, can then be determined by a selection of one element of tr-func(conf ). In the similar way we get successive configurations of the sequence. In each process generation step one of the following situations may be encountered. (1) tr-func(conf n ) = null k In this case the process cannot be continued and conf is called a final configuration of the process. Thus, the process is finite and called terminating . Processes which are infinite sequences are called nonterminating . (2) tr-func(conf ) = {conf) In this case conf, , = conf* and the next configuration is determined uniquely. (3) tr-func(conf ) = {conf, conf", ...} h9 In this case we have more than one element for the choice, as any set element may be selected as the successor configuration conf . For example, if a process describes the summation of vector components, the order of the summation — from left to right or from right to left — may be left open by the definition. If such a specification is needed, for instance, to implement a practical computation then it may be given by an additional rule. (k) tr-func is not defined for conf. For example, if in a process step we try to add two values but one is not a number then the next configuration may not be defined. If such a process is implemented on a computer then the computation may stop or continue depending on supplementary rules adopted for the implementation. A system is called deterministic if the value of the transition function never has more than one element. Otherwise, the system is called nondeterministic . 3.3 Interpreters 3.3.1 The Definition The interpreter system component is especially important for the definition of the transition function. The interpreter is a fixed object, never changing in the course of a process. Interpreters are defined by the following grammar: (1) is- interpreter = is-({is-proc-id : is-proc-des) ) (2) is-proc-des = is- (par-id- list, instr) (3) is-instr = is-(instr-id, arg-list) 50 (k) is-arg = is-S v is-state-ao v is-state-sel v is-func-des \/ is-par-id v is-instr (5) is-func-des = is-(func-id, arg-list) In the grammar the abbreviations introduced in definition 2.3.^- are often used. For instance, in (2) instr is the abbreviation of s-instr : is-instr. The rules may be briefly annotated as follows: (1) Any tagged object proc-id : proc-des is called a procedure . Thus, the interpreter is a set of procedures. Since interpreter is an abstract object, all procedure identifiers must be mutually distinct. (2) A procedure designator proc-des is composed of an instruction usually called the procedure body , and a parameter identifier list, possibly nil . We require that the instruction contains only those parameters, which are present in the par-id- list. (3) An instruction is composed of an instruction identifier, instr-id, and a possibly empty argument list. Instr-id refers to one of predefined set of instructions or is a procedure identifier, proc-id. (k) Objects of many types may appear as an instruction argument. It may be the symbol S, the only object satisfying predicate is-S. This symbol is used to denote the current state. State-ao-set and state-sel-set have been introduced in section 3.1. (5) A function designator contains the function identifier and a list of arguments of the same type as the ones used in instructions. Example 3.^-.l Let t e par-id- set, loop-instr e instr- set and loop e proc-id- set. Then the tagged object 51 loop : (s-par-id-list : , s-instr : loop-instr) is a procedure. The second element of the pair satisfies is-proc-des. Example 3. if. 2 Let bin-op e func-id-set and X e state-ao-set. Then the object (s-func-id : bin-op, s-arg-list : <+, 5> x>) satisfies is-func-des. Example 3.^.3 Let intp-program, loop € proc-id-set compound € instr-id-set t € par-id- set loop-instr e instr-set Then is-interpreter is satisfied by the object (intp-program : (s-par-id-list : nil , s-instr : instr), loop : (s-par-id-list : , s-instr : (s-instr-id : compound, s-arg-list : )> ) ) ) For instr any object satisfying is-instr may be substituted. 52 3.3.2 The Basic PPL The examples of the last section illustrate how interpreters may be represented using the general notation introduced so far. The resulting description, however, is difficult to read and unnecessarily long. Thus, to facilitate an interpreter and thereby a process definition, a special Process Definition Language, PDL, is introduced in this report. To general expressions for abstract objects, PDL adds a number of contraction for some frequently used interpreter constructs. The full PDL will be defined in section 3-5. The contractions of so called basic PDL are presented below: (1) £ roc(par-id 1 ,...,par-id m ) j instr d = f (s-par-id-list : , s-instr : instr) (2) instr-id(arg n , . . .,arg ) 1 m df (s-instr-id : instr-id, s-arg-list : ) 1 m df (3) label-id : label = (s-intr-id : label, -arg-list : ) (k) fd func-id(arg n , . . .,arg ) = — 1 m (s-func-id : func-id, s-arg-list : ) In the definitions m > is assumed. If m=0 then the parenthesis enclosing an empty argument list may be omitted. If instr-id = label then we have a pseudo-instruction serving to introduce a label. The symbol fd used in contraction (k) serves to distinguish a function designator from the value of a function having identical name. The symbol is useful in some definitions, but in interpreters descriptions it may be omitted entirely. To this end the rule holds that if the expression 53 func-idCarg^ .. .,ar^) is used as an argument of either an instruction or another function designator then it denotes always a function designator and the symbol fd need not be used. To more easily distinguish between function designators and procedures we assume that func-id-set proc-id-set = null . Example 3.5.1 The procedure description presented in example 3.^.1 inay be contracted to loop : proc (t ); loop-instr This phrase, when interpreted according to the contractions, implies that t e par-id- set and loop-instr e instr-set. ■ Example 3.5-2 The function designator presented in example 3.^.2 may be denoted now as fd bin-op (+, 5, X) This phrase implies that bin-op € func-id-set. ■ Example 3-5-3 The interpreter presented in general object notation in example 3.^.3 may be defined in PDL by (intp-program : proc ; instr, loop : proc(t); compound (t, loop(t))) 54 3.4 The Transition Function In this section the transition function, tr-func, is defined in detail. 3.4.1 Argument Values The value of the argument of a function or an instruction is given by Definition 3-4.1.1 val : (arg, state)-set -> state-ao-set U state-sel-set val (arg, state) = [arg = S -* state, arg -: fd func-id (arg-., . . . ,are ) -* func-id (val( arg , state), ..., val (arg, state)) arg e state-ao-set U state- selset -» arg ] Note that for arg =: par-id or arg =: instr the function val is not defined. The definition may be briefly annotated as follows. The value of symbol S is the current state. If arg is a function designator having func-id as a s-func-id component then the value of arg is the value of the function func-id applied to the value of the function designator arguments. Thus, to define the value of a function designator fd func-id (arg.., ..., arg ) 55 we have to define the function func-id : (x , . . .,x)-set -> state-ao-set U state-sel-set The domains of x. must include the ranges of val(arg., state). 1 1 If arg is equal to a state-sel or to a state-ao (distinct from a function designator) then the value of arg is arg itself. If arg e state-co-set then its value is clearly given by the definition. The value of an instruction or a parameter identifier is not defined. Example 3.^.1.1 val(s, state) = state val(fd bin-op(+, 5, X), state) = bin-op(+, 5, val(X, state)) 3.J+.2 The Instruction Stack The instruction stack may be any object satisfying is-instr-stack, for example instr- stack = instr. instr„ . . . instr null 12 n Given a system configuration conf = (state, instr- stack) the next state depends on the state and on the top element of the instruction stack (in our example instr ). Thus, sometimes we say the transition of the configuration is the result of executing the top instruction of the stack. As one result of the transition, the top instruction is either deleted or % replaced by one or more instructions. If the instruction stack becomes empty, then a final configuration has been reached. 3.U.3 Instruction Types The behavior of a given instruction depends on its type. We distinguish seven instruction types, six of them are determined by the following instruction identifiers : assignment, conditional, compound, choice, label, skip If the instruction identifier is a procedure identifier then we distinguish the seventh instruction type, called a procedure call . To facilitate the description the following abbreviations will be used: in-top = instr- stack • s-top in-tail = instr- stack • s-tail a-list = in-top • s-arg-list arg. = a-list • [i] p-des = interpreter • (in-top • s-instr-id) p-list = p-des • s-par-id-list p-body = p-des • s-body The abbreviations denote the following objects: in-top denotes the top instruction of the instruction stack. in-tail denotes the tail part of the instruction stack. a-list denotes the argument list of the top instruction of the stack. arg . denotes i-th argument of the a-list. 57 p-des denotes the procedure designator selected from the interpreter by the instruction identifier of in-top. p-list is the parameter identifiers list of p-des. p-body is the body of p-des. The following briefly describes the execution of instructions of every type. 3.U.3.1 Assignment Instruction If in- top =: assignment(arg , argp ) then state' = assn(state, val(arg,, state), val(arg^, state)) and instr- stack' = in-tail Thus, the state has been changed to a new state* and the instruction itself has been deleted from the instruction stack. The assignment instruction is the only one which may change the state. The execution of the assignment instruction is defined if and only if val(arg,, state) e state-sel-set val(arg , state) e state-ao-set U state-sel-set Example 3- ^■•3.1 Let Then instr- stack = assignment (s-a, 10) '" instr p " null state* = assn( state, s-a, 10) instr- stack' = instr null 58 3.^.3.2 Conditional Instructions If in-top =: conditional(arg, instr-., instr Q ) then where state * = state instr- stack' = instr in-tail instr = [val(arg, state) -* instr, , n val(arg, state) -* instr p ] Thus, the conditional instruction is replaced in the stack by either instr, or instr p , depending on the state- arg value. A conditional instruction is defined only if val(arg, state) e bool-set Example 3.^.3.2 Let instr- stack = instr instr„ null 59 where instr = conditional^ (x > 0;, instr,, instr p ) Then state' = state and if val((x > 0), state) = true then instr- stack' = instr instr null if val((x > 0), state) = false then instr- stack* = instr p instr- null 3.^+.3.3 Compound Instructions Let in-top =: compound( instr,, . .., instr ) Then state' = state and instr- stack' = instr, ... instr in-tail 1 n Thus, the compound instruction has been replaced by its component instructions. Example 3.^.3.3 Let instr- stack = compound (instr , instr ) instr p null Then instr- stack' = instr instr. instr,, null a b 2 6o 3.^.3.^- Choice Instructions If in-top =: choice ( ins t,, ..., instr ) 1' ' n then state' = state and instr- stack' = instr ' in- tail where instr e f instr.,, ..., instr ) L 1 n J Thus, the choice instruction is replaced by one of its components -which one, however, is not specif iced. Example 3.^.3.^ Let instr- stack = choice (instr , instr, ) " instr~ " null a b 2 Then, depending on the choice made, we have instr- stack' = instr instr " null a d or instr- stack' = instr instr p null 3.^.3-5 Label Instruction If in- top =: label : label 61 then state' = state and instr-stack' = in-tail. Thus the label instruction simply removes itself from the instruction stack. The label instruction may be considered as a pseudo- instruction, serving only to introduce a label into the instruction stack. An example of the label instruction is given in the next section. 3. ^-.3. 6 Skip Instruction If in-top =: skip (label-id) then state' = state and instr-stack' = reduced (in-tail, label-id) where the function reduced is defined as follows: reduced (in-tail, label-id) = [in-tail = null -* null , in-tail • s-top • s-label = label-id -* in-tail, true -* reduce (in-tail • s-tail, label-id) ] Thus, the instruction skip (label-id) removes from the instruction stack all instructions preceding the first label instruction, with label-id as its argument. If no such instruction exists then all instructions are removed from the stack so that it becomes empty. Example 3.^.3.6 Let instr-stack = skip(l) " instr ~ 1 : label ~ instr~ " null 62 where instr p is not a label instruction. Then state' = state and instr-stack' = 1 : label instr null 3.U.3.7 Procedure Calls If in-top =: proc-id(arg , ..., arg), m> then state* = state and instr- stack = instr in-tail where instr = subst-list(p-body, p-list, a- list) The function subst-list may be defined by the function subst, introduced in section 2.7. Definition 3.^.3.7 subst-list : (ao, eo-list, ao-list)-set -» ao-set The value of the function is defined as follows: subst-list(ao, eo-list, ao-list) = [eo-list = nil ^ ao-list = nil -> ao, eo-list =: ^ ao-list =: -» 1 1 subst(ao, eo , ao ), eo-list =: ^ 1 ' n+1 ao-list =: -> r ' n+1 subst(subst(ao, , 1' n ' ), 1 n eo n+l> a( W 63 The new top instruction, therefore, results from the body of the selected procedure by replacing all parameters par-id. by the arguments arg„. (0 < i < m). A procedure call is defined if and only if a) p-des -f null , that is, the interpreter contains the procedure being called. b) leng(a-list) = leng(p-list ), that is, the number of the instruction arguments is equal to the number of parameter identifiers in the procedure. Example 3.4.3.7 Let instr- stack = pc(arg , ..., arg ) instr p null , pc e proc-id-set and interpreter • pc = p_roc(x,, . . .,x ); body(x , ...,x ) where x. e par-id-set and body(x , ...,x ) is the selected procedure body represented as a function of x, ,...,x . Then instr-stack* = body(arg, , ..., arg ) instr p null 3.4.4 The Formal Definition This section presents the formal definition of the transition function. Definition 3.4.4.1 tr-func : conf-set ~* (conf-set)-set Gh The value of tr-func is defined by tr-func(( state, instr-stack)) = [in-top = null -* null , in-top = : assignment(arg , argp ) -* { ( as sn( state, val(arg ), val(argg)), in-tail)}, in-top =: conditional (arg, instr, , instr„) -* { (state, [val(arg) -* instr,, - val(arg) -» instr p ] in-tail)}, in- top =: c ompound( instr , ..., instr ) -» {(state, instr, ... instr in-tail))}, in-top =: choice (instr, , ..., instr ) -> {(state, instr.. in-tail), ..., (state, instr in-tail)}, in-top =: skip (label-id) -» {(state, reduce (in-tail, label-id))}, in-top =: proc-id(arg,, ..., ar g^) ^ (m > 0) -» { (state, subst(p-body, p-list, a- list) in-tail)} ] Thus, the value tr-func (conf) is defined if the instruction stack is null or the top instruction in-top is equal to one of the instructions listed in the definition. Moreover: 65 a) In the case of an assignment instruction: val(arg, ) € state-sel-set val(arg ) € state-sel-set U state-ao-set b) In the case of a conditional instruction: val(arg) e boo 1- set c) In the case of a procedure call: p-des fi null leng(a-list) = leng(p-list) and every procedure designator contains only those parameter identifiers, which are present in its par-id- list. 3.5 A Process Definition Language In section 3.^.2 the basic Process Definition Language, PDL, has been described. The language introduces a number of contraction making the notation of an interpreter shorter and the transition function definition clearer. The extended PDL, or simply PDL, introduced in this section, includes basic PDL, a few standard functions and some additional contractions, It is designed with the idea that the interpreter described in PDL will look like a program written in a higher level language. 3.5.1 Instructions 3.5.1.1 Special Instructions Let never-used denote a label never used a label instruction argument and stop = skip (never-used) 66 Thus, "stop" clears the instruction stack and terminates the process, To indicate that the next system configuration is not defined the following abbreviation may be used: undefined = choice ( ) The instruction choice with empty argument list is undefined. The instruction denoting no action except the transition to the next instruction may be defined by: df skip = begin 1 : label end where 1 is any label. 3.5.1-2 Assignment Instruction arg 1 := arg 2 df assignment (arg,, argp) The instruction may be read "arg, becomes arg„." 3.5.1.3 Compound Instructions begin instr, ; . . . ; instr end — a — 1' n compound (instr,, . .., instr ) The symbols begin and end may be omitted if and only if the compound instruction contains more than one instruction and it is written between than and else , between else and fi or between loop and repeat . 3.5.1.^ Conditional Instructions if arg then instr, else instr p fi = conditional (state-arg, instr,, instr p ) 67 Example 3. 5. 1.1+ . 1 The expression if (a > b) then s-a := S • s-b else instr, ; instr p fi denotes the instruction conditional ((a > b), assignment (s-a, S • s-b), compound (instr,, instr p ) ) Deeply nested conditional instructions are sometimes difficult to read. Thus, to make the relation more transparent the following contractions are defined: ef state-arg then instr, else instr p fi = else if state-arg then instr else instr p fi fi then instr fi = then instr else skip fi Example 3.^.1.^.2 The expression if arg, then instr, ef argp then instr p ef arg,. then instr„ fi denotes 68 if arg, then instr-, else if argp then instr p else if arg then instr_ else skip fi fi fi 3.5.1-5 Loop Instruction The basic set of PDL instructions does not include any special construct to describe repetitive execution of an instruction. Such construct, however, may be readily defined. We shall assume as a standard the following procedure: loop : proc (t); begin t, loop (t) end It is easy to see that the call loop (instr) results in iterative execution of the instr. The iteration can be terminated only by a skip instruction, which is contained in the instr and "skips over" the end of the loop. Hence, we introduce notation loop instr repeat = begin loop (instr); loop- exit : label end break = skip (loop-exit) 69 Note that it is never possible to skip to loop-exit label from outside the loop. The break instruction, therefore, terminates the smallest enclosing loop. To avoid conflicts, label identifier loop-exit should never be used elsewhere. Whenever a loop instruction is used, we assume that the standard loop procedure is included in the interpreter. Example 3. 5.1* 5-1 Using loop and break instructions some other repetitive instructions may be introduced, for instance while p do instr od = loop_ if i p then breake fi ; instr repeat I 3.5.1.6 Collateral Instruction Given a sequence of instructions, the order in which they are executed is sometimes irrelevant. This may be expressed by the following instruction: collat (instr.,, ..., instr ) = 1' n y choice ( begin instr ; . . . ; instr end , begin instr ; ...: instr, end) 70 The instruction "choice" has n! arguments, each one being a distinct permutation of instr,; ...; instr . Example Let instr-stack = collat (instr , instr, ) " instr„ null a 7 b' 2 Then state' = state and instr-stack' is equal either to instr instr, instr~ null a b 2 or to instr, instr instr^ null b a 2 3.5.2 Standard Functions 3.5-2.1 Selector Applications It is often convenient to express a simple selector as the value of a function designator. To form a composite selector from simple selectors expressed in this way, a special function designator, apply-sel, may be used. Its value is defined by Definition 3-5.8.1 apply-sel : (t, s,, ..., s )-set -» t-set > where t-set = state-ao-set U state-sel-set and s. e state-sel-set. The i value of the function is apply-sel (t, s n , ..., s ) = t • s n • ... • s ' 1' ' n 1 n 71 Thus, if t e state-ao-set the function value is an abstract object and if t e state-sel-set then the function value is a selector. To facilitate notation, the following contraction may be used: fd t • s • ... • s = fd apply- set (t, s,, . .., s ) Again, in writing an interpreter, the symbol fd may be omitted. The value of apply- sel function designator is val (fd t • s n • ... • s , state) = — 1 n' apply-sel (val(t, state), val (s , state), ..., val ( s , state ) ) = n val (t, state) • val (s., state) • ... • val (s , state) Example 3.5.8.1 The expression S • s-store • [(5+1)] denotes an abstract object fd apply-sel (S, s-store, fd s-elem (fd bin-op(+, 5,1)) ) The value of the expression is val(S • s-store • bin-op (+, 5,1), state) = val(S, state) • val (s-store, state) • val(bin-op(+, 5>l)> state) = state • s-store • [6] 72 3.5-3 Standard Operations To describe standard operations, the following (partial) functions un-op and bin- op are introduced: un-op : (op, ao)-set -> ao-set bin-op : (op, ao, ao)-set -> ao-set For the standard op-set the values of the functions are: val (un-op (op, ao), state) = op val(ao, state) val(bin-op(op, ao , ao ), state) = val(ao , state) op val(ao, state) As the standard operator set we assume standard- op- set {+, -, *, /, mod , -, £, <, <, >, >, -, ", ^} This set may, of course, be extended as necessary. If no comment on the operators is made they have the standard mathematical meaning operator / applied to integer results may render a real result. Examples 3-5.7.1 un-op(-,, false ) = true bin-op (+, 3, 8) = 11 bin-op(/, 2, 5) = 0.1+ 73 To facilitate interpreter notation, the following constructions will be used: (op state-ao) = fd un-op(op, state-ao) (state-ao op state-ao p ) = fd bin- op (op, state-ao, state-ao ) Examples 3.5-7.2 (-5) denotes fd un-op(-, 5) (3+8) denotes fd bin-op(+, 3, 8) val((-5)^ state) = -5 val((3+8), state) = 11 Parenthesis enclosing first argument of a conditional instruction or arguments of an assignment instruction may be omitted. Example 3.5.7.*+ The instruction s-a := x + 1 denotes s-a := (x+l) or, in basic PDL assign(s-a, fd bin-op(+, x, l)) 7^ 3.5.^- Other Conventions 3.5.^.1 Content Expressions For any selector the following contraction is defined: t sel = S • sel For the new symbol we have val(t sel, state) = state • sel Thus, t sel is evaluated as the state component selected by sel. Example 3.5.3.1 Let s-a, s-b e state-ss-set. Then t s-a or f s-a are contractions of S • s-a. If c-ab = s-a • s-b then t c-ab is a contraction of S • c-ab. The value of this expression is state ■ c-ab. 3.5. ^.2 Comments Comments may be written inside an interpreter. They are enclosed in curly brackets { }, for instance {a > 1) . 75 h. Simple Applications i+.l A Computer In this section we shall show how' the Semantics Definition System may be used for the formal description of an actual computer. Some computer components, for instance, input and output, will be omitted and only a few computer instructions described. Some computer structures, for instance, words, will not be discussed in detail. The following definition may be easily extended to cover these aspects. The assumed computer scheme is shown in Figure 4.1.1. The computer state may be expressed by is-state = is- (store, ace, xr, ic, ir) The direct components of the state are defined by is-store = is-word-list is-acc = is-word is-xr = is-addr is-ic = is-addr is-ir = is-instruct is-instruct = is- (code, i-bit, x-bit, addr) * See H. Zemanek, Abstrakte Objekte, Elektronische Rechenanlagen, Vol. 10 (1969), 5, PP. 208-216. M store 76 ace (accumulator) xr (x-register) ic (instruct -counter) I ! I i i i _l I !_ code i x addr ir (instruct-register) Figure U.l.l A Computer Scheme 77 Note that computer instructions, instruct, are distinct from PDL instructions, instr. A word could be easily defined as a bit-list, but for the moment such representation is of no interest to us. Thus, we define word-set as the set of word-values w. (i=0,l, . . .,N). The words, addresses, codes and bits are assumed to be elementary objects given by: word-set = {w_, w,, ..., w } (N > 0) addr-set = {0, 1, ..., max-addr} code- set = {L, ST, A, BZ, HLT} bit- set = {0, 1} The codes are assumed to be identifiers. Thus, we may assume state-eo-set = word-set U addr-set U inst-id-set U bit-set state-ss-set = {s-store, s-acc, s-xr, s-ic, s-ir, s-code, s-i-bit, s-x-bit, s-addr} It is occasionally important that instructions and integers can be represented by words and vice versa, words can represent integers. To this end the existence of the following functions is assumed: instruct-rep : word-set -* instruct-set int-rep : word- set ->• int-set word-rep : int-set -» word- set 78 For example, instruct-rep (word ) denotes the instruction represented by word and word-rep (int ) denotes the word representing int . a To facilitate the interpreter description the following abbreviations will be used: c-code ~ s-ir • s-code . , . , df . . , . , c-i-bit = s-ir • s-i-bit c-x-bit = s-ir • s-x-brb c-addr = s-ir • s-addr c-cell = s-store • [f c-addr + 1] Thus, c-cell is the selector of a store word. The "address" of the word is determined by the s-addr component of the instruction register. Now, the interpreter may be written. It is presented at the end of this section and briefly described as follows. For the initial configuration of the instruction stack we assume instr- stack = main- cycle null The main-cycle instruction calls the main-cycle procedure. Its body consists of a loop instruction. Inside the loop we have a compound instruction composed of four interpreter instructions. The first one assigns a new computer instruction to the instruction register ir. The second adds one, modulo max-addr, to the instruction counter ic. The third and fourth are procedure calls. The body of the procedure modify- address is a compound instruction composed of two conditional instructions. If i-bit of the instruction 79 register contains 1 then the s-addr component of the instruction register is replaced by a new address. Then, if x-bit of the instruction register contains 1, the content of the x- register is added (modulo max-addr) to the same component. The perform- operation procedure describes how particular computer operations are performed. For instance, if the s-instr-id component of the instruction register contains L then the value of t c-cell is assigned to the accumulator. If the value of t c-code is HLT then the intepreter execution is terminated. Interpreter The interpreter is defined by the following object: (main- cycle : proc ; loop s-ir := instruct-rep( t s-store * [t s-ic]); s-ic := (t s-ic + l) mod max-addr; modify-addr; perform- ope rati on repeat , modify-addr : proc ; begin if t c-i-bit = 1 then c-addr := (instruct-intp( t c-cell)) * s-addr fi \ if t c-x-bit = 1 then c-addr := (t c-addr + t s-x) mod max-addr fi end, 80 perform-oper : proc ; if t c-code = L {load) then s-acc : = t c-cell ef t c-code = ST {store} then c-cell := t s-acc ef t c-code = A {add} then s-acc := word-rep(int-rep(t s-acc) + int-rep(t c-cell)) ef t c-code = BZ {branch on zero} then if int-int (t s-acc) = then s-ic := t c-addr fi ef t c-code = HLT {halt} then stop fi) k.2 Arithmetic Expressions lj-,2.1 Expression Values Let us consider the class of objects expr-set defined in example 2.3.8. The class contains, for instance, expr„ = (s-op : *, s-1 : X, s-r : expr, ) where expr = (s-op : +, s-1 : Y, s-r : 5) To compute a value of an expression the values of variable identifiers have to be known. To this end the existence of the following function is assumed: cont : (var-id, state )-set -* int-set 81 The cont (var-id, state) is the value of the var-id; it is called the var-id content . The dependence on state indicates that the content of var-id may vary during a process. Now, the value of an arithmetical expression may be defined by Definition U.2.1.1 ve : (expr, state)- set -> int-set ve (expr, state) = [expr =: int -* int, expr =: var-id -+ cont (var-id, state), expr =: (s-op : op, s-1 : expr,, s-r : expr p ) -» bin- op (op, ve(expr, , state), ve(expr p , state))] It may be easily seen that a value for any expr depends on a state only because the values of var-id depend on it. The definition assigns a value to any arithmetical expression but does not specify how to compute it. Two algorithms, serving this purpose, will be given in sections h.2.,2 and U.2.3. Example If. 2. 1.1 Let cont(X, state) = 2 and cont(Y, state) = 7 Thus, the value of expr„, given at the beginning of this section, is ve(expr„, state) = bin-op (*, ve(X, state), ve(expr, , state)) where v However, .expr.., state) = bin-op(+, ve(Y, state), ve(5, state)) ve(X, state) = cont(X, state) = 2 ve(Y, state) = cont(Y, state) = 7 ve(5, state) = 5 Hence, ve(expr.,, state) = bin-op (+, 7, 5) = 12 ve(expr , state) = bin-op(*, 2, 12) = 2k Thus, the value of expr n is 2k. k.2.2. A Deterministic Computation For this case we assume is- state = is-(expr, stack) The s-expr component is the expression to be evaluated- -we assume that it does not change duringthe entire computation. The stack component provides an environment for the expression evaluation. At the end of the evaluation the result is located at the top of the stack. The rest of the stack remains unchanged. Example U.2.2.1 Suppose the initial state is state^ = (s-expr : expr„, s- stack : 3 null ) 83 where expr n is defined in section U.2.1. Then, when the process is terminated, the final state value should be state = (s-expr : expr , s-stack : 2k 3 null ) The number 2h is the expr„ value, according to example U.2.1.1. For the initial value of the instruction stack we assume instr-stack = intp-expr( s-expr) null The interpreter defining the process is presented at the end of this section. It is composed of three procedures: intp-expr, push and bin-oper. They may be briefly described as follows. intp-expr is the. main procedure of the interpreter. It is called first, it is recursive and it uses push and bin-oper procedures as subroutines. The push procedure places its argument on the top of the stack. The bin-oper procedure removes the elements a, and a p from the stack, computes bin-op (op, a,, a^) and places the result on the top of the stack. Theorem U.2.2.1 Let us assume all the definitions introduced in this section and state- = (s-expr : expr, s-stack : stack) Then the process generated by the system terminates and, in the final configuration, we have state = (s-expr : expr, s-stack : ve(expr) stack) Qk Proof The theorem results from the following assertion: for any c-expr such that is-expr( state • c-expr), the call intp-expr (c-expr) computes the value of expr' = state • c-expr and pushes it on the top of the stack. To prove the assertion let us consider the following cases. If expr' =: int then is-int(t c-expr) is true and push (t c-expr) is performed. Thus, evidently, the assertion is true. If expr* =: var-id then we can similarly show that the assertion is true. If expr' =: (s-op : s-1 : expr.^ s-r : expr p ) and the assertion is true for expr, and expr then, as may be readily demonstrated, the assertion is true for expr'. Hence, according to the structural induction theorem, the assertion is valid for all expr'. Thus, the theorem is proven. The Intepreter (intp-expr : proc (c-expr); if is-int(t c-expr) then push(t c-expr) ef is-var-id(t c-expr) then push(cont(t c-expr, S)) ef is-bin-expr( t c-expr) then intp-expr (c-expr * s-l); intp-expr (c-expr • s-r); b in- oper( c-expr • s-op) push : proc (int) ; ; s- stack := int t s- stack, 85 bin-oper: proc ( op ) ; s-stack := a t s-stack • s-tail • s-tail {where a = bin-op(op, a,, a ) and a. = t s-stack • s-top(i)} ) U.2.3 A Nondeterministic Computation For this section we assume is-state = is-(expr) state- = (s-expr : expr) instr-stack = intp-expr( s-expr) null The interpreter is given at the end of this section. The interpreter procedure, intp-expr, uses instruction collat and the process is not deterministic. Theorem U.2.3.1 Assuming definitions given in this section the process generated by the system terminates and in the final configuration we have state- = (s-expr : ve(expr)) Thus, the initial expression is replaced by its value. ■ The proof is similar to the one presented in the former section. 86 Interpreter (intp-expr : proc ( s-expr ) ; if is-var-id(t s-expr) then s-expr := cont(t s-expr, S) ef is-bin-expr( f s-expr) then collat( intp-expr (s-expr • s-1), intp-expr (s-expr •. s-r)); s-expr := bin-op (t s-expr • s-op, t s-expr • s-1, t s-expr • s-r) fi ) 87 References 1. McCarthy, J. "Towards a Mathematical Science of Computation. " In Information Processing 1962, North Holland Publ. Co., 1962. 2. McCarthy, J. "A Formal Description of a Subset of Algol." In Formal Description Languages (T. B. Steel, Jr., ed), North-Holland Publ. Co., 1964. 3. Burstall, L. M. "Proving Properties of Programs by Structural Induction." Comp. Journal , 12, No. 1, kl-kQ, 1969. k. Lukas, P. and Walk, K. "On the Formal Description of PL/ 1. " Annu. Rev. Automat. Program , 6, Part 3, 105-182, 1969. 5. Wegner, P. "The Vienna Definition Language." A. CM. Comp. Surveys , k, No. 1, 5-63, 1972. 6. Ollongren, A. Definition of Programming Languages by Interpreter Automata, Academic Press, London, 197^. UBLIOGRAPHIC DATA HEET 1. Report No. UIUCDCS-R-76-773 3. Recipient's Accession No. Title and Suht it lc A Semantics Definition System (A Preliminary Description) 5- Report Date January, 1976 . Author(s) Leon Lukaszewicz 8. Performing Organization Rept. No. Performing Organization Name and Address Department of Computer Science University of Illinois Urbana, Illinois 10. Project/Task/Work Unit No. 11. Contract /Grant No. 2. Sponsoring Organization Name and Address Department of Computer Science University of Illinois Urbana, Illinois 13. Type of Report & Period Covered 14. 5. Supplementary Notes 6. Abstracts A simple and universal system for the semantics definition of programming languages is presented. The system includes a state set, and interpreter, an instruction stack set and a transition function. A few examples of semantics definitions are given. The definitions are easy to read, allow an intuitive understanding of the languages and provide a base for a feasible language implementation. 7. Key Words and Document Analysis. 17a. Descriptors programming languages definition semantics interpreter 7b. Identifiers/Open-Ended Terms 7c. C.0SATI Field/Group 8. Availability Statement 19. Security Class (This Report) UNCLASSIFIED 20. Security Class (This Page UNCLASSIFIED 21. No. of Pages 22. Price °RM NTIS-35 (10-70) USCOMM-DC 40329-P71 o ~^