Conditions and Jumps To be useful in practice, most programs must have more
than sequential execution: we need conditions and jumps. At its simplest, this means
the modeling language equivalent of IF and GOTO??”and indeed if we are generating
assembly language, that may be all we can use in the output.
In models, IF can be represented either as an object, from which True and False
relationships exit, or else as an n-ary relationship. It can also be extended to a switch??“
case or ELSEIF structure, with one exiting relationship or role for each choice. If the
control paths rejoin after being divided by the IF, as in the top half of Fig. 11.1, a na?±??ve
recursive generator will produce poor results. The resulting code will work, but will
duplicate the rest of the program for both branches. In cases more complicated than
the ?¬?gure, even maintaining a list of visited objects will not be suf?¬?cient to avoid
problems in a recursive generator.
A recursive generator can be made to work with IF structures by changing the
modeling language. Rather than requiring both control paths to rejoin to the main
control path, we can model the branches in an IF structure as subordinate to the IF
statement. An example of this is shown in the bottom half of Fig. 11.1. The content of
the ???Foreign???? conditional statement includes its Yes and No branches, each of which
is followed by its own new recursion.
Pages:
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535