THE ALGORITHMIC METALA~GUAGE
ALMET*
V.V.CHER~YUGOV Leningrad (Received
5 February
1. Construction
1968; revised
of the algorithmic
15 April
1968)
metalanguage
THE form of the quantities with which we can operate in a concrete problemoriented algorithmic language is defined and fixed in the creation of the language. A problem orientated language makes it possible for the user to call the values of the quantities indicated by names (identifi~) by means of procedures (o~rations), defined in the language or described by the user, within the scope of the types of quantities existing in the language. At the same time there is a number of problems (synthesis of schemes, translation from algorithm languages, the carrying out of analytical calculations etc.) for whose description the use of an algorithmic language with an enlarged set of types of quantity is more natural and effective. In the proposed language, as distinct from problemorientated languages, in addition to names and values the structure of the quantity is also an object of the language. Definition. An algorithmic language is a ~tala~uage if it has all three characteristic qu~tities: structure, name and value are the objects of action of the language. In the description of algorithmic processes for a metalanguage it is possible for the user to introduce quantities which are adequate for the objects of the program (such ideas as block, string ets., denoting methods of restricting variables, generally differ from the idea of the structure of a quantity). The algorithm media of a metalanguage can be used for the transformation (calculation) of the written program into the metalanguage (for instance, transformations similar to the substitution of actual parameters by name in ALGOL-60). In this way various dialects, adapted to the solution of one problem or another, can be formed within the scope of one language. If we wonsider this feature of a metalanguage, only necessary algorithmic media can be included in the base configuration, which in its turn overlooks the creation of a translator from the *Zh,
v’y>hisl. Mat. mat. Fiz.,
9, 6, 1419-1423,
1969
247
248
V. V. Chernyugov
metalanguage. In the ALMET language the means of producing grammars without context is used to describe the structure of the variables. Suppose that the contextually free grammar G is quadruple W,, V, , P, 3, where VT is a finite set of terminal symbols, VN is a finite set of non-terminal symbols (metavariables) which has no intersection with V,, p is a finite set of generating rules and S is the finite set of words in the alphabet V = V, IJ V,. The generating rules have the form di : : = ‘pii 1‘pi21 . . . 1qin 7 where Ai E V, is a metavariable and (Pii’ (Pi21””% are the words in the alphabet V. The variable generating the rule for a word consists of a change of metavariable Ai in this word to ‘pii. In the metalanguage the structure of the variable is indicated by a reference to an element of the set S. The variable with the structure II, E S, can take as its value any words from VT, which can be generated from the initial word $ by means of a consecutive application of the generating rules of this grammar. 2.
A formal description
of the algorithmic
metalaguage
ALMET
1. The structure of the language. An algorithmic metalanguage is intended to describe algorithmic processes on quantities which vary in structure. The writing of an algorithm in a metalanguage consists of descriptions: descriptions of variables, meta-variables, operations on quantities and operators. The descriptions of the metavariables give the generating grammar, by means of which the structure of the variables are defined. To control the flow of the algorithmic process an operator is introduced for a conditional jump. To increase the ease of programming and rational realization the language has a block structure and a block localization of the quantities. 1.1. Syntax
:: = of operators> end :: = begin :: = 1 dist of descriptions> of operators> :: = / : : I~description of the operation> :: = \(((: :: = (the symbols of some alphabet,as well as the underlined words, left from this alphabet are symbols of the
The algorithmic
metalanguage
249
almet
metalanguage). 2. Descriptions. The description define the properties and localization descriptions
of the variables.
The
of quantities must precede their use in the algorithm (dynamically).
The quantities described are present in the block containing the descriptions these quantities.
of
A repeated description of a quantity in an embedded
(dynamically) block stops the operation of the preceding description at the time this block is working. The sphere of action of a mark is similarly defined. The appearance of a mark before an operator (: ) is considered as a description of this mark. Variables, metavariables and operations are described in a corresponding way. 2.1.
Description of variables and metavariables.
The description of a variable consists the identifier of the variable.
of relating the required structure to
The structure is defined by giving the
corresponding generating grammar in the form of a description of metavariables. The set of metavariables forms the set V,
and all the other symbols of the
metaformulae form the set of terminal symbols VT.
The structure of a variable
defines the form of the words in the alphabet VT which can be values of the variable. 2.1.1.
Syntax.
(The metalanguage symbols &and
1 are equivalent in
meaning to the symbols : = and 1.1 :: = dcl
# :: F :: # :: = ~~tlist if metaformulae> :: = :: = : : = : : =
Note.
It is considered that in every algorithm there is a description of the metavariable s and QC- fin of the form or :: = # or - fin 2 #, where represents the symbol 1, and
250
V. V. Chernyugov
such texts appears in the transformation program in the metalanguage 2.1.3. am
of the writing of the
Examples
dcl f : : = -2 : : = -
(calculation)
(z) # -
1 b #
This describes a variable withidentifier f having the structure (z). The description of the metavariable z gives the generating grammar, corresponding to which the variable f may take as values words of the form (b), (aba), (aabaa) etc. 2.2 Descriptions
of the operations.
The descriptions of the operations define the transformations to which the quantities of the defined form may be subject. The form of the quantities, to which the transformation described is applicable, is given by the structure of the argument. The specification of the operation indicates whether the procedure belongs to the class of procedure-operations, function-operations or metaoperations. 2.2.1.
Syntax.
:: = :: = procedure () :: = cmetalanguage symbol> :: = unetaformula> :: = :: = procedure - end -1function - end meta - end () uesult> :: = :: = 2.2.2.
()
Note.
In the metaformula for the structure of the argument variables may be introduced which replace the parts of the metaformula which are of equivalent structure, while in the realization of the operator for the operation the variables take as their values the parts of the argument identified with them (see 4.1.2)
The algorithmic
metalanguuge
almet
251
3. Expressions The primary component of the description of an algorit~i~ process is the The realization of an expression consists of the calculation of the expression. values of the expression. 3.1.
Syntax.
:: = ) :: = / / :: = 1 unetavariable> of . 3.2.
Calculation
of the value of an expression.
The value of an expression is a word in VT, composed of values entering into the expression for the components. The values of the components are calculated in succession from left to right. The value of the terminal symbol is the terminal symbol itself. The value of a variable is calculated from the structural description of the value of the variable (see 4.1.2) in accordance with generating grammar, operating in the block containing the expression to be calculated. The construction of has as its value the part of the value corresponding to the variable mentioned. The value of the operator for a function-operation is the value of the expression uresult> of this function-operation. The operator for the function-operation is realized in the same way as the operator for an operation. 4. Operators.
I
The operators in a block (promo) are realized in succession in the order of their position. The natural order can be changed by a conditional jump operator. 4.1. 4.1.1.
The operators for the operations. Syntax.
:: - () :: =
V. V. Chernyugov
252
4.1.
Realization
of the operator for an operation.
The operator is applied to the value of the expression . Identification (see 121) of this value is carried out from the structure of the argument (it must be noted that the algorithmic metalangnage described in I21 in not a metalanguage in the sense of the definition of a metalanguage given in Section 11. The identification is possible if the word which is the value of the ~~rnent can be derived from the word tstructure of the argument> (considering that the variables replace the parts of the metaformula which are equivalent in structure) in the grammar used in the block. If the identification is impossible this is considered as a mistake in the algorithm. The result of the identification is the structural description (S-marker) [11 of the value of the argument. The variables in the structure of the lament take new values if we take account of the branches of the structural description corresponding to the variables. The structural description of the value of the variable is used in the calculation of the value of the variable. After carrying out the identification, the operators of the body of the operation are realized. 4.1.3
The meta-operation.
A m&a-operation considers the value of an expression unetaprogram> as an algorithm in the metal~guage. After realizing the body of the operation the value of the expression ~e~ro~am> is ca~c~at~ and the word obtained is realized as an operator. 4.1.4.
Note
It is considered that two operations are described in each aIgorit~ with names input and output for effecting the input and output of i~~mation. (The body of these operations is naturally .L ) The operator for the functionoperation input () effects the input of information in accordance with the instructions which can be given by the value of the expression. The value of the operator for the f~ctio~operation input () is the value of the word which is input. The iperator for the pr~~~~~ratioa output f outputs the value of the expression. 4.2 The operator for a conditional 4.2.1.
jump.
Syntax
:: = if :: = urelation sign>
The algorithmic
metalanguage
almet
253
** . . = :: = :: = =I# 4.2.1. Realization
of the conditional
operator.
The values of the expressions and are compared. If the Boolean expression is true the operator indicated by the mark mentioned is realized by what follows and in the opposite case the following operator is realized. 4.3.
The block.
The operator inputs new definitions of the variables, metavariables, operations and marks whose descriptions are in this block. After realizing the input operators in the block the input definitions are no longer in force. 4.4.
The empty operator.
The operator is considered to be realized. 4.4.1.
syntax.
:: = 3. Example Let us consider a program which translates the description of an arithmetic expression from ALGOL 60 to the Polish inverse description. begin d= :: = ar. exnression # ar. expression :: = term 1 0~. + E - tee 1 term 9. + s - ar. exnression # term --- :: = factor1 factor op. x s I term # first expression 1 first expressionJ factor # factor :: = -first expression :: -- = ident Itar. expression) # ident :: =alblcldlelflg# --___--op.+o~-::++I-# Op.xorl::=x//# -&ccc%; F(D) begin ar. expression :: op. + E - Iterm, ar. expression, 01. + s ----= term ) 0. 0, term, #
254
V. V. Chernyugov
term :: = factor J factor, term, 9. x ok / # --factor :: = first expression 1 first expression, -first expression
factor I#
:: -- = ident / ar. expression #
output (D) end procedure
- end
F(e x (a x b + c) b - f x g)
In the block the variable D described has the structure ar. expression. descriptions
of the metavariables.
ident, op. + or -,
ar. expression,
The
term. factor, first expression,
op. x or/ define the set of permissible values of the variable
D?he terminal symbols are a, b, c, d, e, f, g, +, -, x, /, T b,). The description of the procedure F defines the required transformation of the arithmetic expression. The procedure operator is As a result of the identification the structural description of this word. structure of the variable D is redefined
f x g.
the metavariables ar. expression,
applied to the word e + (a x b + c) / b the variable D will have as its value In the body of the operation F the by means of a repeated description of
term, factor, first expression.
The operator
output (D) outputs the value of the variable D. The value of the variable D, calculated in accordance with the new grammar, has the form e, a, b, x, c,+ , b, I, -k.
f, g, x9--. Translated
by H. F. Cleaves
REFERENCES 1.
2.
KHOMSKII, N. and MILLER, J. languages. Kibernetich. sb.
Introduction
1, 227-290,
to the formal analysis 1965.
of natural
TURCHIN. V. F. A metalanguage for the formal description of algorithmic languages, in: Tsifrovaya v$zhisZ. tekh. i. programmirovanie. Moscow, 124, 1966.
1, 116-