Structure of GDL
A GDL definition is a sequence of function requests where the function name is followed by a list of parameters in parentheses. Temporary numeric values and reference points and lines are assigned to names using an equals sign, and can then be used to build the geometric objects.
Formally, the structure of a GDL definition is described by the following grammar. The grammar is more difficult to follow than the examples but may be useful in determining fine points of syntax. In this grammar, the grammatical variable on the left (before the colon) is to be replaced by one of the sequence of objects on the right. Each sequence occupies one line as presented in this grammar, but does not have to be on one line in the final written definition.
Starting with the single variable "definition", the replacement of objects according to these rules continues until all objects have been expanded to a set of literal words or characters. The literal words are all the objects in upper case, as well as user-supplied expansions of "name" and "constant". The literal characters are colons, semicolons, and commas as shown in the expansions. If the rule allows "empty" as an expansion, then that position can be filled by a blank.
Notice that some of the rules contain the same object on the left and right sides. These objects can thus be expanded multiple times until the series is terminated by choosing a different object. In this way lists are formed. Comments can be placed anywhere, a space is allowed in the definition by delimiting them with /* and */. Keywords can be in uppercase or in lowercase, though all are shown here in uppercase. An example follows the grammar.
definition: declaration_of_parameters declarations
declaration of parameters: empty
PARAMS: parlist;
parlist: name
name, parlist
name: string of characters beginning with a letter (max 39 characters)
declarations: declaration;
declaration; declarations
declaration: name = primtype( list_of_expressions)
name = expression
operation(list_of_expressions)
primtype: POINT DIRECTION PLANE CURVE SECTION PIPED
SWEEP PLATE BEAM CYLINDER CONE EXCONE
DISH SPHERE TOROID FLANGE NODE ATTRIBUTE
SURF_OF_REV SHAPE_BSV INLINE_BSV BOOLEAN
operation: CUT DUPLICATE SEAMLESS TEMPORARY IMPORT3D
list_of_expressions: expression
expression, list_of_expressions
expression: expression + expression expression - expression
expression * expression expression / expression
-expression ( expression )
unary_func(expression) binary_func(expression, expression)
constant name
unary_func: SIN COS TAN ATAN SQRT INT
binary_func: POW
constant: string of characters containing a numeric constant
Example of formal GDL construction:
First start with the single object "definition" and apply the first rules
definition -> declaration_of_parameters declarations
We won't use any parameters, so the first of these objects is expanded to "nothing" using the rule
declaration_of_parameters -> empty
giving the single object:
declarations
This rule is expanded several times using the recursive rule
declaration -> declaration; declarations
to give
declaration; declaration; declaration
Thus the rule means that the declarations section is a list of declarations separated by semicolons. Expanding one of these with the rule:
declaration -> name = primtype( list of expressions);
and supplying a name and a primtype gives:
DRAIN = CYLINDER( list_of_expressions );
Usually the expressions in the inner list will be expanded to names or numerical constants, sometimes with simple arithmetic. For example, assuming p1, p2, and radius have already been defined:
DRAIN = CYLINDER(p1, p2, RADIUS + 10.0, 1);
There are other restrictions on the list of expressions that depend on the primitive being defined (see section 6.5).
So now we have produced a single "step" in the creation of a model. The two other declarations will also produce steps that either create primitives, assign an arithmetic value to a variable, or cause an action to take place.
Parameters
Parameters can be introduced to increase the elasticity of the definition. Thus for example one definition can be used to create geometric models for a whole family of pumps. The parameter values are supplied when the model is generated. The parameter declaration, if it exists, must be the first declaration in the definition. Parameters can be used in numeric expressions and they are considered floating point constants when the geometric model is evaluated.
Temporary variables
Temporary variables can be defined by assigning a numeric expression to a name. This makes it easier to use the same constant in multiple locations and change them all by changing the assignment to the temporary variable. This use of variables is similar to the use of parameters, but the values are in the GDL file itself and cannot be changed when the model is constructed.
Note: A name can appear only once on the left side of the assignment. In other words the value of the temporary variable cannot be changed further down in the GDL file.
Numeric expressions
Numeric expressions can contain basic arithmetic operations: addition, subtraction, multiplication, and division.
Multiplication and division have precedence over addition and subtraction. Unary minus has precedence over all other operations. Parentheses can be used to define the order in which expressions are evaluated; otherwise evaluation takes place from left to right.
Intrinsic functions
The following built-in functions are available:
sin cos tan atan sqrt pow int abs atanr
Arguments for trigonometric functions can be either in radians or in degrees. If variable _UseDegrees is not defined in the gdl file then values are in radians, otherwise values are in degrees. Arctangent (atan) also gives also the result in radians or degrees depending on the presence of the above mentioned variable. Function atanr(x) always returns its value in radians.
The power function pow(x,y) raises the base x to the power y: xy . The following situations result in an arithmetic error during computation of a geometric model:
x < 0 and y is not integer
x = 0 and y is negative
The square root function also results in an arithmetic error if its argument is negative.
Function int removes the fractional part of its argument so that it performs rounding towards zero.
Function abs returns the absolute value of the argument.