As we process each reachable State, it will be pushed on the stack, then
the output for it will be performed. Afterwards it will be popped off the stack, and we
will move on to repeat the loop for the next reachable State.
Similarly, if we are generating a number of C ?¬?les and a make?¬?le for them, we
might start with the make?¬?le on the top of the output stack.We could then navigate to
each model element from which aC?¬?le will be generated. For each element, wewould
output a line to the make?¬?le for that element??™s C ?¬?le, then push a new output stream
directed to that C ?¬?le.With that on the top of the stack, we would perform the output
for the contents of the C ?¬?le, then pop it off the stack before moving on to the next
model element.
Using a DSL for the commands can give a major advantage over a standard
programming language. This is especially so in the area of navigation, which takes up
the bulk of the generator. Listing 11.1 is an example of a standard programming
language, C#, used in a T4 template from the Microsoft DSLTools forum (apparently
an earlier version, since it uses <% rather than <#).
Listing 11.1 Generator written in a generic programming language.
ConceptBs
<%
foreach ( ConceptB b in this.ConceptA.Bs )
{
%>
Name: <%=b.Name%>
Outgoing links:
<%
MetaRoleInfo roleInfo = b.
Pages:
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506