Global attributes and their use in the description of programming languages

Global attributes and their use in the description of programming languages

Description o/programming 185 languages 56. CHEREMISIN. F. G. Solution of the plane problem of the aerodynamics of a rarefied gas on the basis of ...

676KB Sizes 0 Downloads 12 Views

Description

o/programming

185

languages

56. CHEREMISIN. F. G. Solution of the plane problem of the aerodynamics of a rarefied gas on the basis of Boltzmann’s equation. Dokl. Akad. Nauk SSSR. 209,4.811-814, 1973. 57. ARISTOV, V. V. and CHEREMISIN, F. G. The splitting of the inhomogeneous kinetic operator of Boltzmann’s equation. Dokl. Akad. Nauk SSSR, 231, I. 49-52, 1976. 58. ARISTOV, V. V. and CHEREI1ISIN. F. G. A discrete ordinate conservative difference scheme for the solution of kinetic equations by the splittmg method. In: The direct numerical modelling of gas flows (Pryamoe chislennoe modelirovanie techenii gaza), 164- 17 1, VTs Akad. Nauk SSSR, Moscow. 1978. 59. ARISTOV, V. V. and CHEREXIISIN. F. G. A conservative splitting method for the solution of Boltzmann’s equation. Zh. \+zhisl. Mat mat. Fiz., 20, 1, 191-207, 1980. 60. SHMIDT, B. Electron beam density measurements in shock waves in argon. J. Fluid Mech., 39, 361, 1969.

U.S.S.R.

Comput.

Marhs. Math. Phys. Vol. 20, So

5, pp 185-194

Printed in Great Britain

0041-5553/80/050185-lOSO7.50/0 0 1981. Pergamon Press Ltd.

GLOBAL ATTRIBUTES AND THEIR USE 1N THE DESCRIPTION OF PROGRAMM.ING LANGUAGES*

A.N.BIRYUKOV,V.M.KUROCHKlN and V.A.SEREBRYAKOV Moscow (Received

GLOBAL attributes. formal description attributes

a generalization of programming

are introduced

of the concept of semantic attributes.

widely used in the

languages. are discussed. It is proved that when global

into the attribute

example of the use of global attributes I. The concept of an attribute

27 March 1980)

scheme it is still possible to verify its correctness.

An

is presented. is widely used In the formal defirntion

of programming

languages. A strict definition of an attribute was first given in by Knuth [I. 2). The essence of this definition is that with each non-terminal or terminal grammar there is associated a set of symbols (attributes).

and with each rule of the grammar there is associated a collection

formulas for evaluating Dqfinjriorr

1. We define the attribute

where G is a context-free

of

the values of the attributes. evaluation

scheme (a.e.s.) as the tetrad

grammar. called the Input or given a.e.s.:

&spi

is the set of attributes; @ is the mapping I-., d T‘,--21j”; {F+) includes those Fij such that Fii is the j-th formula of evaluation of attributes associated with the i-th rule. each such formula being the assignment operator

*Z/I. ~,jGhis/. ;zfat. mar. Ci-_., 20. 5. 1284- 1293, 1980.

186

V. M. Kurochkin

A. N. Eiryukou,

and V. A. Serebryakov

< attribute > : = < expression > (Every,where below it is assumed that G does not contain useless rules). In its turn the expression may include attributes. With each attribute

in the angular brackets there may be an index indicating

symbol of the given rule the attribute

is associated (0 is the index of a symbol of the left side,

I is the index of the first symbol on the right side, and so on). Non-indexed symbols not occurring in the given rule (this correspondence By. Knuth’s definition

these evaluation

To each occurrence

the attributes

that is. only indexed attributes.

assigned to it, the evaluation of which is executed

of formulas corresponding

Therefore the values of the attributes the attribute

relate to

of a symbol of the grammar in the tree of inference there corresponds

of values of the attributes

in accordance with the collection

definition

attributes

will be defined below).

formulas may contain only the symbols of the

grammar occurring in the given rule of inference,

its own collection

with which

are connected

of a symbol corresponding

of direct descendants

to the applied rules of inference. with the tree of inference.

In Knuth’s

to a given vertex of the tree may depend on

