• Tidak ada hasil yang ditemukan

4~2.3 METALANGUAGE EXTENSIONS

4.3 PROGRAMS

LWL does not support the creation of programs, as such. In its top level structure, it is heavily influenced by the requirements of the REL language processor which supports the specialized languages created by LWL. The most notable omission in LWL is the lack of statements to dee I are or invoke procedures; the most rad i ca I change is in the syn tax and semantics of function invocation.

4.3.1 MISCELLANEOUS DIFFERENCES FROM PASCAL

In the denotation of var i ab I es, intermediate fie Id identifiers and pointer references may be omitted when no ambiguity is in traduced thereby. For instance, given the fol lowing definition of BIBLIO's author and q_author categories,

category author=@ author _entry;

and

~

author _entry=~ record name: name_str1ng;

num_pub:

0 ••

max_num_pub;

pub: arra\d[l .• max_num_pub] 2..f. publication end;

category q_author =@ author

_I

ist;

~

author

_I

ist =~record next q_author; ·

this: author end;

var x: q_author then the variable designator

x. pub

[1]

is an abbreviation for [email protected] is@. pub

[1]

This form of abbreviation is especially useful when referring to some part of the complex list structures maintained

by

the language processor.

For the convenience of the language writer, the for statement

has been expanded and modified.

PASCAL's

to and downto constructions

need not be di st

i

ngu

i

shed, arid a new form exists for a I I owing an

iteration increment other than one. New forms also exist to express iteration over al I values of a scalar type and al I elements of a I ist.

Thus,

for type=~ pub I ication_type do is equivalent to

for type= book •• collection do • • •

given the definition of pub Ii cat i on_type introduced ear Ii er. A I so, i f v2 is a pointer to a record which includes another pointer to that record type { typ i ca I in a sing I y Ii nked Ii st), then

for vl := al I v2 do

S

is equivalent to

vl := v2;

while vl <> ni I do --w-i th vl @ do begin

- - S ;

vl := <the next pointer value for vl>

end

In the spec i f.i cation of re I at i ona I operators, a mi nor change is introduced. Knuth has pointed out the desirabi I ity of performing numerical comparisons on pointers, because an arbitrary (but consistent) ordering al lows certain sophisticated algorithms to be more efficient

than if only equality or inequality between pointers were determinable (1973, p. 2 of the letter to Hoare}. In response to this observation, the relational operators<, >, <=, and>= also apply between pointers of the same type {i.e., the same target type).

4. 3. 2 FUNCTIONS

The fundamental program unit to be created in the metalanguage is the function. Inputs to a function are called its constituents, and its resu It is ca I I e-d its va I ue; the types of both are determined from the rules of grammar which mention the function as their. semantic function. Functions are normally evaluated by the language processor in response to its analysis of a user's sentence; thus, the constituents and value of

a

~unction are represented in

a

structure cal led

a

phrase marker, 1-1hich is a tree representation of linguistic and computational

information developed by the language processor.

The elimination of procedures and the redefinition of functions both resuJt from the dis~ipline imposed on evaluation by the

REL

System

· I anguage processor. In a syntax directed interpreter, the user's sentence· is analyzed according to the grammar of the object language, and interpretive functions corresponding to each of the applied grammar ru I es are invoked to compute the II meaning" of the sentence. According to the I inguistic model which is the basis of the

REL

languaga

processor, every rule of grammar represents a meaningful operation of the object language, and its corresponding function defines the matching computation on the language's universe of discourse. Functions are composed by the composed application of rules of grammar in the analysis of the user's sentences. Functions may also be cal led by other functions, to permit a hi erarch i ca I composition of a Igor i thm i c tasks.

In that case, we permit a slightly altered syntax from PASCAL's for the function reference.

In addition to the forms which correspond to PASCAL's function designation, we a

I so

a

11

ow a function to appear as a se

I

ector on its first constituent. For example,

f(a,b,c) is

equ i

va

I en

t to

a.f(b,c)

This is done so that the distinction between reference to an item in a structure and the functional computation of an attribute of a record type object may be deliberately blurred. For instance, if we define

~complex= record rp, ip: real ~nd;

var ex: complex;

function norm (c:complex; real};

then LWL wi

I I

al low the references cx.rp

and

ex.norm

to appear i dent i ca

I •

This is des i rab

I

e, because i-n referring to the norm of a complex number, there is no need to distinguish in the form of the reference between the above method of computing the norm at every reference and the alternative strategy of storing its value in the representation of the type:

~

complex

-= record rp, ip, norm

real end;

This syntactic usage recognizes that a selector is a function just as any other operation which computes a value from a record~ and it unifies the syntax of al I

·

function references. This is a minor part of

SIMULA 67's class concept [Dahl 1868).

4.3.3 THE PHRASE MARKER

The phrase marker, mentioned above, is the uni versa I s true ture of the REL language processor. Space considerations prevent a complete description here, and the reader is referred

. to [Thompson

1974b] for a

fu

11

treatment. For the purpose of describing LWL, the fol lowing

Dalam dokumen lment of the Requirements for the Degree of (Halaman 71-76)