The meta-language - Springer Link

33 downloads 0 Views 2MB Size Report
language semicolon operator has been formally defined and there is no element of circularity in such a link between object and meta-l~nguage. It would be ...
THE META-LANGUAGE:A REFERENCEMANUAL

Cliff B.Jones

Abstract: The recent work of the Vienna Laboratory on the sub= ject of semantic definitions has used the "denotational semantics"

approach. Although this is a clear break

with the earlier abstract interpreter approach,

the

newer meta-language has tried to preserve and even improve upon the readability of the earlier "VDL" no = tation. The meta-language described here has been used in the definitions of large programming languages and systems. This paper is not a tutorial;

rather it pro =

vides a reference document for the meta-language.

CONTENTS

0.

Introduction

220

I.

Logic Notation

223

2.

Elementary Objects

224

3.

Composite Objects

225

3.1

Sets

226

3.2

Pairs

228

3.3

Maps

228

3.4

Tuples

230

3.5

Trees

231

3.6

Functions

232

3.7

Implicit Definition

235

4.

Object Description

236

5.

The r61e of "undefined"

239

6.

Defining Semantics

240

6.1

States & State Transitions

241

6.2

A Macro-expansion Process

243

6.3

Simplifying Extended Expressions

251

6.4

Basic Combinators

258

6.5

Other Issues

258

APPENDICES I

Concrete Syntax

261

II

Conventions

265

III

Example definition

266-277

220

0. I N T R O D U C T I O N Q

This paper is intended to p r o v i d e a r e f e r e n c e d o c u m e n t w h i c h d e s c r i b e s the m e t a - l a n g u a g e used t h r o u g h o u t this volume.

It is equally i m p o r t a n t

to a p p r e c i a t e w h i c h o b j e c t i v e s are not b e i n g aimed for here. On the one h a n d this d o c u m e n t is d e f i n i t e l y not a tutorial, neither for den o t a t i o n a l semantics nor for the specific m e t a - l a n g u a g e used. of this paper no m o t i v a t i o n at all is provided,

In m u c h

the reader who is not

familiar w i t h the general ideas is r e c o m m e n d e d to read Bj~rner 78b before a t t e m p t i n g to use this paper. On the other h a n d this d o c u m e n t does not p r o v i d e a formal

"foundation" for the m e t a - l a n g u a g e in the

style of, say, Mosses 75.

The a i m of this

"reference manual"

is to p r o v i d e a d o c u m e n t w h e r e

readers or writers of the m e t a - l a n g u a g e can find a d e s c r i p t i o n of its constructs in terms of some other notation. As such, this d o c u m e n t does not n e c e s s a r i l y i n t r o d u c e all terms and n o t a t i o n in a strict leftt o - r i g h t order.

The n o t a t i o n to be i n t r o d u c e d is p r i m a r i l y intended for the purpose of d e f i n i n g languages or systems using the a p p r o a c h k n o w n as "denotational semantics";

a l t h o u g h it can also be used as a sort of p r o g r a m m i n g lan-

guage this is not its purpose. A general

"denotational" a p p r o a c h can

be expected to yield a d e f i n i t i o n w h i c h can be viewed in four parts:

~)

A b s t r a c t syntax of the language to be studied

~)

Context Conditions

~)

S e m a n t i c Objects

~v)

M e a n i n g function(s)

Before e m b a r k i n g on d e f i n i n g the m e a n i n g of a language it is o b v i o u s l y e s s e n t i a l to fix w h a t

("object")

language is to be studied:

the task of the first two parts of a definition.

this is

The a b s t r a c t syntax

defines a class of objects w h i c h are abstractions of the actual texts of the language. syntax:

(The class of texts w o u l d be d e s c r i b e d by a c o n c r e t e

this subject is w i d e l y d o c u m e n t e d and in c o n s e q u e n c e need not

occupy space here).

The a b s t r a c t s y n t a x of a language is "context free"

and it is thus impossible to r e s t r i c t the class of a b s t r a c t texts to those which are o b v i o u s l y meaningful.

For example,

in a p r o g r a m m i n g

language it is impossible to specify that all valid programs m u s t use only d e c l a r e d identifiers. the m e a n i n g functions,

Rather than leave such c h e c k i n g to cloud

a s e p a r a t e section defines p r e d i c a t e s over the

221

objects of the a b s t r a c t syntax.

Such p r e d i c a t e s define a sub-set of

the objects w h i c h are s p e c i f i e d by the a b s t r a c t syntax;

those objects

w h i c h s a t i s f y the c o n t e x t c o n d i t i o n s are said to be "well-formed". The m e a n i n g functions p r o v i d e d e n o t a t i o n s only for w e l l - f o r m e d objects.

The third p a r t of a d e f i n i t i o n defines sets of semantic objects. the d e n o t a t i o n s c h o s e n for a language states)