of the given vertex, on attributes

of its direct ancestors or

brothers. In this paper a generalization

of the concept of an attribute

introduced

by, Knuth will be

considered. 2. We will understand

by the domain of action of an attribute

tree of inference a set of ramifications including

the given attribute

to use formulas

on the left or right side.

In the relation of attributes is two ramifications

of a given vertex of the

of the tree in which it is permissible

described above the domain of action of each of the attributes

in which the vertex A occurs (for brevity we will call the vertex A the vertex

marked by the symbol A to which the attribute

considered

is assigned). The attributes

having

this domain of action will be called local. Of course the use of local attributes is not always convenient in the definition of a programming language. For example, let us consider the concept of a block in ALGOL 60. A variable, labelled in a block. may be used in any operator occurring in the block. Therefore in the use of local attributes to each symbol of the grammar which can be the descendant of a symbol there must be assigned a local attribute, a list of permissible descriptions. its evaluation

formulas for these descendants

permissible descriptions

simply consisting of the assignment

of the ancester to the list of permissible descriptions

of a list of

of the descendant.

In [2] there is introduced the concept of a global attribute assigned to an axiom of the grammar and available in any ramification of the tree. It is clear that this definition again cannot be useful for the definition of a block of ALGOL 60, since such attributes only for values available in the whole program.

can be used

Description of prognzmming

3. Definition 2. We define the attribute

~2 (a)

as the set of symbols of the grammar to which

o is assigned.

We now define the tree of inference some vertex A (sometimes attribute

187

languages

the domain of action of an attribute

a ascribed to

for brevity we will simpl> speak of the domain of action of the

n), as follows.

