NORMA (1158464), страница 3
Текст из файла (страница 3)
declaration .
operator .
iteration .
Program in NORMA consists of one or several parts. The parts may be of three types - main part, simple part and part-function (corresponding to key-words MAIN PART, PART, FUNCTION). Parts can call each other by name and communicate data with help of formal and actual parameters or through external files with help of INPUT and OUTPUT declarations.
Localization rule is true for each part: the names declared in the part are localized in it. There are no global variables in the language.
The main part must be in the NORMA program and be the only one (it has no formal parameters. Main part calls and recursive calls are prohibited.
There is name of the part, and the list of formal parameters in the part header. Formal parameters must be declared in the body of part with help of declaration-of-scalar-variables, declaration-of-variables-on-domains, and declaration of external.
Parameters-variables declared before the key-word RESULT in the list of formal parameters are initial data for computations specified in the part, the parameters declared after are the results of computations. One and the same parameter can’t be initial and result at the same time (it causes reassignment which is prohibited in NORMA). The key-word RESULT isn’t used in part-function (the result of computations is connected with the name and the type of function).
There are definitions, operators and iterations in the body of part. In general their order is arbitrary, possible constraints are defined in translator’s source language description).
It is an example of main part header :
MAIN PART Linear . ! Variant of May 25 1998 :
! ======= linear approximation ========
! the case of axial symmetry for M=1 ;
! computation is being done on Beta angle for the point I=0 ;
! further for I=1,2*N values
! are being extended on symmetry for V,FI,DAVL .
BEGIN
body of part
END PART
It is an example of simple part header:
PART IntFKP .
! Computation of integral from FKP function
! with interpolation of integral function
BETA,ALPHA, ! - node points
ALL,ALC,ALR, ! - points for interpolation
STEP, ! - integration step
FKP ! - name of integral function
! - result IntResult
RESULT IntResult
BEGIN
EXTERNAL FUNCTION FKP DOUBLE .
VARIABLE ALPHA,BETA,ALL,ALK,ALR,STEP,IntResult DOUBLE .
body of part
END PART
5. NORMA constructions
We can divide Norma constructions into declarations, defining program objects (e.g. domains, indexes, variables ) and constructions for computation rules specification.
5.1. Declarations
declaration :
declaration-of-domain
declaration-of-domain-indexes
declaration-of-scalar-variables
declaration-of-variables-on-domains
declaration-of-distribution-indexes
declaration-of-domain-parameters
declaration-of-input
declaration-of-output
declaration-of-external
Objects which can be declared in NORMA are: domains, scalar variables (scalars), variables specified on domain, index constructions, distribution indexes, domain parameters, input and output variables, names of external functions and parts.
5.1.1. Declarations of domains
declaration-of-domain :
declaration-of-unconditional-domain
declaration-of-conditional-domain
declaration-of-unconditional-domain
declaration-of-rectangular-domain
declaration-of-diagonal-domain
domain :
new-domain-without-name
name-domain
unconditional-domain :
new-domain-without-name
name-unconditional-domain
name-domain :
name-unconditional-domain
name-conditional-domain
name-unconditional-domain :
name-rectangular-domain
name-diagonal-domain
The notion domain was introduced in NORMA for index space representation. Domain is a complex of integers numbers sets {i1,....,in }, n>0, ij>0, j=1,...,n. Each set gives coordinates of the point from n-dimensional space. Unique name - index name is connected with one of the directions (coordinate axes ) of the n-dimensional space.
The domain defines coordinates values of index space points, but not the values of the calculated variables in these points. For example if you need to calculate the value of the variable Yi,j, i.j =1,...,n on some grid Xi,j, i,j =1,...n, which was introduced during task solution (e.g. by formula Xi,j =F(h,i,j), F- given function, h - given parameter) you should:
(1) define the domain consists of points i,j = 1,...n;
(2) define variables X and Y;
(3) set the rule of grid Xi,j computation : Xi,j = F(h,i,j) and the rule of Yi,j values computation Yi,j = G(Xi,j ) (F,G,h are considered to be given somehow).
Domain in NORMA can have a name. The operations of modification and multiplication are defined on the domains. Domain indexes aren’t specially declared, they are introduced in domains’ declaration. Domain can be conditional and unconditional. Conditional domain consists of the index space points. The number and the coordinates of these points can change depending on fulfilment or non fulfilment of conditions on domain. Unconditional domain consists of the points from index space, which number and coordinates may be defined during the translation.
There are two different terms in NORMA: declaration of domain (named conditional or unconditional domain) and use of domain (syntactically it is the name-domain or new-domain-without-name). Domains are used in declarations of the variables declared on domain, setting computation domain in ASSUME operators, input and output variables declarations, setting domains of actual parameters in part or functions calls, in reduction functions.
5.1.1.1. Declaration of unconditional domain
declaration-of-rectangular-domain :
multidimensional-domain
new-domain
multidimensional-domain :
onedimensional-domain
[ name-multidimensional-domain : ] ( domain-product )
domain-product :
component-domain { ; component-domain }+
component-domain :
multidimensional-domain
name-unconditional-domain
onedimensional-domain :
[ name-onedimensional-domain : ] ( name-index = value )
value :
range
const-expression
range :
const-expression .. const-expression
new-domain :
[ name-new-domain : ] new-domain-without-name
new-domain-without-name :
name-unconditional-domain / list-modification
modification :
name-index = value
name-onedimensional-domain { { +,- } boundary-function }+
boundary-function :
LEFT( const-expression )
RIGHT( const-expression )
name-rectangular-domain :
name-onedimensional-domain
name-multidimensional-domain
name-new-domain
declaration-of-diagonal-domain :
name-diagonal-domain : name-unconditional-domain / list-condition-on-index
The notion of one-dimensional domain is a key notion in rectangular dimensions declaration. One-dimensional domain is used for setting the range of points on some coordinate axe in the index space. In the simplest case the name of one-dimensional domain, index name and the boundaries of index values changing are declared in one-dimensional domain declaration:
RegionK: (k =1..15) .
Name-onedimensional-domain can be used for reference to this domain.
The name of index is an index variable. The set of its values is defined by the range
const-expression .. const-expression. The boundaries of the range are integer positive constant expressions built from integer constants, domain’s parameters and arithmetical operations. Particular values must be assigned to the domain’s parameters in the declaration of domain’s parameters. The value of the low boundary mustn’t be more than the value of upper boundary.
Multidimensional domain is built by operation “;” of rectangular domains multiplication.
It is an example of two-dimensional domain declaration. This domain is built by the multiplication of one-dimensional domains AxisK and AxisL:
Square: (AxisK : (k=1..15) ; AxisL : (l=1..5) ) .
Domain Square may be defined in different ways ( e.g. taking into account the previous definition ):
Square : (RegionK ; AxisL : (l=1..5) ).
The “;” operation of rectangular domains’ multiplication has an ability:
A;B=B;A if A and B are domains.
It means that the order of the index space directions in domain’s declaration isn’t fixed (or fixed arbitrarily, that is the same for user). If the order of index space directions is important (e.g. consistency of directions is needed for using the same variables on the same domains in the different parts) it may be set by INDEX declaration (5.1.2).
If the domains are operands of domains’ multiplication operation they must have different index names.
The issue of rectangular domain modification may be in addition of some points, deletion of the points or changing the range. The modification of the first two types is defined by the boundary-functions LEFT(n) and RIGHT(n). Function LEFT is applied to the left boundary of the range and function RIGHT - to the right one. Sign “+” means that the points are added to the one-dimensional domain, sign “-” means that they are deleted. Both functions have one parameter n which defines the number of the points. Integer positive constant may be an actual parameter of the function only. Call to the functions is allowed only in the context with the name of one-dimensional domain setting modificated range:
name-onedimensional-domain {+,-} LEFT(n)
or
name-onedimensional-domain {+,-} RIGHT(n).
E.g. the declaration
FlushK : Square / AxisK - LEFT(2) + RIGHT(2) .
defines domain FlushK which consists of points k=3 .. 17.
The boundaries of the resulting range (after using LEFT and RIGHT functions) must be positive integer and the left boundary mustn’t exceed the right one.
Declaration
Square2: Square / AxisK+Left(1)-Right(2) .
isn’t right because the left boundary of the resulting range k=0...13 isn’t positive.
A domain under modification with help of function Left or Right must be multidimensional domain.
You can change component one-dimensional domain by the explicit redeclaration of the ranges. For this purpose index name of direction and its new value must be declared in the modification.
E.g.