Skip to main content

III. The Form Machine

Input/Output Streams and Forms​

This section describes the syntax and semantics of forms that specify the data reconfigurations. The Form Machine gets an input stream, reformats the input stream according to a form describing the reconfiguration, and emits the reformatted data as an output stream.

In reading this section it will be helpful to envision the application of a form to the data stream as depicted in Fig. 5. An input stream pointer identifies the position of data (in the input stream) that is being analyzed at any given time by a part of the form. Likewise, an output stream pointer locates data being emitted in the output stream.

    /\/\                                                  /\/\
^ | | FORM | | ^
| | | ----------------- | | |
| | | +- ----------------- -+ | | |
| | | | CURRENT PART OF | | | |
INPUT | |<= CURRENT < ----------------- > CURRENT => | | OUTPUT
STREAM | | POINTER | FORM BEING APPLIED | POINTER | | STREAM
| | +- ----------------- -+ | |
| | ----------------- | |
| | ----------------- | |
| | ----------------- | |
\/\/ \/\/
Figure 5. Application of Form to Data Streams

Form Machine BNF Syntax​

form           ::=  rule | rule form

rule ::= label inputstream outputstream ;

label ::= INTEGER | <null>

inputstream ::= terms | <null>

terms ::= term | terms , term

outputstream ::= : terms | <null>

term ::= identifier | identifier descriptor |
descriptor | comparator

identifier ::= an alpha character followed by 0 to 3
alphamerics

descriptor ::= (replicationexpression , datatype ,
valueexpression , lengthexpression control)

comparator ::= (value connective value control) |
(identifier .<=>. control)

replicationexpression ::= arithmeticexpression | <null>

datatype ::= B | O | X | E | A

valueexpression ::= value | <null>

lengthexpression ::= # | arithmeticexpression | <null>

connective ::= .LE. | .LT. | .GE. | .GT. | .EQ. | .NE.

value ::= literal | arithmeticexpression

arithmeticexpression ::= primary | primary operator
arithmeticexpression

primary ::= identifier | L(identifier) | V(identifier) |
INTEGER

operator ::= + | - | * | /

literal ::= literaltype "string"

literaltype ::= B | O | X | E | A

string ::= from 0 to 256 characters

control ::= : options | <null>

options ::= S(where) | F(where) | U(where) |
S(where) , F(where) |
F(where) , S(where)

where ::= arithmeticexpression | R(arithmeticexpression)

Alternate Specification of Form Machine Syntax​

                                 infinity
form                    ::=  {rule}
                                 1
                                    1         1          1
rule                    ::=  {INTEGER}   {terms}   {:terms} ;
                                    0         0          0
                                       infinity
terms                   ::=  term {,term}
                                       0
                                                    1
term                    ::=  identifier | {identifier}   descriptor
                                                    0
                           | comparator
                                                  1