there are not more Definition 3. If among the descendants of the vertex .~E,BZ (0, vertices BE& (01. then the domain of action of the attribute II of the vertex A is all the ramifications of the subtree of which A is a vertex. and the ramification in which a given there occurrence of A is a descendant. If among the descendants of the vertex A=& (a) then the domain of action of the attributes a of the vertex A is all are vertices BE& (a), ramifications

of the subtree with vertex A except for subtrees whose vertices are descendants

of a vertex B, and a ramification

in which the vertex A is a descendant.

In the second case the intersection

of the domains of action of two attributes

having the

same name a is possible. as shown in Fig. 1. In the two ramifications the attribute a relating to the symbol B IS indicated with an index corresponding to the occurrence of this symbol In the rule. The attribute

II relating to the s\,mbol A is not indexed.

FIG. 1 It is obvious that Knuth’s definition We will call attributes In [I]

in [I] is a particular

defined in this way, global attributes.

a definition

of correctness

case of definition

given above.

if they are not local.

and an algorithm for checking it for an a.e.s. with

local attributes are given. In this paper we introduce the concept of the correctness with global attributes and prove the possibility of checking it 4. We will consider an example of the use of global attributes.

of an a.e.s.

The language described

below has a block structure. Each block contains a list of descriptions and a list of operators. Each operator is either a block or an identifier, which must be described in one of the enclosing blocks or in the given block.

A. P+‘.Biryukov,

188

List of symbols and attributes
>.
< statement

V. hf Kurochkin

corresponding

and V. A. Serebryakov

to them:

> :: Medium. Error.

> :: List.

< operator >> < hst of operators > :: Error,
> :: Name

Rules of the grammar and formulas for evaluating attributes: 1.


2.


> ::=
> :: Medium < 0 > ::= $; Error < 0 > ::= Error < 1 >;

> ::= (< statement>:

< list of operators >) :: Medium < 0 > := Medium U List

< 2 > : Error < 0 > := Error < 4 > ; 3.

< statement

> ::= < identrfier > :: List < 0 > := Name < 1 > ;

4.

< statement

> ::= < statement

5.

< list of operators > ::= < operator > ::Error < 0 > :=Error

< list of operators > ::= VError < 3 >; 7.


>: < identifier > :: List <0> :=hst < 1 > U Name < 3 >; < I >;

of operators >, < operator > ::Error < 0 > :=

> I:= < identifier > :: Error < 0 > := if Name < I > Q Medium then True

otherwise False; 8.


> ::= ::Error

< 0 > := Error < 1 > :

The global attribute Medium contains all admissible statements. erroneous if at least one undescribed identifier is used. 5. We will need the following definitions

A program is regarded as

below

the set of symbols for which rules of inference Definition 4. We denote by, &Z(U) exist with assignments associated by them with the unindexed attribute a; al(a) is the that is, the set set of possible ancestors for Bl(a),

.a(a)={DlD

1 ap4az, LkLeZ(a)};

arca)

is the set of symbols for which by the rules of inference there corresponds a fomlula in which the unindexed attribute P is encountered on the right side of the assignment

operator:

Br(a)

is the set of possible ancestors for

Br(a)

= {DID

&r(a)

2.a1Aa2, AEEPr(a)).

7

that is, the set

Description

Lemma

189

of progrclmming hngunges

1

Let an a.e.s. be given. For every unindexed

occurrence

of the global attribute

a in the

formula it is possible by reason of the a.e.s. to establish whether a tree of inference exists in the input grammar of the a.e.s. such that this occurrence any attribute

does not fall in any domain of action of

a.

Proof. We first explain informally

the basic idea of the algorithm, verifying whether the

a.e.s. possesses this property’. We subdivide the set of non-terminals

of the input grammar of

OUI

a.e.s. into three subsets: and a rule A + a with left side A exists, to which there 1, (a) = {A pl=l’s corresponds a formula containing the unindexed attribute a},

An arbitrary tree of inference in the input grammar is “cut off’ through all the symbols from the set If on the cross section there is even one symbol of the set dj(a)~J12(a). Zr (a) (and therefore on it no symbol of the set .M2 (a) ), then in the original tree an unindexed attribute was encountered in some formula outside its own domain of action. We now pass on to the formula explanation.

We construct

the grammar

G’= ( I-.,‘. 1-T’.P’, s’), where

{d-w},

V,V’=JXS(a)~{~‘},

P’={A-crIA+cr~P.

li,‘=~‘,~,~‘,(a)il.;X,(a).

A EV~‘)U

s’@V.v. The question of the existence of a tree where some occurrence

outside the domain of action is equivalent

to the question

of the attribute

a

lies

of whether the words of the language

L(G’) contain symbols from the set

This problem is easily solved. To solve it. &r(a). to replace all the terminal symbols, different from the symbols of Jxj (a) ( by

it is sufficient

empty strings. Then the problem reduces to checking whether the language generated after this substitution

contains

a non-empty

string. which we know can be done. The lemma is proved.

Lemma 2 Let an a.e.s. be given. For an> global attribute

a from the form of the a.e.s. it is possible

to establish whether there exists a tree of inference in the input grammar of the a.e.s. such that in some domain of action not one assignment involves the attribute II. &of:

We construct

an algorithm verifying whether the a.e.s. possesses the property

mentioned. We first construct the set 8 (n) = {A RAE& (a) and to all the rules of the form A + CYthere is ascribed an assignment to an unindexed attribute a}. If for all rules of the form B + a1 Aa,, where the symbol A stands on the right side: for example, in the i-th place, there exists a formula of the form a :=e (here e is some expression),

then obviously

a tree satisfying the condition

of the lemma does not exist.

190

A. N. Biryukov,

V. M. Kurochkin and V. A. Serebryakov

Let a rule exist for which there is no corresponding

formula. We transform

the initial

grammar of our a.e.s. as follows:

(1)

V,‘={s’}LJ(V,\s4+?))U8(a),

(2)

v,‘=r-,r:(~(a)‘\~(a)),

(3)

s’+vs,

in P there is a rule A + cp: to which there is not assigned a P’= {s’-+(c 1 B+&(a), and to the rule tormula ot the form o(l~>: =e)~{B+?(B-+JEP, B --) p there is not assigned a formula of the form U: =e}. A tree satisfying the condition

by the grammar

of the lemma exists if and only if the language generated G’= ( V.,.‘, VT’, P’, s’), is not empty. We will prove this.

If L(G’) is empty, then either in P’ there is not a single rule of the form s’+ up,or in every inference in G’ there is necessarily encountered In the first case, by (3) the assignment

a non-terminal

to the attribute

at the vertex A. In the second case the non-terminal 8 (a)

for which there is no rule in P’.

a is encountered

in the first branching

for which there is no rule may belong to

or may be a symbol not belonging to J& (a)

and such that to all the rules of the initial

grammar. where it is on the left side, a formula of the form u:=e is assigned. If it is a symbol to all the corresponding rules in P there then by the definition of 8(a), from J?(a), is assigned a formula of the form a:= e. We note that on constructing

the tree of inference in G’

we do not go bey,ond the limits of the domain of action of the attribute no generating

Conversely. let $G’) terminal alphabet the condition

II, since in P’ there are

rules for symbols from srl (a)

V,

be non-empty.

We construct

Then from s’ it is possible to deduce a chain in the

by’ this rule a tree of inference in the grammar G, satisfying

of the lemma. For this we continue

the inference

from the terminal symbols

choosing for them rules with which formulas of the belonging to the set d(n) \Ep (a), form a:=e are not associated. We put the subtree obtained under an inference SGalAa2, where the symbol A appears as the result of the application

of a rule to which the formula

is not assigned. In the construction of the tree of inference in the grammar G u(i): =e in the domain of action of the attribute a associated with the vertex A, there is not a single assignment

to this attribute,

which is what it was required to prove.

Lemma 3 Let an a.e.s. be given. For every global attribute u it can be established

from the form of

the a.e.s. whether a tree of inference in the input grammar of the a.e.s. exists such that in the domain of action of the attribute u more than one assignment occurs for it. Proof: G’= ( l-x’,

We construct I-,‘, P’, s’)

from the input grammar of the a.e.s. a new grammar as follows:

T’,Y’=l-.,-iJ {s’},

s’e

r-,‘=r-,~{_3’1AE~~(u)},

vs,

Description of programming

P'={s'+a~A+a~P}U{A~a'~A-+a~P after replacing all the symbols A from

J$ (a)

191

languages

and cr’ is obtained by the symbols

from (Y

.A’).

In the initial a.e.s. let there be a tree of inference in which for some occurrence attribute

a in its domain of action there are two assignments.

of the

This is possible if and only if one

of the following two cases holds.

FlG. 3

FIG. 2 Case 1. One of the branchings

in which the assignment

is realized

IS

a descendant

of

another. as sh .twn in Fig. 2. That is for the rule C -+ a. with which is assocrated the assignment to the attribute

a: descendants

are possible in which an assignment

realized. We will consider that in the upper assignment greater than or equal to unit!,. since the cor:isponding are Interested

in descendants

to the attribute

u is also

the attribute II is not indexed b!, an inde\ case is considered In [l] We note that u e

which are not at the same time descendants

of s)-mbols from 2 (O 1.

since such s>,mbols introduce new attributes a. Therefore in the grammar G’ we consider for each of the rules. with which an assignment to the attribute is associated. the set of its descendants.

If among these descendants

a.e.s. the double assignment

to the attribute

Case 2. None of the branchings descendant

of another.

there are s) mbols from

&l (a).

then in the original

a in its domain of action is possible.

m which an assignment

IO the attribute

a is realized is the

as shown in Fig. 3. This means that there is a rule in whose right side

there are two non-terminals

such that from each of them a s),mbol can be deduced whose rule

