JACQUESCOHEN~,GREGORYFINNS and DANIELPFAU$ Brandeis University, Waltham, Massachusetts 02 154, U.S.A. A&raet---This paper describes a computer language enabling its users to define three-dimensional truss structures. The language can be used either as a design tool in specifying the geometrical characteristics of these structures or as an input language to a program that actually performs their structural analysis. The main characteristic of the language is that it is procedural; programs defining a nucleus of a structure can be made into procedures (subroutine) which can be called within programs and other procedures in order to define more complex structures composed of that nucleus or its variants. This characteristic is particularly useful in defining repetitive geometrical patterns which themselves appear within repetitive pattems.The paper also describes a syntax-directed compiler whose input is a sentence in the language and whose output is interpretable code which, when executed, produces drawings and provides listings of the coordinates of the points and the linkages defined by the user in his source program. Several examples of structures detined using this language are inc!uded in the paper.
1. INTRODUCTION THE INCREASING availability of compiler generators [6,2, !YJhas encouraged computer users to develop their own problem-oriented languages. This paper describes one such language which is useful in defining spatial trusses. The definition has two purposes: (1) to enable a designer to evaluate the geometrical characteristics of a structure, or (2) to provide input data to a computer program which will actually perform the structural analysis of the specified structure (such as in [4]). A few of the typical structures considered by the authors as being conveniently described by means of a computer language are depicted in Figs. 3(a), 6(b), 8 and 11; a large number of similar structures are presented in [I]. Some of the common geometrical features of these structures are that they contain a large number of regularly located points, and that the members linking these points exhibit regular patterns which may themselves be imbedded in other regular patterns. The above features suggest that a language for describing these structures should include general iterative and procedural capabilities, It was also felt that the following were the most desirable characteristics in designing the language:
(a) Simplicity, @I Power of expression,
(c) Safety, (4 Ease of implementation. t Physics Department. # Senior student, Physics Department. 3 Senior student, Mat~~ti~ Department. 829
830
JACQUESCOHEN,GREGORYFINN and DANIELPFAU
Characteristics (a), (b), and (d) are attainable as a consequence of adopting a procedural type of language, i.e. one in which statements can be combined to form a procedure, a call of the latter being itself considered as a statement of the language. Characteristic (c) is achieved by allowing the user to access only the information that has been previously defined, and by providing language constructs which reduce the possibilities of programming errors. It was with this characteristic in mind that the authors did not allow the use of GO-TO’s in this language, but provided a variety of iteration and case statements such as those which have been suggested in [3]. The formal Backus-Naur-Form description of the language’s syntax is given in the the Appendix; the description of its compiler is presented in Section 4. The syntax and semantics of the language are informally described in the next section by means of examples. 2. LANGUAGE DES%RIPTION A program in this language consists of a declaration part followed by a main program part; the entire program is enclosed between the symbols begin end, and a semicolon is used as a delimiter between statements of the language. In the declaration part, the user specifies the variables that are used in the program. The declaration part may also contain the definition of procedures to be called in the program. Variable declarations are described in Section 2.1 and procedures in Section 2.3 The executable statements of the language, i.e. those that constitute a program part, are grouped into two classes: (1) Point definition statements (P-statements),
and
(2) Linkage definition statements (L-statements). For safety reasons, P-statements must always precede L-statements, and a special delimeter (#) is used to separate the P-statement part from the L-statement part. Certain statements, such as those utilized in iterations, are considered valid as either P-or-L-statements. It should be noticed that the syntax of the language forces its user to first define all points of a structure before defining the linkages between them?. The description of P, L and P-or-L-statements is given in Section 2.2. Finally, the standard functions and procedures (including input and output) which are available to the user of the language are described in Section 2.4. 2.1 Variable declarations There are four types of simple variables in the language : integer, real, point and direction. The variables are given identifier names as in most programming languages, and as it is commonly done, variables cannot be declared twice, and the same name cannot be utilized to specify two different types of variables; integer and rea2 variables are handled as in Algol 60 [7]. A point variable is used to define a point in space, and , similarly, a direction variable is used to define a direction. For example, the declaration : integer i ; real t-1,r2, pi; point a, b, c, d, e; direction p; defines the given integer, real, point and direction variables which will contain specific values when the assignment statements of the language are executed; point and direction variables can also be declared as being arrays of any dimension.
t It should also
be noticed that points may be defined which are not the part of any linkage. points are reported to the user as it will be shown in Section 4.3
These
831
A Language for IMining Spatial Trusses
For example, the declaration: point array Pl, P2, Q3 [SO] ; direction array RADIAL [4,30,1 OJ ; defines the one-dimensional point arrays PI, P2, Q3, each of which has 50 as maximum dimension, and the three-dimensional direction array RADIAL whose maximum dimensions are 4,30, and IO. 2.2 Executable statements 2.2.1 P-statements. Points can be defined in a variety of ways. The simplest assignment of a value to a point variable has the form : p 4- cart [x, y, z]
in which p can be a simple or subscripted point variable and x, y, and z are real (or integer) variables. Actually X, y, and z can be any arithmetic expressions using real and integer variables. The above statement assigns the coordinates whose values are the numbers indicated by X, y and z to the point p (see Fig. la). If the arithmetic expressions corresponding to x, y,z contain integer variables, their evaluation follows the integer to real conversion rules utilized in Algol60 [7]. Therefore, the P-statement:
(a)
2
(b)
= /
r P( X,Y.Z 1 ‘2 x
_____z x
__ Y 2
(d)
t
/‘d2 : e--d,
2
(e) /
__+P(~I,PI.~~.P~) b/
x
/
-.
//
/’
/
,d P'P,
,d,L)
x
PO
Y/ FIG.1 P1[i*2.OJtcart[3*sin(3.1415/j),
4, rl*r2]
is a valid assignment if i, j, r 1and r 2 are either real or integer variables, and Pl is a one-dimensional point array whose maximum dimension is not less than the computed subscript. A point can also be defined by using other types of coordinates. For example: 4 + Wnd CP, e, 23 assigns to the point variable q (subscripted or not), the Cartesian coordinates X, y, and z which are computed from the cylindrical coordinates p, 8 and z (see Fig. lb). As in the previous case, p, 0, and z can be any arithmetic expression, the angle 8 being expressed in radians.
832
JACQUESCOHEN,
GRW~ORY FINN and DANIEL PFAU
Similarly, assigns the Cartesian coordinates computed from the spherical coordinates p, 0, and 4 to the point variable r (see Fig. lc). Other means of assigning values to point variables involve the use of directions. A direction variable, subscripted or not, can be assigned a value using a statement such as : t +-from
p to q
in which the direction t is defined as parallel to a line passing through the points specified by p and q, where p and q are either names of previously defined points or explicit values of their coordinates. Therefore, RADIAL[i, j, k*2] + -from curtC0.0, 1.&i, 2.0]to sphere[i*pi, rl, r2] is a valid direction assignment to an element of the direction arra_yRADIAL. Directions are useful in defining points which either lie on a given line in space, or at the intersection of two lines. Lines are represented in the language by a previously defined name (or explicit value) of a point in space and previously defined name (or explicit value) of a direction. For example, the assignment: s t
inter [dl thru al, d2 thru a21
assigns as the value of the point variable s the coordinates of the intersection of the line passing through point al and having the direction dl with the line passing through point a2 and having direction d2t (see Fig. Id). Notice that in the above definition, any of the variables dl, al,d2, and a2 could be replaced by language constructs defining points or directions. A final command for defining a point is illustrated by the following example : P + polar
[PO, 4
Ll
in which the value of a point p is defined by the coordinates X, y, and z of a point lying on a line passing through the point po, parallel to the direction d, and at real or integer distance L from po (see Fig. le). The ability to use point and direction definitions imbedded in other point and direction definitions allows one to write statement such as: P [i, j] c inter [from inter [dl thru curt [*, 1.0, 2.0 *i], from polar [P [i,.j], D
UIT
distance]
to cylind[distance, pi/2, pi/j] thru P[l, i]] to P [2, i] thru S, R thru Q] in which P is a point array, D a direction array, dl and R are directions, S and Q are points and the remaining variables are of integer or real type. Also notice that, as shown in the
above example, the value of a point can be changed by assigning a new value computed from its previous one. t
If the
two linesdo not intersect at a unique point a run-time error-messageiSgivento the User.
A Languagefor DefiningSpatialTrusses
833
A convenient P-statement is the one that enables the user to delete previously defined points. The command : delete point p
in which p is the name of a point which had been previously assigned a value, marks the point as no longer having a value, and it is disregarded if such definition had not occurred. This feature is particularly useful when creating quasi-regular patterns of points; first, a regular pattern of points is defined by means of iterative or procedural statements (see Sec2.2.3 and 2.3); then, points which are judged unnecessary are eliminated via the delete command. P-procedure calls (which are valid P-statements) are described in Section 2.3. 2.2.2 L-statements. Linkage of previously defined points is accomplished by a link command. There are two basic variants of the link command. The first enables the user to link the same pomtp, to points pI, pz ,... pn t (see Fig. 2a) and has the form : Iink p. to PI, ~2, , p3 . . . . ..P. The second enables the user to connect points pz to p2, p2 top3,.....p,l and has the form: link p1 to pz to p3 to . . ..P.+_~ top,,.
/v PI
(a 1
p2
po
p3
p”
***
p4
(b)fFp3 :. i,“, n
(cl
I/u FIG. 2
t Notice.that some of thepss might refer to the same point.
e
top,? (see Fig. 2b)
834
JACQUESCOHEN,GREGORYFIN and DANIEL
PFAU
The above two types of link commands can be combined to establish linkages more complex patterns. For example, the command :
having
link d to a, e, b to a, c, e to c
is equivalent to the series of commands : link d to a, e, b; link b to a, c, e; fink e to c;
and tnc pattern of linkages it establishes is the one depicted in Fig. 2c. It snould be pointed out that the commands link a to b; Iink & to a;
are equivalent, since linkages in this language are assumed to be non-directed straight line segments. Two or more linkages of the same pair of points are admissible (and sometimes quite useful) to execute in an iteration but, upon program completion, only one is considered as having taken place. It is also possible to have differently named points occupying the same position in space, and therefore to have two links that physi~liy occupy the same region in space, but actually connect differently named points. A list of points having identical coordinates is available to the user so that occurences of (unwanted) coincident links can be checked (see Section 4.3). It is possible to delete previously defined linkages by the command : delete Iink pI to p2
which deletes a previously defined linkage between pl and p2 (or it is disregarded if such link does not exist). Actually, the link list following the basic symbols delete link can be of the most general type involving to and comma lists, as explained in the beginning of this subsection. Similarly to the case of point deletion, the deletion of previously defined links can be useful when defining quasi-regular structures; first, a regular structure is generated using iteration or procedure calls and then certain links are removed to achieve the desired effect. The remaining L-statements are standard procedures which output information about the points and linkages defined by a user in his source program. These standard procedures will be described in Section 2.4. L-procedure calls are also valid L-statements and are described in Section 2.3. 2.2.3 P-or-L-statements. The simplest P-or-L-statement is an assignment to a real or integer variable. The left hand part of the assignment is a simple integer or real variable and the right hand part is an Algol 60 arithmetic expression and its evaluation follows the rules of Algol 6Ot;. Examples of assignments are: pi t 3.14159; rl c SIN(pi/2)&i+ t The standard trigonometric language (see Section 2.4).
c;
functions available in Algol 60 are also available to the user of this
A Languagefor Defining SpatialTrusses The iteration s~tement has two forms. The first is illustrated by the follo~ng
835
example:
fur i c 1 step I until n do ---; in which the p, L, or P-or-L-statement
following it will be executed repeatedly with the same conventions as in [7]. Two or more statements can be executed repeatedly via the for statement by enclosing them between the delimiters begin and end. The second type of iteration is the while type, illustrated by the following example: while i < 2~ do -- ; In this case the statement (or group of statements delimited by begin end) following the symbol do is repeated until the boolean expression i c 2*n becomes false. The classical if then is also a valid P-or-L-statement and follows the semantic rules of Algol 60. A variant of the Algol switch (or Eortran computed GO TO) is available in the form of a case statement [3]. The P-or-L-statement : case i of -__ ; --
; -__ ; . . . ____end
has the following semantics: the arithmetic expression following the symbol cme is evaluated as an integer i and control is transferred to the ith statement following the symbol oft. After this latter statement is executed, control is transferred to the statement following the symbol end. A comment in this language has the following form : ~~rnrne~tthis is a comment; or, ! this is a comment; The string between the delimiter comment (or the symbol !) and the semi-colon has no semantical meaning, its only purpose being to document source programs. A comment is considered to be a P-or-L-statement and can also appear between two semi-colons in a declaration part. 2.3 Procedures One or more P-statements can be combined to form the body of a P-procedure, i.e. a procedure for point definition. A call of this procedure is itself a valid P-statement and therefore such a call may appear in the body of another P-procedure. Similarly, L-procedure bodies are formed by combi~ng L-statements and the latter could contain L-procedure calls. Although P-procedure declarations can appear intermixed with L-procedure declarations, a P-procedure call can only appear as a P-statement and an L-procedure call as an L-statement. If a procedure S, has in its body a call to procedure S,, which in turn has in its body a call to procedure S,, and so on until the call of S,, these calls are valid if and only if all the S,‘S are different; that is, no recursive P or L-procedures are allowed in the language. Procedure declarations involving formal parameters must specify the nature of each of its parameters. Valid parameters for P-procedures are integers, reals, points, directions, point arrays and direction arrays; valid parameters for L-procedures are integers, reals, points and point arrays. The variables appearing in a procedure body should either be formal parameters or global variables declared at the beginning of a program. An example of a P-procedure declaration is as follows : t .b in the case of the instruction following the for statement, several instructions can be grouped into one by enclosing them between the symbols begin and end.
836
JACQUES COHEN, GREGORY FINN and DANIEL
PFAC:
point procedure mast (A, pt, dn, k, n): point array A; point pt ; real k; direction dn; integer n: ,for i c I step I until n do A [i] +-polar [pt, dn, h* (i-l)]; where i is a global variable: A, pt, dn, h, and n are formal parameters of the given type and the objective of the procedure is to define points of the point array A as IEpoints on a line passing through thepointpt and having the direction dn; then points are located at a distance Iz from each other. The call: mast (P, curt [O,0, 0 1,from cart [0, 0, 0] to cart[O, 0, I], 3.5, 10) defines IO points in the array P (declared as having a dimension of at least 10) which are points in the z-axis and located at a distance 3.5 units from each other. An example of a link procedure is as follows : link procedure truss (a, b, c, d, e); point a, b, c, d, e; link d to a, e, b to a, c, e to c; This procedure defines linkages of the five given points uniting them in the pattern shown in Fig. 2c. A call of this procedure should contain as actual parameters the names of previously defined points. Therefore, if A [i], B[j], C[k, 11, D, and F[.i] are five points whose coordinates have been defined in a point definition part, the call: tru.ss(A[il, BUI, CR, 11,D, WI, would link them according to the topology of Fig. 2c. 2.4 standard ~~nctio~~~and procedures As in Algol 60, standard functions and procedures are available to the user of this language. Their purpose is to provide input-output capabilities and to perform computations which commonly appear in programs. The trigonometrical functions (SIN, COS, TAN) and the functions to perform square roots (SQRT) may be called m arithmetic expressions within P or L-statements. The unary functions XPRQJ, YPROJ, and ZPRQJ are real functions havmg a point as argument and can be used in any arithmetic expression appearing on a P-statement part of a program. As their name indicates, the result of each is the x, y, and z projections of the point in question. The input and output of real or integer variables is a valid P-or-L-statement. The procThe procedure IN(r) assigns to the real or integer variable v the next value input as data. edure OUT(r) prints the value of the variable Y as an integer or real number depending on its type. The P-or-L-procedure OUTSTRING, whose argument is a quoted string, is also available to print messages. The standard procedure PRINT, having a string as parameter, outputs the coordinates of the points defined by the user and their linkages; this information has the string with which the procedure is called as a heading. The procedure PRINT, as well as the others described in the remaining part of this section, can only be called within an A-statement part. The standard procedure DISPLAY, which has a string as its parameter, plots the projection of the structure defined by the user in the planes perpendicular to the x, y, and z axes, each plot having as heading the string specified by the parameter. Finally, the standard procedure PERSPECTIVE can be called to produce perspectives of structures which have been defined. This procedure has five parameters: the first three are real or integer numbers which describe the position of the plane onto which the perspective is drawn; the fourth is a point which represents the position of the observer’s eye; the fifth is a string to be used as heading in the plot. Examples of the use of the standard functions and procedures are presented in the following section.
837
A Language for Defining Spatial Trusses 3. EXAMPLES In this section four examples of the use of the language are presented:
3.1 Tower The tower shown in Fig. 3a is one of the outputs of the source program given in Fig. 4. The base of the tower rests on the three points pl, p3 and p5, the vertices of an equilateral triangle whose side’s length is 2*D (see Fig. 3b). The points pz, p4 and p6 are needed to define the middle points of each side of the tower. The points pt to ps are represented by the point array P of dimension 6. The variable VERTICAL defines the direction of the z axis. The points of the tower are represented by the point array COLUMN whose dimensions are 6 (the number of points needed to define a horizontal cross-section) and 20 (the maximum number of levels in the tower). Thepointprocedure PV is used to define N equidistant points on a line passing through the point PT, having direction DiV, the points being at a distance H from each other. The link procedure L links the five points Tl to T5 according to the pattern shown in Fig. 3c. Notice that the linkage between the points Tl and T5 is unnecessary since an iteration is used to connect the points around the tower and the vertical links need to be established only once.
fbf
(a)
/u T
(Cl 2
/J--
5
X
Y
FIG. 3
T
Ti
7-4
838
JACQUES COHEN, GREGORY FINN
and
DANIEL
PFAU
The main program of Fig. 4 first reads and prints the values of D, H, and Iv; in the particular case of Fig. 3a, these values are respectively 1.0 (units), 1.5, and 16. The actual coordinates of the base points P [1] to P [6 ] are then computed, as well as the direction VERTICAL. The last statement in the P-statement part is an iterative call of the procedure PV to assign values to all the points of the tower.
The linkage part of the program consists of an iterative call of the procedure L to link the points of the array COLUMN.
The PRINT command at the enct of the ~-statement part produces the output shown in Fig. 5. Figure 5a presents a (partial) listing of the coordinates of the points defmed by the program and a list of points having identical coordinates. Figure 5b presents a Gavin) Wing of the distances between any two points that have been linked. Figure 5c lists a part of the connectivity (linkage) matrix?. The result of the command PERSPECTIVE is depicted in Fig, 3a. Notice that it suffices to: (1) introduce a direction array containing six directions representing those of the lines passing through points P [ I ] to P[ 6 J and converging to a point in the z axis, and (2) modify the call of the procedure PY so as to use the six elements of that array, in order to define a tower in which the columns are slanted instead of being vertical. 3.2 Lattice grid The lattice grid shown in Fig. 6a is one of the numerous examples which appear in Borrego’s book [l J. The program shown in Fig. 7. produced the plot presented in Fig. 6b. The program can be briefly described as follows. t It should be recalled that the triangular matrix linkage only records the links (i,j) for i>j; if i< j the element (j, 6’)should be inspected to check for a linkage.
842
JACQUES
COHEN, GREWJRY FINN and
DANIEL PFAU
(b)
z
LL Y
x
-
1% I 10
I-rux
.a
RIGHT ,036
TRIANGULAR -1e.888
.BdB FIG. 6
LATTICE EIE R)IM
NETWORK 73.0%
-l,.BBB
14.88
A Janguage for Des&
Spatial‘huws
843
Two two-dimensional arrays TOP and BOTTOM are utilized to describe the top and bottom points of the grid. The point procedure GRID creates a matrix of points parallel to the x, y plane and at a distance ZCON from it. XCON and YCON specify the distance between the points along the x and y axes. XLIM and YLIM are integers specifying the number of points along the x and y axes. The link procedure BRACE unites the three top points 7’1, T2, T3 to the bottom points Bl, B2 according to the patterns shown in Fig. 2c (without) the link c-e). As in the case of the previous example, the main part of the program consists of two calls of the point procedure GRID to set up the top and bottom points, followed by a (doubly) iterative call of the Zinkprocedure BRACE to establish the linking. This latter procedure is called twice within the double loop to perform the linking of an element (see Fig. 2c) and its symmetric counterpart with respect to the diagonal (i.e. a line passing through points TOP [ 1, l]] and TOP [7,7]), Notice that the vertical linkage between the top and bottom points of the grid is performed twice, except for the points lying in two of the boundaries; this repeated linkage does not, however, effect the definition of the structure Also notice that the linkage of the points TOP[7, 7] and BOTTOM [4, 41 is performed separately, that is,outside of the double loop. Finally, it should be remarked that the points corresponding to the middle of the squares of the top level (i.e. TOP [2,23, TOP [2,4], etc.) are utilized in the program for convenience only and no linkage stems from them, These points are reported to the user by the standard procedure PRINT. Only the result of the call to draw a perspective (that of Fig. 6b) is presented in this paper.
3.3 lZome The dome shown in Fig. 8 is defined by the program in Fig. 9. The center point, located on the z-axis, 300 units above the origin, is linked to the twelve points on the innermost circle (see Fig. 1Od). Each circle is composed of twelve more points than the circle immediately inside of it, It should be noticed that points at the intersection of each circle and the lines emanating from the center point have three links to the surrounding circle. Every other point on the circle has only two links. The strategy employed in this program is to create the links defi~ng the concentric circles and then to define the linkages between each pair of adjacent circles.
844
. ?> ‘i *
Fro. !3
A Languagefor DefiningSpatialTrusses
845
The point procedure CIRCLE defines NP equidistant points, along a circle of radius D centered Z units above the origin, by using cylindrical coordinates. The link procedure AROUND connects NP successive points to create the cords approximating a circle. The two link procedures LINK3 and LINK2 create the links between an inner and outer circle, LINK3 creating three links and LINK2 creating two. In these procedures, the parameter INDEX denotes the link end point on the inner circle, and the parameter N denotes the number of the outer circle. Finally, the link procedure FINISH connects the first point of the array representing the inner circle to the first, second and last points of the array representing the outer circle. This procedure is necessary in establishing the continuity of the structure.
~TSITO
.67
ItnmsPTPtUE
CIRCLES .e63
,020
FOR STADIUM 4.m
DOME FIE POItn
FIG.1&3
.8D
.81*
6.W
JACQUES COHEN.GREWRY FINNand DANIELPFAU
846
/
FIG.
x
lob
8WFI8,TO
.67
CIRCLES
IHTfRCEPTPLMr .90a
AND LINKS
,088
FROM TOP OF,DOME
MPPiNT .BdB .F.w
4.669
c*
_ _--.__
,,/;;__-
---------.--
__:I-., .-‘-
’
-..
I/
CIRCLES Fla
1Oc
exuFI(IIrn
47
*HIFRww
.eu2
A
,/ /
‘.
\
-‘\
..
----._
./
-. \
--._,.
\
/----
,.’
AND EjiTGIi\lNING
.BBB 4.m
OF LINKS
E(F. P?I.+T .D88
BETWEEN
.Bao
CIRCLES
6.m.
A Lmguage for IMining Spatial Trusses
All the necessary points are created by six calls of the pointprocedure CIRCLE, one call for each of the circles whose points are stored in the arrays ONE, TWO, THREE, FOUR, FIVE and SIX. The points are linked to form polygons inscribed in the circles by calling link procedure AROUND six times (a snapshot of this linkage is seen in Fig. lOa), Then the center point is connected to the twelve points of the first circle (see Fig. lob). Every point in ONE has three links to TWO, therefore LINK3 is called twelve times within afor statement to establish these linkages (see snapshot in Fig. 1Oe). For each subsequent pair of adjacent circles, there is an additional point with two links between each pair of points with three links; for example, for the pair of circles whose points are stored in TWO and THREE, there is one two-link point between each pair of three-link points and for THREE and FOUR, there are two two-link points between each pair. All circles are divided into sections containing one three-link point and the proper number of two-link points. The links in a se&ion are created by repeated calls of LINK2 and one call of LINK3. The complete dome is defined iteratively by establishing the links in every section of each circle. A view of that structure as pIotted by the program appears in Fig. 8, 3.4 itact& ~~~ A simplified radar aerial pictured in Fig. 11 has also been defined in this language, but only a brief description of its program is being presented in what follows. The periphery of the radar has the shape of an ellipse centered at the origin. Points along this major
848
JACQUES COHEN,GREGORY FINNand DANIELPFAU
ellipse are created using Cartesian coordinates. The elliptical trusses perpendicular to the to the plane of the major ellipse are defined by P-procedures. Calls to linkage procedures are then used to connect the points in order to achieve the bracing depicted in Fig. 11.
x
I
t
vfxwz*lm
.*
DnWTM
CUTOUT *.w
.L
VIEW OF RADAR 9.m
AERIAL
E*EPOM
*(.#a
*.*L
rt.eo
FIG. 11
4. IMPLEMENTATION The nucleus of the compiler for the language described in the previous section has been produced by a compiler generator [2] using the syntax rules presented in the Appendix. The Actions generator actually produces a syntactical analyzer needed to drive the translation. were subsequently incorporated to the analyzer in order to output pseudo-instructions which, when executed, perform the tasks required by the user in his source program. These pseudo-instructions (actually post-fixed notation as in [8]) are simulated by an interpreter described in Section 4.2. In Section 4.1 a description is given of the data structure utilized by the interpreter. 4.1 Data structure Three uni-dimensional real arrays X, Y, and 2 are used to store the actual coordinates of the points defined by the user in his source program. Even when a point is defined in coordinates other than cartesian, a conversion to the latter takes place; a point is therefore represented internally as a pointer (or index) to the parallel arrays X, Y, and 2. Similarly, point arrays are arrays of integer indices to the real arrays X, Y, and Z.
A Languagefor DefiningSpatialTIUWS
849
Directions are internally represented as a pointer i to the arrays X, Y, Z and indicate directions parallel to the line passing through the origin and the point (XYI, Y[il, ZPl> AS in the case of point arrays, direction arrays are pointers to X; Y, and Z. The boolean array Exist, initialized to false (or zero), is utilized for checking if a point declared by the user has been assigned a value at a given point of the execution of a program. The triangular boolean array Linkage, also initialized to false (or zero), stores the linkages specified by the user in his program. Linkage [i, j]t is true only if a link command to unite point i to point j has been executed, and is reset to false if the corresponding link is deleted. In the actual implementation, both arrays Exist and Linkage are bit arrays so that a large number of points can be defined by the user of the language. The interpreter also utilizes the array Stack as the working stack for evaluation postfixed polish notation. 4.2 Interpreter The first pseudo-instruction of an object program executed by the interpreter is the one which initializes the bit arrays Exist and Linkage to zero (false). Each time a point is defined, its Cartesian coordinates are stored in the X, Y, 2 arrays and the corresponding bit of the array Exist is turned on. As mentioned before, coordinates specified by cylindrical, spherical, polar and intersection definitions are transformed into their Cartesian counterpart. This is done by interpreting the pseudo-instructions (operators ‘cylind’, ‘sphere’, ‘polar’ and ‘inter’ which act respectively on the 3rd, 3rd, 3rd, and 4th topmost elements of the Stack and produce a pointer i to the arrays X, Y, and 2 in which the equivalent Cartesian coordinates are stored. Arithmetic expressions and assignments are handled as in [8]. Link commands are interpreted via the pseudo-instruction ‘link’ which, when executed, operates on the two topmost elements of the Stack (i.e. two indices of the arrays X, Y, Z) and turns on the corresponding bit of the array Linkage. Since only the bottom tria’ngular bit matrix is used in this implementation, the two indices i and j must satisfy the condition: i > j. If this condition is not met, the bit specified by Linkage u, i] is turned on (instead of Linkage [i, j]). 4.3 Error and warning messager Error messages are essential in providing the user withinformation enabling him to correct his program; warning messages report to the user the existence of conditions which, although valid in the definition of a structure, should be brought to his attention for safety reasons. The compile-time error messages include those which are normally available in compilers; that is, they indicate purely syntactical errors, errors involving undeclared variables or variables which have been declared twice. Other error messages are those signaling an unmatching number (or types) of formal and actual parameters, and overflow situations in which too many points or directions are declared in a source program. Run-time error messages include those reporting subscripts outside the declared bounds of arrays, attempts to create a direction using points with identical coordinates, or to define points using the intersection of non intersecting lines. A run-time error message is also issued during the execution of a link command involving undefined points. All the run-time t If i
< j
then Linkage u, i] is used.
JACQUB COHEN, GREGORY FINNand DANIEL PFAU
850
error messages are fatal, i.e. their occurence triggers the end of a program’s execution. Warning messages are printed by the call of the standard procedure PRINT, and they provide the following information : (1) a list of declared but undefined points, (2) a list of points having identical coordinates, and (3) a list of points which have not been linked. 4.4 Details of the current implementation The compiler and interpreter for the language described in this paper are operational on a 64K PDP-10 computer at Brandeis University. Both compiler and interpreter are Fortran programs in which the only machine-dependent subroutines are those necessary to perform bit storage and retrieval. The compiler contains approximately 1700 Fortran statements and the interpreter about 1300. These programs can handle structures having up to 1200 points, but this limitation could be extended if more memory space were available. The results are printed on a line printer or teletype and the drawings plotted on a Calcomp 565 plotter. The example of the tower presented in Section 3.1 took 32 CPU seconds to compile and execute. The present versions of the compiler and the interpreter are available from the authors. As mentioned before, these programs are mostly Fortran programs with a few assembly language subroutines which are specific for the PDP-lo-Calcomp 565 configuration. 5. FINAL REMARKS It is apparent from the description of the language and from the examples presented in this paper that it is possible to write a variety of programs capable of defining the same structure. This variety, which expresses the semantic richness of the language, enables the user to select the “best” among several programs defining the same structure. The criteria for this selection may not necessarily be the shortness of a program. If the output of the definition serves as an input to another program that performs structural analysis, it is important that the non-zero elements of the matrix describing linkages be as close as possible to the diagonal. This characteristic is relevant in reducing the computation time and increasing the accuracy of the solution of the simultaneous equations needed to compute member stresses. If two or more programs for defining the same structure are available, a simple computation can help one decide which program is optimal according to this criteria?. An interesting feature that can be easily implemented is the capability of presenting in a graphical display (rather than a plotter) the perspective of a structure. By iterating the perpective command, one can vary the position of the coordinates of the observer’s eye and therefore obtain movies (series of snapshots) that show views of a structure taken by a camera promenading around it. More elaborate programs eliminating hidden lines are now available to enhance the visibility of objects and could be used in connection with the programs described in this paper. Several additional features could also be incorporated in the language; among these one should mention the following: (1) Commands to perform the translation and rotation of points, (2) Language constructs enabling one to define points and linkages of separate structures to be subsequently assembled, (3) Commands defining loads acting on structures at given points and directions. t
A constant expressing the degree of closeness to the diagonal is printed by the program which out. puts the linkage matrix.
851
A Language for Defining Spatial Trusess
‘The authors also feel that the experience gained by the actual use of the language in its present form should provide more insight as to which of the current features should be refined or modified. Such refinements and modifications are easily attainable by the use of a compiler generator. Finally, it should be mentioned that an approach similar to the one adopted in this paper could be used in the design and implementation of a language for solving finite element problems. REFERENCES [l ] J. Boannoo, Space Grid Structures The MIT Press, Cambridge, Mass. (1968). [2] J. COHEN et al. A compiler generator, Brandeis University (1972). [3] 0. J. DAHL, E. W. DIJKSTRAand C.~A. R. HOARE,StructuredProgramming Academic Press, New York (1972). [4] S. J. PIZNVES et al. Stress: A Reference Manual The MIT Press Cambridge, Mass. (1965). [5] D. Gauzs, Compiler Construction for Digital Computers Wiley, New York (1971). [6] W. M. MCKEEMAN,J. H. HORNING and D. B. WORTMAN,A ComDiler Generator Prentice Hall New Jersey (1970). [7] P. NAUR (Editor) Revised report on the algorithmic language, Algol60, Comm ACM, January (1963). [8 ] B. RANDALL and L. J. RIBELL, AIgol60 Implementation Academic Press, New York (1964).
APPENDIX BNF Dejnition -zprogram> < declarations
qf the Lmguaget
: : = begin and instructions > : : =
: : =
: : =
c instructions> -cdeclarations>
-cdeclarations > -cdeclaration> -csimple type>
: :=
: :=
: :=
1
integer 1 real 1 point / direction point urray I direction array
identifiir
: : =
;
; -cprocedures> 1 ; -einstructions >
< list> 1 -z array list >
end
I
identifier
< array list > , -c array segment >
: :=
< dimension list > : : =
identifier identifier
i
c array segment > list>
, integer
/ 1 ]
I
t Notice that the symbols identifier and number are defined as in Algol60. Also div stands for integer division.
;
852
JACQUES COHEN,GREGORYFINN and DANIELPFAU
: : ;=
4instructions> -zprocedures>
: := : : =
c point definition instructions> < linkage definition instructions > < procedures >
; c procedure> 1 -cprocedure> identifier ; i compound point instruction> / link procedure identifier ; / point procedure identifier ( < formal parameter list > ) < specification list > c compound point instruction> ( link procedure identifier ( < formal parameter list > ) ; i specification list > : c compound linkage instruction-p point procedure
< formal parameter list > : : =
i formal parameter list > identifier [ identifier
: : --- c specifications> < specifications: a
list>
< specifications > : : =
-Cpoint definition instructions > : : 7
< point definition instruction > : : =
: : z : : = identifier
list>
: : =
#
/
.
;
1
i point definition instructions> < point definition instruction> -cpoint definition instruction>
; 1
< point definition> 1 c direction definition > / 1 i < point procedure call> 1 i assignment > 1 < point if instruction> i point case instruction> 1 < input output instruction>