Both

(e.g. c o n t i n u o u s functions over

and any a u x i l i a r y objects such as environments are described.

In a sense,

this part of a d e f i n i t i o n is unnecessary~

The a b s t r a c t

syntax is the only way in w h i c h the class of source objects is d e l i m i t ed

(unless a translator f u n c t i o n from c o n c r e t e syntax is written);

the

d e n o t a t i o n s and a u x i l i a r y objects w h i c h can be created by the m e a n i n g f u n c t i o n s could,

in fact, be d e d u c e d from those functions. However,

the s e p a r a t e d e s c r i p t i o n of semantic objects

is both an invaluable aid

to the reader of a d e f i n i t i o n and an i m p o r t a n t tool to be used during the d e v e l o p m e n t of the m e a n i n g functions.

The first three parts of a definition,

then, have defined a class of

w e l l - f o r m e d a b s t r a c t objects and a class of semantic objects: m e a n i n g is d e f i n e d by a f u n c t i o n m a p p i n g the former into the latter. This mapping will be d e f i n e d by a family of

(recursive)

functions. An o b j e c t i v e

of a d e n o t a t i o n a l d e f i n i t i o n is that the m e a n i n g of a c o m p o s i t e o b j e c t should be created from the m e a n i n g s of its components. G i v e n this objective there w i l l n o r m a l l y be one semantic f u n c t i o n for each sub-class of a b s t r a c t objects.

H a v i n g o u t l i n e d the "denotational method"

in general,

a few comments

can now be made on the spefic m e t a - l a n g u a g e used in this volume. n o t a t i o n was r e f e r r e d to w i t h i n the Vienna Lab as "Meta-IV").

