PMDF System Manager's Guide


Previous Contents Index

5.3.3 A Complex Mapping Example

Example 5-1 shows a mapping that will take a roman numeral as input and will output the equivalent decimal integer. Although this example is completely contrived, it does show almost all of the features of the mapping facility. Multiple passes over the patterns are used, as well as continuations and substitutions.

Example 5-1 Mapping File Example

ROMAN-TO-INTEGER 
 
  *|0|%*                Input$ Error$E 
  0%*|0|                $0$1|0|$R 
  *|0|                  Value$ =$ $0$E 
  *|4|MMM*              $03|3|$1$C 
  *|4|MM*               $02|3|$1$C 
  *|4|M*                $01|3|$1$C 
  *|4|*                 $00|3|$1$C 
  *|3|CM*               $09|2|$1$C 
  *|3|DCCC*             $08|2|$1$C 
  *|3|DCC*              $07|2|$1$C 
  *|3|DC*               $06|2|$1$C 
  *|3|D*                $05|2|$1$C 
  *|3|CD*               $04|2|$1$C 
  *|3|CCC*              $03|2|$1$C 
  *|3|CC*               $02|2|$1$C 
  *|3|C*                $01|2|$1$C 
  *|3|*                 $00|2|$1$C 
  *|2|XC*               $09|1|$1$C 
  *|2|LXXX*             $08|1|$1$C 
  *|2|LXX*              $07|1|$1$C 
  *|2|LX*               $06|1|$1$C 
  *|2|L*                $05|1|$1$C 
  *|2|XL*               $04|1|$1$C 
  *|2|XXX*              $03|1|$1$C 
  *|2|XX*               $02|1|$1$C 
  *|2|X*                $01|1|$1$C 
  *|2|*                 $00|1|$1$C 
  *|1|IX*               $09|0|$1$R 
  *|1|VIII*             $08|0|$1$R 
  *|1|VII*              $07|0|$1$R 
  *|1|VI*               $06|0|$1$R 
  *|1|V*                $05|0|$1$R 
  *|1|IV*               $04|0|$1$R 
  *|1|III*              $03|0|$1$R 
  *|1|II*               $02|0|$1$R 
  *|1|I*                $01|0|$1$R 
  *|1|*                 $00|0|$1$R 
  *                     |4|$0$R 

The operation of this example mapping is best understood by tracing an input string through the process. For instance, suppose the input string CDLXIV is given. On the first pass through, the very last pattern, *, is the one that matches --- it produces the output string |4|CDLXIV and, because of the $R specified in the template, resumes the mapping process from the start of the table using the output string |4|CDLXIV as the new input string.

On the second pass through, the pattern that matches first is *|4|*, which produces the new string 0|3|CDLXIV. Scanning continues from this point because of the $C sequence. The next pattern that matches is *|3|CD*, which produces the string 04|2|LXIV. Processing continues and the pattern *|2|LX* matches, producing 046|1|IV. Processing continues and the pattern *|1|IV* matches, producing 0464|0|, and the $R takes the process back to the top of the table.

On the third pass through, the pattern that matches first is 0%*|0|, which produces 464|0| and restarts at the top again.

On the fourth pass through, the pattern that matches first is *|0|, which produces the string "Value = 464" and exits because of the $E.


Previous Next Contents Index