Recursion
This section demonstrates
how recursion is used to process a much simpler structure than that given
in Figure 1. The example
shown in Figure 1 is for
the DFHTBSP program, which has the following parameters:
- Input:
- PATTERN, HIGHERNODE, and BUILDER
- Inout:
- AUDITTRAIL
- Output:
- NODE and RESPONSE.
The following list outlines the flow in DFHTBSBP. The step references refer
to steps in this list.
- Add and initialize an action to the AUDITTRAIL (this is used later in steps 5 and 11).
- Using parameter PATTERN, find the address of the associated builder.
- Call the builder stub with function number 1 (for BUILD) with
the following parameters:
- Input:
- HIGHERNODE and BUILDER
- Output:
- NODE.
The builder uses the BUILDER parameters to create its specific object. Storage is obtained and the parameters are copied into it.
- Check that the response from the build is ‘OK’.
- Copy the address of the output parameter NODE into the AUDITTRAIL action.
- Process all the subpatterns that may be attached to your pattern
- Get the next subpattern Pn.
- Call DFHTBSBP with the following parameters:
- Input:
- Pn, NODE, and BUILDER
- Inout:
- AUDITTRAIL
- Output:
- SUBNODE and SUBRESPONSE
Note: In this step, you call yourself again, passing NODE. At the next level of recursion, this appears as HIGHERNODE. - Stop when the last pattern is processed.
- Call the builder stub with function number 5 (for CONNECT)
with the following parameters:
- Input parameters:
- NODE
- Inout parameters:
- HIGHERNODE
The builder’s CONNECT entry point now places the address as given by NODE into an offset of HIGHERNODE.
- Finally, place the address of the pattern into the AUDITTRAIL action.