descriptor              ::=  ({arithmeticexpression}  , datatype ,
                                                  0
                                   1                     1           1
                            {value} ,  {lengthexpression}  {:options}
                                   0                     0           0
                                                                1
comparator              ::=  (value  connective  value {:options} ) |
                                                                0
                                                             1
                            (identifier .<=. value {:options} )
                                                             0
connective              ::=  .LE. | .LT. | .GE. | .GT. | .EQ. | .NE.

lengthexpression        ::=  # | arithmeticexpression

datatype                ::=  B | O | X | E | A

value                   ::=  literal | arithmeticexpression
                                                        infinity
arithmeticexpression    ::=  primary  {operator  primary}
                                                        0
operator                ::= + | - | * | /

primary                 ::=  identifier | L(identifier) |
                            V(identifier) | INTEGER
                                                     256
literal                 ::=  literaltype  "{CHARACTER}   "
                                                     0
literaltype             ::=  B | O | X | A | E
                                                1
options                 ::=  S(where) {,F(where)}  |
                                                0
                                                1
                            F(where) {,S(where)}  | U(where)
                                                0

where                   ::=  arithmeticexpression |
                            R(arithmeticexpression)
                                                    3
identifier              ::=  ALPHABETIC  {ALPHAMERIC}
                                                    0

Forms​

A form is an ordered set of rules.

      form ::=  rule | rule form

The current rule is applied to the current position of the input stream. If the (input stream part of a) rule fails to correctly describe the contents of the current input then another rule is made current and applied to the current position of the input stream. The next rule to be made current is either explicitly specified by the current term in the current rule or it is the next sequential rule by default. Flow of control is more fully described under Term and Rule Sequencing.

If the (input stream part of a) rule succeeds in correctly describing the current input stream, then some data may be emitted at the current position in the output stream according to the rule. The input and output stream pointers are advanced over the described and emitted data, respectively, and the next rule is applied to the now current position of the input stream.

Application of the form is terminated when an explicit return (R(arithmeticexpression)) is encountered in a rule. The user and server connections are closed and the return code (arithmeticexpression) is sent to the originating user.

Rules​

A rule is a replacement, comparison, and/or an assignment operation of the form shown below.

      rule ::= label  inputstream  outputstream ;

A label is the name of a rule and it exists so that the rule may be referenced elsewhere in the form for explicit rule transfer of control. Labels are of the form below.

      label ::=  INTEGER | <null>

The optional integer labels are in the range 0 >= INTEGER >= 9999. The rules need not be labeled in ascending numerical order.

Terms​

The inputstream (describing the input stream to be matched) and the outputstream (describing data to be emitted in the output stream) consist of zero or more terms and are of the form shown below.

      inputstream   ::=  terms | <null>
outputstream ::= :terms | <null>
terms ::= term | terms , term

Terms are of one of four formats as indicated below.

      term ::=  identifier | identifier  descriptor |
descriptor | comparator

Term Format 1​

The first term format is shown below.

      identifier

The identifier is a symbolic reference to a previously identified term (term format 2) in the form. It takes on the same attributes (value, length, type) as the term by that name. Term format 1 is normally used to emit data in the output stream.

Identifiers are formed by an alpha character followed by 0 to 3 alphameric characters.

Term Format 2​

The second term format is shown below.

      identifier descriptor

Term format 2 is generally used as an input stream term but can be used as an output stream term.

A descriptor is defined as shown below.

      descriptor ::= (replicationexpression, datatype,
valueexpression, lengthexpression
control)

The identifier is the symbolic name of the term in the usual programming language sense. It takes on the type, length, and value attributes of the term and it may be referenced elsewhere in the form.

The replication expression is defined below.

      replicationexpression ::= arithmeticexpression | <null>
arithmeticexpression ::= primary | primary operator
arithmeticexpression
operator ::= + | - | * | /
primary ::= identifier | L(identifier) | V(identifier) |
INTEGER

The replication expression is a repeat function applied to the combined data type and value expression. It expresses the number of times that the value (of the data type/value expression) is to be repeated within the field length denoted by the data type/length expression.

A null replication expression has the value of one. Arithmetic expressions are evaluated from left-to-right with no precedence. (It is anticipated that this interpretation might be changed, if necessary.)

The L(identifier) is a length operator that generates a 32-bit binary integer corresponding to the length of the term named. The V(identifier) is a value operator that generates a 32-bit binary integer corresponding to the value of the term named. (See Restrictions and Interpretations of Term Functions.) The value operator is intended to convert character strings to their numerical correspondents.

The data type is defined below.

          datatype ::= B | O | X | E | A

The data type describes the kind of data that the term represents. (It is expected that additional data types, such as floating point and user-defined types, will be added as needed.)

      Data Type         Meaning              Unit Length

B Bit string 1 bit
O Bit string 3 bits
X Bit string 4 bits
E EBCDIC character 8 bits
A Network ASCII character 8 bits

The value expression is defined below.

           valueexpression ::= value | <null>
value ::= literal | arithmeticexpression
literal ::= literaltype "string"
literaltype ::= B | O | X | E | A

The value expression is the unit value of a term expressed in the format indicated by the data type. It is repeated according to the replication expression, in a field whose length is constrained by the length expression.

A null value expression in the input stream defaults to the data present in the input stream. The data must comply with the datatype attribute, however.

A null value expression generates padding according to Restrictions and Interpretations of Term Functions.

The length expression is defined below.

        lengthexpression ::= # | arithmeticexpression | <null>

The length expression states the length of the field containing the value expression as expanded by the replication expression. If the value of the length expression is less then the length implied by the expanded value expression, then the expanded value expression is truncated, see Restrictions and Interpretations of Term Functions.

The terminal symbol # means an arbitrary length, explicitly terminated by the value of the next term. The # is legal only in the input stream and not in the output stream.

If the length expression is less than or equal to zero, the term succeeds but the appropriate stream pointer is not advanced. Positive lengths cause the appropriate stream pointer to be advanced if the term otherwise succeeds.

Control is defined under Term and Rule Sequencing.

Term Format 3​

Term format 3 is shown below.

      descriptor

It is identical to term format 2 with the omission of the identifier. Term format 3 is generally used in the output stream. It is used in the input stream where input data is to be passed over but not retained for emission or later reference.

Term Format 4​

The fourth term format is shown below.

      comparator    ::= (value connective value control) |
(identifier .<=. value control)
value ::= literal | arithmeticexpression
literal ::= literaltype "string"
literaltype ::= B | O | X | E | A
string ::= from 0 to 256 characters
connective ::= .LE. | .LT. | .GE. | .GT. | .EQ. | .NE.

The fourth term format is used for assignment and comparison.

The assignment operator .<=. assigns the value to the identifier. The connectives have their usual meaning. Values to be compared must have the same type and length attributes or an error condition arises and the form fails.

The Application of a Term​

The elements of a term are applied by the following sequence of steps.

  1. The data type and value expression together specify a unit value, call it x.
  2. The replication expression specifies the number of times x is to be repeated (or copied) in concatenated fashion. The value of the concatenated xs becomes, say, y of length L1.
  3. The data type and the length expression together specify a field length of the input area (call it L2) that begins at the current stream pointer position.
  4. The value of y is truncated to y' if L1 > L2. Call the truncated length L1'.
  5. If the term is an input stream term, then the value y' of length L1' is compared to the input value beginning at the current input pointer position.
  6. If the values are identical over the length L1' then the input value of length L2 (may be greater than L1') starting at the current pointer position in the input area, becomes the value of the term.