(The

It is

i m p o r t a n t to a p p r e c i a t e that the authors do not regard the m e t a - l a n guage as any sort of fixed standard.

Rather,

it is o f f e r r e d as a basis

w h i c h has been shown to be a d e q u a t e for a v a r i e t y of definitions,

and

w h i c h can be e x p e c t e d to be a d e q u a t e for d e f i n i n g other related systems. Even for such systems the e x i s t a n c e of a b o d y of n o t a t i o n does not elim i n a t e the d i f f i c u l t i e s of c h o o s i n g suitable abstractions their definition.

Moreover,

for use in

it m u s t be r e a l i z e d that an a t t e m p t to ap-

ply the ideas of d e n o t a t i o n a l semantics to systems of an e n t i r e l y different nature will require the i n v e n t i o n of suitable extensions to the n o t a t i o n p r e s e n t e d here. T h e r e does, however,

appear to be some virtue

in a d e g r e e of s t a n d a r d i s a t i o n in the b a s i c notation.

222

The n o t a t i o n used by the O x f o r d U n i v e r s i t y group

(cf. Stoy 74)

for de-

n o t a t i o n a l semantics d e f i n i t i o n s is rather d i f f e r e n t in a p p e a r a n c e from that p r e s e n t e d here and it may be useful to s p e c u l a t e as to the cause. The O x f o r d group h a v e b e e n p r i n c i p a l l y c o n c e r n e d w i t h q u e s t i o n s of foundations and have w o r k e d w i t h r e l a t i v e l y small languages. They have,

in fact, chosen languages w h i c h illustrate the key p r o b l e m s with

a m i n i m u m of u n n e c e s s a r y detail.

In contrast,

tended to tackle

languages and systems. Furthermore,

larger

(given)

the languages have u s u a l l y b e e n d e f i n e d

the Vienna group have

"warts and all". For a defi-

nition of a certain size it becomes v i r t u a l l y i m p o s s i b l e to r e m e m b e r enough c o n v e n t i o n s to permit use of single c h a r a c t e r names,

type clauses

given i m p l i c i t l y by Greek letters chosen for p a r a m e t e r s etc. Thus,

for

large languages a d i f f e r e n t style is adopted to provide a readable definition. For example, possible,

(longer)

a syntax is e m p l o y e d w h i c h is as a b s t r a c t as

f u n c t i o n names are u s e d in the hope that they are

s u g g e s t i v e to the reader etc.

It is i n t e r e s t i n g to compare the rela-

tive merits of s u c c i n c t n e s s and r e a d a b i l i t y on Mosses 74 and Henhapl

78. The various topics are d i s t r i b u t e d t h r o u g h o u t this paper as follows. S e c t i o n 4 is c o n c e r n e d with the a b s t r a c t syntax notation. The actual objects

(and their operators)

w h i c h have been found to be of use in

earlier a p p l i c a t i o n s of this m e t a - l a n g u a g e ,

are d e s c r i b e d in sections

2 and 3. S e c t i o n s 1 and 5 b r i e f l y outline the logic n o t a t i o n used. The heart of the m e t a - l a n g u a g e is the means for d e f i n i n g and c o m b i n i n g m e a n i n g functions:

this is d e s c r i b e d in section 6. The subject of ar-

bitrary order or m e r g i n g of o p e r a t i o n s

is c o m p l e t e l y omitted from

this paper for reasons given in section 6.

An outline concrete syntax for the m e t a - l a n g u a g e is given in a p p e n d i x I and a p p e n d i x II lists some c o n v e n t i o n s w h i c h have been used in earlier definitions. A p p e n d i x III contains a d e f i n i t i o n of a small language, close study of w h i c h should provide the reader w i t h a clear u n d e r s t a n d i n g of the use of the notation.

223

i. LOGIC N O T A T I O N

In d e f i n i n g any language s o m e t h i n g has to be taken as a basis. For the d e s c r i p t i o n of the o p e r a t o r s of the m e t a - l a n g u a g e ,

the f i r s t - o r d e r pre-

dicate calculus w i t h e q u a l i t y is chosen. T h e r e are two reasons for this choice. Firstly, provided

a c o n s i s t e n t and c o m p l e t e a x i o m a t i c d e f i n i t i o n can be

(e.g. Kleene

67). Secondly, it is w i d e l y enough u n d e r s t o o d

that the p r e s e n t a t i o n here can be r e s t r i c t e d to p r o v i d i n g

"readings"

for the p a r t i c u l a r symbols chosen.

Fig.

I-! d i s p l a y s the n o t a t i o n a d o p t e d t h r o u g h o u t this paper. The con-

straints on b o u n d e d q u a n t i f i e r s are used in p r e f e r e n c e to implications (Thus:

(Vx£NatO)(lis-prime(4.x)) (Vx)(x6Nat 0 ~ lis-prime(4ox))

, rather than

)

in order to reduce the number of "undefined" operands°

However,

the

p r o b l e m of the m e a n i n g of the logical operators w i t h u n d e f i n e d values m u s t be faced and is d i s c u s s e d in section 5. The c o n s t r a i n t s on quantifiers m a y be o m i t t e d w h e r e the context makes t h e m obvious.

The

(iota) d e s c r i p t i o n o p e r a t o r yields the unique o b j e c t s a t i s f y i n g a

predicate.

It is an error to use the o p e r a t o r if no, or m o r e than one,

v a l u e s a t i s f i e s the predicate.

(B:XoEX)(P(Xo)) Here again, text.

Thus:

~ p((~xEX)(p(x)))

the c o n s t r a i n t may be omitted if it is clear from the con-

224

Symbol

Reading

TRUE FALSE

truth values

&

and

V

or

implies equivalence not V

for all

3

there exists

3"

there exists exactly one the unique object

(¥x£X)(p(x)) (vxlc(x))(p(x))

for all members of set X, p(x) for all x satisfying c, p(x) similarly for other quantifier8

fig. I-1: Logic notation

2. ELEMENTARY OBJECTS

In writing a definition it will normally be necessary to use objects which are structured

(i.e. composite).

together with their operators, will, however,

Some types of composite objects,

are described in section 3. A definition

also have to employ certain basic objects whose struc-

ture is of no interest for the system being defined. For example, many definitions will require natural numbers but will wish to treat them as elementary objects. Two standard objects,

the truth values, have already been introduced:

225

TRUE,

FALSE

A n o t h e r o b j e c t w h i c h w i l l be e x p l a i n e d b e l o w holder for an o m i t t e d b r a n c h in a tree)

