Transformations can thus often be output as the
instructions to perform the transformation, rather than require the generator to
perform the calculation and output just the answer. In some cases, this can also
make the generated output easier to understand: rather than contain some
mystical number, with no clear relation to the model, the output shows the
calculation from the model values. Even batch ?¬?les are capable of this, as shown in
Listing 11.4.
Listing 11.4 Using batch ?¬?les for simple arithmetic.
C:\>set FahrTemp = 0
C:\>set /A KelvinTemp = (FahrTemp??“32) * 5 / 9 + 273
256
But there are surprises in store for the unwary, for instance if you try to bit-shift the
above result using the >> operator, as in Listing 11.5.
Listing 11.5 Pushing the limits of arithmetic in batch ?¬?les.
C:\>set /A KelvinTempHighByte = KelvinTemp >> 8
"Appends the result to the file called 8, so have to quote:"
C:\>set /A KelvinTempHighByte = "KelvinTemp >> 8"
1
C:\>set /A KelvinTempLowByte = "KelvinTemp % (1<<8)"
0
And if you put these in a batch ?¬?le, you will notice that the result of the SET
operation is no longer sent to standard out, and the modulus operator % needs to be
doubled to avoid being interpreted as a batch ?¬?le argument. . . Still, one of the joys of
generation is learning all the little tricks and foibles of the language you are
outputting!
278 GENERATOR DEFINITION
11.
Pages:
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514