9. Names in Datalanguage
A name is recognized when it has been associated with a particular data container or set of containers.
Datalanguage has mechanisms for the recognition of names in contexts. That is, the meaning of the name is related to where it appears.
This makes it possible to attach natural meanings to partially qualified names.
For example:
WEATHER FILE LIST
STATION STRUCT
CITY STR (15)
STATE STR (15)
DATA LIST (24)
OBSERVATION STRUCT
HOUR STR (2)
TEMPERATURE STR (3)
HUMIDITY STR (2)
PRESSURE STR (4)
END
END
RESULTS PORT LIST
RESULT STRUCT
CITY STR (15)
HOUR STR (2)
TEMPERATURE STR (3)
END
FOR STATION WITH STATE EQ 'CALIFORNIA'
FOR RESULT, OBSERVATION WITH HOUR GT '12'
AND HUMIDITY LT '75'
CITY = CITY ;
HOUR = HOUR ;
TEMPERATURE = TEMPERATURE ;
END ;
END ;
in the assignment 'CITY = CITY', the first CITY is understood to be RESULT.CITY and the second is understood to be STATION.CITY.
9.1 Informal Presentation of Recognition Rules
'Ident' is used in the sense of section 3. For example, in the description:
F FILE LIST R STRUCT A STR (1) B STR (1) END
F, R, A and B are idents.
A context is a tree whose nodes are idents. In such a tree, the terminal nodes are idents of STRINGs. The ident of a LIST is superior to the ident of the LIST-member. The ident of a STRUCT is superior to the idents of the STRUCT elements. The context whose top node is F is said to be the context of F.
+-----+
! F !
+-----+
!
!
+-----+
! R !
+-----+
!
!
+----------+----------+
! !
! !
+-----+ +-----+
! A ! ! B !
+-----+ +-----+
Figure 9.1-1 The context of F
A pathname is a sequence of idents, naming nodes along a path from one node to another. A full pathname in the context starts at the topmost node. Thus F.R.B is a full pathname in the context of F. A partial pathname starts at a node other than the topmost node (e.g. R.B, B).
In Datalanguage, pathnames omitting intermediate nodes, such as F.B (which omits 'R'), are not permitted. Thus partial pathnames are partial only in that additional names are implied on the left.
Three attempts at recognition of a pathname, PN, in a context, CX, are made:
(a) recognition of PN as a full pathname in CX
(b) recognition of PN as a partial pathname in which only the
topmost node of CX is omitted
(c) recognition of PN as an arbitrary partial pathname occurring
only once in CX.
The attempts are made in the above order, and the recognition process halts with the first successful attempt.
As an example, consider the description:
F FILE LIST
R STRUCT
A STR
B STR
S STRUCT
R STR
which defines the context in Figure 9.1-2.
+-----+
! F !
+-----+
!
!
+-----+
! R !
+-----+
!
!
+----------------+----------------+
! ! !
! ! !
+-----+ +-----+ +-----+
! A ! ! B ! ! S !
+-----+ +-----+ +-----+
!
!
+-----+
! R !
+-----+
Figure 9.1-2 Example Context
In this context, F.R.A is a full pathname. Thus, F.R.A is recognized in attempt (a). R is a partial pathname in which only the topmost node is omitted. Thus R is recognized in attempt (b). Note carefully that R is recognized as a reference to F.R, not to F.R.S.R. Finally, B is an arbitrary partial pathname occurring only once in the context. Thus B is recognized in attempt (c).
Two stacks of contexts are maintained: one for names used in an input sense, and one for names used in an output sense. When a name is to be recognized, it is first decided whether the reference is an input reference or an output reference. An input reference is (a) the right hand operand of an assign, or (b) a name in the input set spec of a FOR. An output reference is (a) the left operand of an assign, or (b) the output operand of a FOR. The first context on the appropriate context stack is then searched, according to the procedure outlined on the previous page. If the name is neither recognized nor ambiguous in that context, search continues in the next context on the stack. If the name can be recognized in none of the contexts on the appropriate stack, it is unrecognizable.
When a stack is empty, the recognition procedure is different. The search is carried on in a special context: The context of %OPEN. Its top node, %OPEN, is a built in system ident. Subordinate to %OPEN is a context for each open directory node. Each such context represents all the idents defined in the directory nodes having data descriptions:
F FILE LIST R STRUCT A STR (1) B STR (1)
and:
P PORT LIST R STRUCT A STR (1) B STR (1)
then the context of %OPEN would be as in Figure 9.1-3.
+-------+
! %OPEN !
+-------+
!
!
+-----------+-----------+
! !
! !
+-----+ +-----+
! A ! ! S !
+-----+ +-----+
! !
! !
+-----+ +-----+
! R ! ! R !
+-----+ +-----+
! !
! !
+-----+-----+ +-----+-----+
! ! ! !
! ! ! !
+-----+ +-----+ +-----+ +-----+
! A ! ! B ! ! A ! ! B !
+-----+ +-----+ +-----+ +-----+
Figure 9.1-3 The Context of %OPEN
When a directory node is closed, the corresponding context is removed from the context of %OPEN. When a node is opened, the associated context is added as the rightmost context subordinate to %OPEN.
9.2 Context Stack Maintenance
The context stacks are always empty between requests. The FOR-operator adds entries to the stacks. FOR A adds the context of A to the input context stack. FOR A, B ... adds the context of A to the output stack and the context of B to the input stack.
When adding to an empty stack, FOR adds two contexts instead of one. The second addition to the stack is the context of the looparg; the first addition is the context of the outermost container which encloses the looparg.
For example, given a context of %OPEN as in Figure 9.1-3, and empty context stacks, the fragment 'FOR F.R ...' adds two contexts: (1) the context of F, and (2) the context of F.R.
Contexts are removed from the stacks by the END matching the FOR which added them.