of inference is associated with an assignment

to the attribute

a. To displa! this we consider for

each of the rules of the grammar G’ the descendants of the symbols of its right side. If among the descendants of even one pair of s> mbols of even one rule there are symbols from ck?[(a), then in the a.e.s. a double assignment

to the attribute

II in Its domain of action is possible. which

is what it was required to prove. Everywhere below b>, an a.e.s. we will mean an a.e.s. satrsf! ing the following conditions. 1) in every tree of inference in the initial grammar of tire a.e.s. every occurrence non-indexed global attribute is found in its domain of action. 2) in ever)’ tree of inference in the domain of actron of global attribute assignment

is realized for it.

of a

one and onI) one

A. N. Biryukov,

192

V. M. Kurochkin

We now pass on to the question Definition

and V. A. Serebryakov

of the cycling of an a.e.s. including global attributes.

5. Let there be given an a.e.s. in&ding

inference in the initial grammar of the a.e.s. we construct, a graph of relations below. The arcs? representing constructed

global attributes. following

For any tree of

[l] , a flow graph, called

relations between the global attributes,

are

taking into account the domains of action. We say than a.e.s. is cyclic if and only if a

tree of inference exists whose graph of relations contains an oriented cycle. It is easy to see that in essence our definition and it is given only for completeness,