(roughly,

it is a place

is:

NIL An a u t h o r may also e n u m e r a t e any other objects r e q u i r e d for his defin i t i o n in a n o t a t i o n e x p l a i n e d in section 4. The only p r o p e r t y which is assumed about e l e m e n t a r y objects is that they are d i s t i n g u i s h a b l e . Thus two m e a n i n g f u l o p e r a t o r s are the e q u a l i t y operators

(=,#). A m o n g

the e l e m e n t a r y objects to be e n u m e r a t e d for a d e f i n i t i o n are "references"

(see s e c t i o n 6.1).

In a d d i t i o n to those objects w h i c h can be enumerated,

a definition

w i l l u s u a l l y also require k n o w n objects like natural numbers,

integers,

reals etc. W i t h such familiar sets one may also w i s h to adopt some of their standard o p e r a t o r s

(e.g.

The contents occur

operator,

in c o n t e x t s

meaning

...

or any o t h e r v a l u e r e t u r n i n g

where

the c o n s t r u c t

r

...

(while

A = (let

r d__oot) ~

The r e c u r s i v e

v:r;

...

items

form

v : el in

The r e c u r s i v e

(let

defines

for values.

The

this rule m u s t be i n t e r p r e t e d

as:

v = el

(let w =

(le__~t v:r;

of s y n t a c t i c

side d e f i n e s

(t;w)

else

I)

in w)

that w should be the

e2(v))

~

are more b a s i c

sorts of t r a n s f o r m a t i o n s . )

an a b b r e v i a t i o n :

(IV.e2Cv))(el)

let:

e2(v))

composition

sugar to be d e f i n e d

to p a r t i c u l a r

let p r o v i d e s

f o r m of

in

if v then

of the equation.

~

(Iv~.e2(v'))(Ylv.el(v))

v to be be the m i n i m a l

Functional

...)

combinator

(i.e. are not s p e c i a l i z e d its s i m p l e s t

v

let on the r i g h t hand

fixed-point

The remaining

(let

only

is:

In the case of the w h i l e

minimal

is d e f i n e d

transformation,can

fixed p o i n t of e x p r e s s i o n

is s t r a i g h t f o r w a r d :

el.

In

258

(f'g) = (~x.f(g(x)))

The d y n a m i c c o n d i t i o n a l is d e f i n e d in terms of a c o m b i n a t o r d i s c u s s e d in the next section:

(if V then t I else t 2) ~ cond(tl,t2)(v)

6.4 Basic C o m b i n a t o r s

A d e f i n i t i o n as v i e w e d in section 6.2 is a way of generating, object text w h o s e m e a n i n g is sought,

for any

an e x p r e s s i o n in an e x t e n d e d lamb-

da notation. The length of such e x p r e s s i o n s

is reduced and the reada-

b i l i t y much increased by the use of various combinators.

S e c t i o n 6.3

has shown how these can be e l i m i n a t e d in a way w h i c h yields a m u c h longer e x p r e s s i o n w h o s e s t r u c t u r e corresponds m u c h less closely to that of the o r i g i n a l text. The a d v a n t a g e of this e x p r e s s i o n is ever,

how-

that it is almost in pure lambda n o t a t i o n and it is now only

n e c e s s a r y to discuss the m e a n i n g of two r e m a i n i n g combinators.

In fact all that is done at this p o i n t is to rely on the w o r k of others. Thus along with the models of the lambda calculus in Stoy 74, the minimal fixed point o p e r a t o r

(Y) and the "doubly strict" c o n d i t i o n a l are

adopted:

cond(tl,t2)(T) cond(tl,t2)(TRUE) cond(tl,t~)(FALSE)

= X = t1 = t 2.

cond(tl,t2)(±)

= ±

The a d e q u a c y of the d o u b l y strict functions comes from the e x p l i c i t t r e a t m e n t of errors in the m e t a - l a n g u a g e .

6.5 O t h e r Issues The q u e s t i o n of how to define a r b i t r a r y order of e v a l u a t i o n in a language has been omitted for reasons explained elsewhere. ever,

There are, how-

some points w h e r e it appears to occur in the d e f i n i t i o n s given

259

in this volume. C o n s i d e r the use of:

let l£Sc-loc be 8.t. R-STG

Clearly,

l~dom a R-STG

:= C R - S T G U [l~?]

this intends to show a f r e e d o m of choice w h i c h w o u l d be lost

by p r e - d e f i n i n g an order over elements of So-lot and always c h o o s i n g the "next" free location. E q u a l l y clearly,

it w o u l d be u n n e c e s s a r i l y

c o m p l e x to use some general t r e a t m e n t for n o n - d e t e r m i n i s m functions are Z~Z-8et) construct.

Essentially,

(e.g. all

in order to p r o v i d e a formal d e f i n i t i o n of this it is clear that the p a r t i c u l a r choice makes

no d i f f e r e n c e and it is no m o r e w o r t h w h i l e to prove this c l a i m than it is to o v e r - d e f i n e

(see Jones 77c) and then prove w h a t p r o p e r t i e s

of the d e f i n i t i o n are irrelevant.

It must, however,

be clear that the "let be s.t." c o n s t r u c t could be

used u n w i s e l y and each use should really be a c c o m p a n i e d by its own arg u m e n t of w e l l - f o u n d e d n e s s .

Similarly,

the simple rule that v a l u e r e t u r n i n g t r a n s f o r m a t i o n s can

be w r i t t e n in p o s i t i o n s w h e r e values are r e q u i r e d presents a danger. The e x p a n s i o n g i v e n in s e c t i o n 6.3 that they should be e x t r a c t e d and formed into a p r e c e d i n g

let is only clear if either there is only

one such value r e t u r n i n g t r a n s f o r m a t i o n or if their order will have no e f f e c t on the result. This latter is the case in:

l#t nenv

: env+([gdoe-type(dclm(id),env)lid£do_~mdclm ] U ...)

F i n a l l y the topic of errors in the d e f i n i t i o n should be mentioned. A t a n u m b e r of points it has b e e n i n d i c a t e d that s o m e t h i n g is simply cons i d e r e d to be a w r o n g use of the m e t a - l a n g u a g e case construct).

(~i)(?