In an output stream term, the procedure is the same except that the source of input is the value of the term(s) named in the value expression and the data is emitted in the output stream.

The above procedure is modified to include a one term look-ahead where lengths are indefinite because of the arbitrary symbol, #.

Restrictions and Interpretations of Term Functions​

  1. Terms specifying indefinite lengths, through the use of the # symbol must be separated by some type-specific data such as a literal. (A literal isn't specifically required, however. An arbitrary number of ASCII characters could be terminated by a non-ASCII character.) # is legal only in the input stream, not in the output stream.
  2. Truncation and padding is as follows:
    • Character to character (A <--> E) conversion is left justified and truncated or padded on the right with blanks.
    • Character to numeric and numeric to numeric conversions are right-justified and truncated or padded on the left with zeros.
    • Numeric to character conversion is right-justified and left-padded with blanks.
  3. The following are ignored in a form definition over the control connection.
    • TAB, carriage return, etc.
    • Blanks except within quotes.
    • /* string */ is treated as comments except within quotes.
  4. The following defaults prevail where the term part is omitted.
    • The replication expression defaults to one.
    • The data type defaults to type B.
    • The value expression of an input stream term defaults to the value found in the input stream, but the input stream must conform to data type and length expression. The value expression of an output stream term defaults to padding only.
    • The length expression defaults to the size of the quantity determined by replication expression, data type, and value expression.
    • Control defaults to the next sequential term if a term is successfully applied; else control defaults to the next sequential rule. If where evaluates to an undefined label the form fails.
  5. Arithmetic expressions are evaluated left-to-right with no precedence.
  6. The following limits prevail.
    • Binary lengths are <= 32 bits
    • Character strings are <= 256 8-bit characters
    • Identifier names are <= 4 characters
    • Maximum number of identifiers is <= 256
    • Label integers are >= 0 and <= 9999
  7. Value and length operators produce 32-bit binary integers. The value operator is currently intended for converting A or E type decimal character strings to their binary correspondents. For example, the value of E'12' would be 0......01100. The value of E'AB' would cause the form to fail.

Term and Rule Sequencing​

Sequencing may be explicitly controlled by including control in a term.

     control ::=  :options | <null>
options ::= S(where) | F(where) | U(where)
S(where) , F(where) |
F(where) , S(where)

where ::= arithmeticexpression | R(arithmeticexpression)

S, F, and U denote success, fail, and unconditional transfers, respectively. Where evaluates to a rule label, thus transfer can be effected from within a rule (at the end of a term) to the beginning of another rule. R means terminate the form and return the evaluated expression to the initiator over the control connection (if still open).

If terms are not explicitly sequenced, the following defaults prevail.

  1. When a term fails go to the next sequential rule.
  2. When a term succeeds go to the next sequential term within the rule.
  3. At the end of a rule, go to the next sequential rule.

Note in the following example, the correlation between transfer of control and movement of the input pointer.

    1   XYZ(,B,,8:S(2),F(3)) : XYZ ;
2 . . . . . . .
3 . . . . . . .

The value of XYZ will never be emitted in the output stream since control is transferred out of the rule upon either success or failure. If the term succeeds, the 8 bits of input will be assigned as the value of XYZ and rule 2 will then be applied to the same input stream data. That is, since the complete rule 1 was not successfully applied, then the input stream pointer is not advanced.