does not differ from Knuth’s definition,

since here it is applied to a wider class of objects (an a.e.s.

with global attributes). To check an a.e.s. with global attributes there are no global attributes.

for cyclicity we reduce it to an a.e.s. in which

The corresponding

Before passing to the formal exposition

algorithm is called a reduction

of the reduction-algorithm

algorithm.

we explain informally

the meaning of the sets introduced in it. The set 9(a) consists of symbols to which an a.e.s. without global attributes there will be assigned a local synthesized attribute; by means of the latter the value assigned in the original a.e.s. to the global attribute is transferred to that vertex to which this global attribute is ascribed. Itself it is made local in that branching to whose left side it is assigned. To the symbols of the set % (a) there is ascribed a local inherited attribute,

serving to transmit the value of the global attribute

to all the branches situated

within its domain of action.

Reduction

algorithm

Input. The a.e.s. rl. Output. The a.e.s. without global attributes. Method. For every global attribute Step 0. We construct

a the following sequence of actions is completed.

the set 9 (a).

We first put

5/(a)

=&l(n).

We will repeat step 1

as long as new elements are added to P(n) Step 1. We construct -Weput

the set

LD (a)

of all direct ancestors of the symbols of 9(a).

sj(a)=~((a)U(b(a)\~(a)).

Step 2.We construct the set a?(a)=(kZj~(a)\~(a))Ubr(n). Step 3. To all the symbols of B(a) we ascribe the local attribute a’, differing from all the attributes present in the a.e.s. To all the symbols of a? (a) we ascribe the local attribute a”, also differing from all the attributes present in the a.e.s. Step 4. To all the rules of the form Z-+a,Yaz, where 2, Yc?‘(u), we ascribe the formula a’(O): =a’(i), where i is the number of the occurrence of the symbol Y (we note that this occurrence is unique). To all rules of the form Z+arYIazY2 ... Y,a,+l, where we ascribe the formulas a”ij): =u”(O). where the index j 2, Y,, . . . , Y,=%(a),

Descriph’on

of programming

193

la?IgUageS

denotes the numbers of the occurrence

of the symbols Y,, . , Y, in the rule. In all the rules formulas of the form n: =e are replaced by of the form Z+a, where .&bl(cl), a’(O): =e. All formulas of the form b: =./(a, . . .) in all the rules are replaced by b: =fla”, . . ). where j is the number of the occurrence theformZ+al

YcuZ,where

Z~.s$(a),

%(a)

in the rule. To all rules of

weascribetheformulas a(0): =a’(i), =a(O>, l
YES,

of the symbol Y, and a”(j):

where i is the number of symbols from

of any symbol of &3(a)

on the right side of the rule.

We note that some formulas may change several times on repetition actions for different

global attributes,

can be transformed

into

b’(O):

For example. formulas of the form

=f(a”,

of this sequence of b: =f(a”(j>,

. . .)

. . .),,

We now formula a lemma expressing the relation between the original a.e.s. and the a.e.s. obtained

from it by the reduction

algorithm.

from the point of view of cyclicity.

Lemma 4. The original a.e.s. is cyclic (property by the reduction

algorithm is cyclic (property

A) if and only if the a.e.s. obtamed

from it

B).

Proofi We call the attributes introduced at step 3 of the reduction algorithm and marked by, one dash: attributes of the first kind, we call the attributes introduced there and marked by two dashes attributes

of the second kind. and all the others attributes

B + A. Let the a.e.s. obtained by, the reduction a tree of inference

of the third kind.

algorithm be cy,clic, that is, let there exist

such that the graph of relations of attributes

corresponding

to this tree

contains an oriented cycle. We first note that if all the nodes of this cycle are marked only by attributes

of the third kind: then A is satisfied, since in the reduction

to the a.e.s. formulas of the form u: =flar and among

al,

of the first kind. since they are all synthesized.

be marked by, attributes 0: =!(a,,

of the third kind.

. . : ak ). where a is an attribute of the third kind. and among al. . . . . ak of the third kind. Also the nodes of the cycle cannot be marked by

=f(al:.

there are attributes attributes

algorithm we do not add

. 0,). where LIis an attribute

. * . ,a,),

Also all the nodes of the c),cle cannot

of the second kind, since in the a.e.s. there are no formulas of the form where a” and b” are assigned to the same sy,mbol of the grammar.

We show that all the nodes of a cycle cannot be marked only. by attributes

of the first

and second kinds. Suppose this is not so. We consider a cy,cle whose nodes are marked onl! b! attributes attribute

of the first and second kinds. We also consider an arbitrary, vertex marked b! an of the second kind. We will move from a vertex marked by, tms attribute

of the cycle in a direction

opposite to its orientation.

has been traversed a vertex marked by, an attribute

along arcs

It is obvious that before the whole cycle of the third kind is encountered.

since

otherwise there exists a cycle all of whose nodes are marked only- by attributes of the second kind. which is impossible, or the path goes along an arc corresponding to the application of a formula of the form a: =f(al, . . , uk). where u is an attribute of the second kind, and among the attributesal, . . . , ak there is an attribute of the first kind, which is also impossible, since there are no such formulas in the a.e.s. Therefore, a node marked by an attribute of the third kind exists in the cycle. We will move along arcs of the cycle from this attribute in the direction of orientation of the cy,cle up to the first appearance of an attribute of the third kind (in particular, this attribute may be the attribute

chosen initially).

It is obvious from the reduction

algorithm that the path traversed in

A. h’. Biryukov,

194

the original a.e.s. corresponds kind without intermediate corresponding

V. M. Kurochkin

and V. A. Serebryakov

to a formula connecting

attributes.

the values of two attributes

of the third

In other words, in the graph of relations of the

tree of inference in the original a.e.s. there is an arc going from the first attribute

of the third kind to the second attribute with the second attribute

of the third kind. We repeat this process, beginning

of the third kind, and so on until the whole cycle has been traversed.

It is obvious that in this way’ it is possible to reconstruct

the corresponding

part of the graph

of relations in the original a.e.s., and this part will be a cycle. A + B. It is sufficient

to consider a cycle in the graph of relations of the original a.e.s.,

including global attributes. obtained

We will consider how such a cycle is transformed

from the reduction

algorithm.

going to a node marked by a global attribute,

and of an arc emerging from this node. The arc

going to the node marked by the global attribute going to a node marked by an attribute will correspond

into the a.e.s.

Let there be a fragment of a cycle consisting of an arc will correspond

in the new a.e.s. to an arc

of the first kind with the same name. The emerging arc

either to an arc emerging from an attribute

of the second kind with the same

name, or to an arc emerging from a node having the same mark, if the attribute It is obvious from the reduction

was indexed.

algorithm that in the first case there exists in the graph

of relations a path from the node marked with an attribute

of the first kind to a node marked

with an attribute of the second kind with the same name, that is, the cycle is not broken up: but only, “stretched”. In the second case the fragment of cycle is unchanged. The lemma is proved. We call a non-cyclic

a.e.s. satisfying the conditions

formulated

after the proof of Lemma 3,

correct. We can summarize what was said above as follows. Fmdamerl tal tkorem For ever\’ a.e.s. there exists an algorithm for verifying its correctness. In conclusion

we mention

that none of the algorithms explained claims that it constitutes

a practical method of verifying the correctness of an a.e.s. In this paper all the algorithms merely, illustrate the proof of the theoretical

feasibility of such a verification. Translated by, J. Berry,. REFERENCES

1.

KNUTH, D. E. Semantics of contelt-free IanSuaees. Marh. S>,stems

2.

KNUTH, D. E. Corrections. Marh. Systems Theory, 5. 1, 179, 1974.

3.

KNUTH, D. E. Examples of formal semantics. In: New York. 1971.

Lecture

Theor),,

2, 2, 127-145,

Notes in Math., No. 188,

1968.

Springer,