home *** CD-ROM | disk | FTP | other *** search
/ Oakland CPM Archive / oakcpm.iso / sigm / vol203 / cnvadv.hlp < prev    next >
Encoding:
Text File  |  1984-12-19  |  39.0 KB  |  898 lines

  1. Introduction.
  2. Patterns.
  3. Subroutine Groups.
  4. Conditional Skeletons.
  5. Iterative Skeletons.
  6. The "Same" Skeleton <=>.
  7. Data Transfer and I/O.
  8. Pattern-directed read.
  9. Memory buffer operations.
  10. Disk system, display and return to CP/M functions.
  11. Null pseudofile.
  12. Arithmetic Skeletons.
  13. Character "Arithmetic".
  14. Overlays.
  15. "Exclude" feature.
  16. Miscellaneous features.
  17. :Introduction.
  18.  
  19. This Help file describes advanced CNVRT features as well as additions and 
  20. changes made to CNVRT after CNVPRG.HLP was prepared.  Among the most
  21. noteworthy changes the following may be mentioned:
  22.  
  23.     - the patterns (OR,...) and (AND,...) are now fully functional 
  24.       [refer to the discussion in Section G (Boolean Patterns) of file 
  25.       CNVRT.HLP].
  26.  
  27.     - The conditional and iterative skeletons if, nf, while and until
  28.       may contain more than one triple ([s,p,st] in the case of if and
  29.       nf; [p,sl,sr] in the case of while and until).
  30.  
  31.     - Evaluation of general arithmetic expressions whose operands are
  32.       constants (including floating point) is now possible.
  33.  
  34.     - A function reference or a conditional or iterative skeleton 
  35.       may appear as a pattern; it gives a match if the skeleton's
  36.       value matches the text under examination.
  37.  
  38. :Patterns
  39.  
  40.     The Boolean patterns (OR,...) and (AND,...) now have the full
  41. functionality expected of them, so that programs of the kind illustrated by
  42. the following example are now possible:
  43.  
  44.     [Exclude ALL]
  45.     ((    ((OR,[<:e:>],<(><:e:><)>,[<0>],<(><0><)>)) e
  46.     )()(0)(    (<>,);
  47.         (<:e:><0>,(%t, yes)(%R)):
  48.         (,(%t, no)(%R)):
  49.     ))
  50.     [end]
  51.  
  52.     This programs answers yes if it finds the same string inside and to 
  53. the right of a nest of possibly alternated parentheses and brackets and types
  54. no otherwise.  For example, ([[([(ab)])]])ab produces "yes", (b)c gives "no".
  55.  
  56.     Making this program work requires that the defined pattern e "know" 
  57. what follows it at the place where it is referenced; this issue has been 
  58. resolved, so that if pattern <0> in the second rule fails, the next 
  59. alternative in the OR is tried out.
  60. -
  61.     The effect of having defined patterns check the patterns that follow
  62. references to them on compiled programs is a slightly inflated object file
  63. (about 10%), so that two compilers are now provided: CNVRT and CNVSM.
  64. CNVRT provides the full generality of the language, whereas CNVSM produces
  65. less code at the price of less generality in the use of defined patterns.
  66. CNVSM should be used only when the program doesn't require that defined
  67. patterns check patterns to the right of references to them; our experience
  68. is that this covers a fairly large class of programs, so that maintaining
  69. the two compilers is justified.
  70.  
  71.     Another issue that has now been resolved is that of unbinding 
  72. variables when backtracking is required.  Consider the pattern in the rule
  73.         (<0>(and,<[3]>,<1>)<--><1><2>, ... )
  74. This should match a string that contains two instances of the same triplet
  75. of characters anywhere, such as abcdefbcdgh.  In the previous version 
  76. however, this didn't work because variable 1 became bound after the first 
  77. trial string (the null string) was assigned to variable 0.  If the match 
  78. didn't succeed in the very first trial, <1> would stay bound during each
  79. subsequent trial for variable 0.  With the above example, <1> would bind
  80. the string abc initially and would then fail to match for each new trial
  81. string assigned to <0>: a, ab, abc, abcd, abcde, etc.
  82.  
  83. -
  84.     This difficulty is now resolved by having each variable unbind other 
  85. variables whenever a new trial string is required for it; unbinding occurs
  86. only for those variables which became bound AFTER the previous trial string 
  87. was assigned to the variable doing the unbinding.  For example, in the 
  88. pattern
  89.         <2>:<0>(and,<[3]>,<1>)<--><1><3>
  90.  
  91. if variables 2, 0 and 1 have been bound but a mismatch occurs when the 
  92. second instance of <1> is sought, in assigning a new trial value for <0>
  93. variable 1 will become unbound, but variable 2 will not.
  94.  
  95.     The patterns (AND,...) and (and,...) differ in that "AND" unbinds,
  96. upon failure, any variables it may have bound, whereas "and" doesn't.  "and"
  97. suffices in any application in which it is the very first pattern or when 
  98. there is a variable anywhere to its left (even if hidden away within a 
  99. defined pattern).  "AND" is called for when it is preceded by an (OR,...) 
  100. or a defined pattern containing an (OR,...), but is not preceded by any 
  101. variables.  (AND,...) should only be used where strictly necessary, as it
  102. produces more code and consumes more time during execution.
  103.  
  104.  
  105.  
  106. -
  107.     The length pattern <[n]> admits in place of n any skeleton.  The
  108. pattern will fail to match if the skeleton doesn't evaluate to a string of 
  109. ASCII decimal digits, or if the skeleton does evaluate to such a string but
  110. there aren't that many characters in the text under scrutiny.  Some 
  111. posibilities now allowed by this pattern are:
  112.  
  113.     <[128]>        A constant skeleton: its original definition.
  114.     <[<0>]>        A variable, which should be already bound to a 
  115.             string of ASCII digits.
  116.     <[(&!,<0>)]>    The length of the value of a variable.
  117.     <[(#f,2*<0>+1)]>    Twice the value of a variable plus one 
  118.                 (the value of the variable here could be
  119.                 a string of ASCII digits or an arithmetic
  120.                 expression whose operands are integer
  121.                 constants).
  122.  
  123.     Assuming <0> is bound to the two-digit string "32", the second 
  124. pattern will match a 32-byte string, the third pattern will match a 2-byte
  125. string and the last pattern will match a string of 65 characters.  If the
  126. value of <0> is abc, of the three examples involving <0> the first and the
  127. third will fail, while the second one will match a 3-byte string.
  128.  
  129. -
  130.     Any functional, conditional or iterative skeleton may appear wherever
  131. a pattern is allowed.  A skeleton such as (a,<0>:k), (%R), (if,<0>,(^Z),<1>)
  132. or (until,(%R),(^Z),<=>,(%R),), when appearing on the pattern side of a rule
  133. or within a defined pattern, will have the same effect as if a constant 
  134. pattern equal to the value of the skeleton were present in its place.  
  135. Variables used within such skeletons must have been previously bound.
  136.  
  137. :Subroutine Groups.
  138.  
  139.     Since CNVRT inherits REC's features as regards the grouping of 
  140. subroutines, groups of defined patterns, defined skeletons and whole programs
  141. may be built.
  142.  
  143.     The following example shows a defined pattern group:
  144.  
  145.     { ((IVL,0,9)) d  (<:d:>(ITR,<:d:>)) i  ((or,+,-,)<:i:>) I
  146.       ((or,<:i:>.<:i:>,.<:i:>,<:i:>.)) r
  147.       ((or,<:i:>E<:I:>,<:r:>(or,E<:I:>,))) R
  148.       (<:@:>) } K
  149.  
  150.     Notice that the main routine of the group MUST consist only of <:@:>.
  151. In this example, d matches a decimal digit, i a decimal integer, I an 
  152. optionally signed integer, r a decimal number with explicit point and R a 
  153. general real constant in the fashion of FORTRAN.  External references to 
  154. these patterns are accomplished by writing <:Kd:>, <:Ki:>, <:KI:>, <:Kr:>,
  155. and <:KR:>, respectively.  A reference to the main routine by itself (e.g.,
  156. <:K:>) is meaningless and therefore not to be used, and references from
  157. within the group to definitions in the same group need not have the group
  158. name, as illustrated in the example.
  159. -
  160.     The next example shows a defined skeleton group:
  161.  
  162.     { ((%V,MEM:ll,<=>)) G
  163.       ((%V,MEM:sy,<=>)) Y
  164.       ((@)) } F
  165.  
  166.     The main routine of the group MUST consist only of a reference to
  167. the "skeleton" @.  Outside references to G and Y may take any of the
  168. following forms:  (FG,s), (FG), (FY,s) or (FY), where s is a skeleton whose
  169. value will be passed as an argument to the corresponding skeleton in group
  170. F.  (FG) and (FY) deliver a null argument to G and Y, respectively.
  171.  
  172.     Finally, program groups may also be formed:
  173.  
  174.     { (()()()()) a       (()()()()) b      (()()()()) } A
  175.  
  176. In this case, subroutines a and b are not directly available from outside
  177. the braces, but can only be called by each other and by A; any CNVRT
  178. subroutine may be included in a braced group in the fashion shown, and
  179. each braced group MUST be a subroutine, the final main program of a CNVRT
  180. program file may not be a part of a braced group.
  181.  
  182. :Conditional skeletons.
  183.  
  184.     Four conditional skeletons are provided: IF, NF, if and nf.  IF and 
  185. NF require a variable list to be given, if and nf do not.  Their general
  186. forms are the following:
  187.  
  188.     (IF,(v),s1,p1,s1t,s2,p2,s2t,...,sk,pk,skt,sf)
  189.     (if,s1,p1,s1t,s2,p2,s2t,...,sk,pk,skt,sf)
  190.     (NF,(v),s1,p1,s1t,s2,p2,s2t,...,sk,pk,skt,sf)
  191.     (nf,s1,p1,s1t,s2,p2,s2t,...,sk,pk,skt,sf)
  192.  
  193.     In skeletons IF and NF, v is list of variables (zero or more 
  194. integers between 0 and 30 with one space between each pair of variables).  
  195. Variables appearing in v supersede variables of the same names defined 
  196. outside the IF or NF during the execution of the conditional skeleton;
  197. otherwise, IF and NF operate the same as if and nf, respectively.  
  198. Each s represents a skeleton and each p represents a pattern.  One or more 
  199. triplets [si,pi,sit] may appear; the last skeleton sf may be omitted 
  200. (together with the comma which precedes it).
  201.  
  202.     The next panels describe the operation of if and nf; we repeat 
  203. the form of the corresponding skeleton for ease of reference.
  204. -
  205.     (if,s1,p1,s1t,s2,p2,s2t,...,sk,pk,skt,sf)
  206.  
  207.     Skeleton s1 is evaluated and matched to pattern p1.  If the match 
  208. succeeds, s1t is evaluated and its value becomes the value of the entire
  209. skeleton; if the match fails s2 is evaluated and matched to p2.  This
  210. continues until a match obtains or there are no more comparisons to be made,
  211. in which case the last skeleton sf is left as the result.  If no sf appears 
  212. (which means that the comma following skt is also absent) and all matches 
  213. fail, the value of the skeleton will be the last skeleton failing to match 
  214. the pattern which followed it.  An example follows:
  215.  
  216.     (if,(%R),(^Z),<=>(%t,End of file encountered),(%T,<=>))
  217.  
  218. This will read a line from the default file; if it finds and end-of-file 
  219. marker (control-Z), it leaves it but types the message "End of file 
  220. encountered" (the value of %t is the null string); otherwise, it leaves
  221. the line read by (%R) after typing it.
  222.  
  223.     The use of more than one s,p,s triplet allows constructs of the
  224. "elseif" type within a single (if,...).
  225.  
  226.  
  227. -
  228.     (nf,s1,p1,s1t,s2,p2,s2t,...,sk,pk,skt,sf)
  229.  
  230.     NF and nf are the negative forms of IF and if, repectively; that is,
  231. if s1 does NOT match p1, s1t is substituted, else if s2 does not match p2,
  232. s2t is substituted, etc.  The last skeleton, sf, is substituted only if all
  233. si match the corresponding pi.
  234.  
  235.     Alternatively, "nf" may be read as "unless":  Unless s1 matches p1,
  236. s1t is evaluated and delivered as the result, else unless s2 matches p2,
  237. s2t is given as the result, etc.
  238.  
  239.     Sf (and the comma preceding it) may be absent, in which case the
  240. result will be sk when all si match the corresponding pi.  A useful example 
  241. follows:
  242.  
  243.         (nf,(%Or),Not Found,(a,(%R)))
  244.  
  245. This skeleton will call function a, with argument equal to the first line of 
  246. the default file only if it is possible to open the default file for reading.
  247. Variants of this example include giving arguments to the %Or and %R 
  248. functions.  Notice that if the value of (%Or) is "Not Found", this string
  249. will be left as the value of the nf skeleton since no "sf" is given.
  250.  
  251. :Iterative skeletons.
  252.  
  253.     Four iterative skeletons are provided: WHILE, UNTIL, while and until.
  254. WHILE and UNTIL require a variable list to be given, while and until do not.
  255. Their general forms are the following:
  256.  
  257.     (WHILE,(v),si,p1,s1,s1r,p2,s2,s2r,...,pn,sn,snr,sf)
  258.     (while,si,p1,s1,s1r,p2,s2,s2r,...,pn,sn,snr,sf)
  259.     (UNTIL,(v),si,p1,s1,s1r,p2,s2,s2r,...,pn,sn,snr,sf)
  260.     (until,si,p1,s1,s1r,p2,s2,s2r,...,pn,sn,snr,sf)
  261.  
  262.     In skeletons WHILE and UNTIL, v is list of variables (zero or more 
  263. integers between 0 and 30 with one space between each pair of variables).  
  264. Variables appearing in v supersede variables of the same names defined 
  265. outside the WHILE or UNTIL during the execution of the conditional skeleton;
  266. otherwise, WHILE and UNTIL perform as while and until, respectively.  
  267. Each s represents a skeleton and each p represents a pattern.  One or more 
  268. triplets [pk,sk,skr] may appear; the last skeleton sf may be omitted 
  269. (together with the comma which precedes it).
  270.  
  271.     The next panels describe the operation of while and until; we repeat 
  272. the form of the skeleton for ease of reference.
  273. -
  274.     (while,si,p1,s1,s1r,p2,s2,s2r,...,pn,sn,snr,sf)
  275.  
  276. 1.    The initial skeleton si is placed on the workspace.
  277.  
  278. 2.    If the pattern p1 matches the text, the skeleton s1 replaces it and 
  279. a new text to match with p1 is given by the repetition skeleton s1r.  This 
  280. step is repeated until p1 no longer matches the text presented to it.  
  281.  
  282. 3.    The last text s1r from step 2 (or si if p1 did not match on the very
  283. first try) is used as initial text to match with pattern p2, and a similar 
  284. iteration to that of step 2 takes place on the triple p2,s2,s2r.
  285.  
  286. 4.    Similar iterations are performed for each triple pk,sk,pkr; when the 
  287. last pattern pn fails to match its text, its last residue pnr is left on the 
  288. workspace, unless the optional final skeleton sf is present, in which case 
  289. it replaces the text which last failed to match pn.  The text produced by 
  290. "while" will thus be a concatenation of 0 or more instances of s1, s2, ...
  291. sn and either of the last of snr or sf; the number of instances of sa, sb, 
  292. ..., sn will depend on how many iterations of each triple took place.
  293.  
  294.     "Until" performs in a similar manner, except that iteration occurs
  295. as long as the pattern does NOT match.  Examples follow in the next panel.
  296. -
  297.     The following WHILE reads the default file, leaving on the workspace 
  298. its contents up to but not including the end-of-file marker.
  299.  
  300.     (WHILE,(0),(%R),(and,<[128]>,(NOT,<-->(^Z))),<=>,(%R),<<
  301.         >><=>,<0>(^Z),<0>,)
  302.  
  303.     The symbol <=> is the "same" skeleton, whose value is the text used
  304. in the last matching attempt (regardless of the outcome); this skeleton is
  305. described in the next section of this file.
  306.  
  307.     The first triple in the above example leaves on the workspace, one 
  308. by one,  all full disk sectors of the file which do not contain ^Z.  The 
  309. iteration ends when either no more sectors remain in the file or a sector 
  310. is read which contains a control-Z.  The last text (which is either a single 
  311. ^Z or a sector containing it) is given to the next triple, in which the text 
  312. match the pattern <0>(^Z), so that <0> will be a null string or the rest of 
  313. the file up to but not including the ^Z.  A null string is given as the 
  314. repeat text, which will not match <0>(^Z), and the last action of the WHILE
  315. will be to "append" this null text to the right of the contents of the
  316. workspace.
  317.  
  318.     An example of UNTIL follows.
  319. -
  320.     (UNTIL,(0),0,(and,<0>,13),(,(%Ow,MEM:<0>)),(#p,<0>),)
  321.  
  322.     This skeleton creates 13 memory buffers, named MEM:0 through MEM:12.
  323. Notice that <0> is the first pattern in the "and", so that the variable will
  324. be bound to the text even if the whole "and" fails (which will happen 13 
  325. times).  The skeleton (#p,...) increments by one a number expressed as a
  326. decimal number in ASCII; for instance, (#p,12) yields the string "13".
  327.  
  328.     The skeleton which would close these buffers and release the memory
  329. associated with them would be the following:
  330.  
  331.     (UNTIL,(0),12,(and,<0>,-1),(%C,MEM:<0>),(#m,<0>),)
  332.  
  333. (#m,...) decrements its argument; notice that closing is performed in the
  334. order opposite to the one followed when opening: since memory buffers
  335. are assigned space on the pushdown list, space must be released in order
  336. opposite to that of arrival.
  337.  
  338. :The "Same" Skeleton <=>.
  339.  
  340.     The skeleton <=> may be used wherever a pattern match has taken place
  341. and the workspace hasn't been disturbed (which includes the start of any of
  342. the skeletons in ifs, nfs, whiles, untils, etc.); the value of <=> is the 
  343. whole text in the workspace.  For instance, the rule (,<=><=>) leaves two 
  344. copies of the text to which it is applied.  Any concatenation of one or more 
  345. <=>'s may also be included as the argument of a function or nest of 
  346. functions, as long as it appears where a single <=> would be allowed.  All
  347. of the following examples of CNVRT rules (where ... denotes the pattern) are
  348. allowed:
  349.     (...,<=>);        (...,<=>(a,(b,<=>))):
  350.     (...,(a,<=>)):        (...,<=><=>(%W,FILE.OUT,<=>));
  351.     (...,(%W,(x,<=>),(^Z)));
  352.     (...,(if,<=>,(^Z),,<=><=>));
  353.     (...,(WHILE,(0),(%R),(and,<[128]>,(NOT,<-->(^Z))),<=>,(%R),<<
  354.                 >><=>,<0>(^Z),<0>,));
  355.  
  356. On the other hand, (...,(%R)<=>) or (...,(a,<=>)<=>) are not allowed because
  357. the original text is no longer available at the point where the last <=> is
  358. found in each example.
  359.  
  360. :Data Transfer and I/O.
  361.  
  362.     In this section we describe additions, extensions and changes to
  363. the data transfer and I/O part of the CNVRT library of functions.  A
  364. listing of functions and options that have not been previously discussed 
  365. follows:
  366.         (%R,s,p,st,sf)        Read with then/else options
  367.         (%Or,MEM:n,s)        Open memory buffer for reading
  368.         (%Ow,MEM:n,s)        Open memory buffer for writing
  369.         (%R,MEM:n,...)        Read from a memory buffer
  370.         (%W,MEM:n,s)        Write into a memory buffer
  371.         (%Lr)            Get ID of logged disk
  372.         (%Lw,x)            Log in disk x
  373.         (%t,s)            Type and erase argument
  374.         (%P,s)            Print argument ant leave it
  375.         (%p,s)            Print and erase argument
  376.         (%Q)            Type logon message (formerly (%L))
  377.         (%M)            Return to CP/M
  378.         NUL:            Null pseudofile
  379.  
  380.     (%|) no longer exists since (^MJ) performs the same function.  The
  381. above skeletons are described in detail in the following sections.
  382.  
  383. :Pattern-directed read.
  384.  
  385.             (%R,s,p,st,sf)
  386.  
  387. A read is performed on the file or pseudofile described by skeleton s.
  388. If the text read matches p, the value of the whole skeleton will be that
  389. of st, otherwise sf will be evaluated and delivered to the workspace.
  390. Possible alternatives are as follows:
  391.  
  392.     (%R,s,,st,sf)    The default pattern provided in the library is used.
  393.     (%R,s,p,,sf)    The null string is left if p matches the text read.
  394.     (%R,s,p,st)    st is left if p matches, else the text read is left.
  395.     (%R,s,p,st,)    The null string is left if p does not match the text.
  396.  
  397. If the skeleton s starts with the four-character constant CTR:, no code is
  398. generated for pattern matching and all portions of the %R skeleton following
  399. s will be ignored if present.  A pattern-directed read from a CTR: pseudofile
  400. may be accomplished by hiding the CTR: away elsewhere in a defined skeleton,
  401. e.g.,  (() (  (CTR:x) X ) () ( ... 
  402.                 ( ... , (%R,(X),...)...);
  403.     ))
  404. where ellipses indicate omitted portions of the program.
  405.  
  406. :Memory buffer operations.
  407.  
  408.     Open operations on MEM:-type pseudo files may have an additional
  409. skeleton whose value should be a string of decimal digits indicating the
  410. size in bytes of the buffer desired.  This number is effective only at the
  411. time the buffer is actually created; it is ignored if the buffer already
  412. exists.  If omitted at the time of the initial open, 1024 is assumed.
  413.  
  414.     Associated with a memory buffer pseudofile there are two pointers:
  415. a read pointer and a write pointer.  When the buffer is first created, both
  416. pointers reflect an empty buffer.  Write operations start writing into a
  417. buffer at the location indicated by the write pointer, update the pointer to
  418. the next available location when done and remove the written argument from 
  419. the workspace, however, if the argument doesn't fit in what's left of the 
  420. buffer, nothing is written, the argument remains in the workspace and the
  421. write pointer remains unaltered.  Read operations will read all characters
  422. between the read pointer and the write pointer and the default pattern or
  423. the pattern given explicitly in the read will be tested on this text.  If
  424. there is a match, the portion of the text which matched will remain in the
  425. workspace and the read pointer will be updated to reflect that text has been
  426. read out.  If no match is possible, the text between the pointers is returned
  427. with a ^Z at the end, and the read pointer moves up to the write pointer.
  428. -
  429. When a read is attempted on a MEM: pseudo file in which both read and write
  430. pointers have the same value (either because the buffer is empty or it has
  431. been read out entirely), a single ^Z is returned.  The final text returned
  432. by %R from a memory buffer will of course depend on the presence or absence
  433. of the optional skeletons possible in the (%R,...) skeleton.
  434.  
  435.     Open operations may be performed on an open buffer, with the
  436. following effects:
  437.  
  438.     (%Or,MEM:...)    moves the read pointer to the beginning of the
  439.             buffer, thus making available all of its contents.
  440.  
  441.     (%Ow,MEM:...)    moves both pointers to the beginning of the buffer,
  442.             effectively leaving it empty.
  443.  
  444.     Both open operations on a MEM: pseudofile return the address of the
  445. buffer as a four-digit ASCII hexadecimal number; this is provided for use
  446. with the %B direct BIOS call available with CP/M-86.  For most purposes, %O
  447. skeletons involving MEM: buffers should be nested inside the null skeleton
  448. (,...) which erases its argument from the workspace.
  449.  
  450. :Disk system, display and return to CP/M functions.
  451.  
  452.     (%Lr)    returns a single letter (A, B, ...) corresponding to the
  453.         identifier of the currently logged-in disk.
  454.  
  455.     (%Lw,x)    logs in the disk sppecified by the first letter of skeleton
  456.         x; if x is omitte or is null, A is assumed.
  457.  
  458.     (%t,s)    types and erases the value of skeleton s; it essentially
  459.         replaces (,(%T,s)); %T retains its function (type and leave).
  460.  
  461.     (%P,s)    prints on the list device and leaves on the workspace the 
  462.         value of skeleton s.
  463.  
  464.     (%p,s)    prints on the list device and erases from the workspace the
  465.         value of its argument, it is equivalent to (,(%P,s)).
  466.  
  467.     (%Q)    displays the logon message; this is a function previously
  468.         performed by (%L) [refer to the section on "Program file"
  469.         in CNVRT.HLP].
  470.  
  471.     (%M)    returns to CP/M after closing all files (panic button).
  472.  
  473. :Null pseudofile.
  474.  
  475.     The pseudofile NUL: may appear in skeletons %Or, %Ow, %R, %W and
  476. %C.  When found by %O and %C, no action is taken; reading from the null
  477. file always returns a ^Z and writing to the null file has the sole effect
  478. of erasing the argument.
  479.  
  480.     This feature is useful in compiler and assembler construction, where 
  481. for test purposes one may not want, say, an object file to be produced.  One
  482. could then bind a variable near the beginning of the compiler's execution to
  483. either of NUL: or an actual file name, and use this variable in all 
  484. references to the output file.
  485.  
  486.  
  487. :Arithmetic Skeletons.
  488.  
  489.     Arithmetic skeletons have the form
  490.  
  491.             (#x,s)
  492.  
  493. where x may be a string of one or more of the arithmetic functions and s
  494. is the argument to which the functions given by x are applied.  In the
  495. listing of arithmetic functions which follows, the term "constant" means
  496. a string of ASCII characters representing an integer when the program is 
  497. run with rec80 or rec86, or an integer, long integer, single precision real 
  498. or double precision real when the program is run with rec80f or rec86f.
  499. CNVRT inherits REC8xF's default of promoting smaller-sized arguments to the 
  500. size and type of the larger argument in operations involving arguments of 
  501. different sizes.
  502.  
  503.     f    evaluates a formula.  Its argument must be an arithmetic
  504.         expression in which the operands are constants.  Parentheses
  505.         are allowed (and must be balanced if present); the operators
  506.         recognized are ** or ^ for raising to a power, * for product
  507.         / for division, % for remainder, + for addition or unary 
  508.         plus and - for subtraction or unary minus.
  509. -
  510.         The usual rules for operator precedence and association are 
  511.         followed: ** or ^ precede *, / and %, all of which precede + 
  512.         and -.  Unary +'s are removed and unary -'s are replaced by 
  513.         0-.   *, /, %, + and - associate from left to right and ** 
  514.         or ^ associate from right to left.  Thus, (#f,2^3^2) yields 
  515.         512, (#f,(QUO\(2^3)^2\)) yields 64, (#f,2/4*6) gives 0 and
  516.         (#f,6*2/4) gives 3.  Exponents MUST be of integer type; a
  517.         floating point exponent causes an "Expt err" diagnostic and
  518.         a return to CP/M.
  519.         
  520.     +    Takes an argument of the form a+b, where a and b are 
  521.         constants and returns their sum.  The argument is unchanged
  522.         if it doesn't have the required form.
  523.  
  524.     -    Takes an argument of the form a-b, where a and b are 
  525.         constants and returns the indicated difference.  No change
  526.         is made in the argument if its form isn't a-b.
  527.  
  528.     *    Returns the product if the argument has the form a*b, with
  529.         a and b constant; otherwise the original argument remains.
  530.  
  531.  
  532. -
  533.     /    Returns the quotient given an argument a/b in which a and
  534.         b are constants; no change is effected if the argument
  535.         does not have the specified form.
  536.  
  537.     ^    Given an argument of the form a^b, where a is any constant 
  538.         and b is an integer, returns a raised to the power b.  The
  539.         argument is returned intact if it does not have the indicated
  540.         form
  541.  
  542.     %    Returns the remainder of the division a/b if the argument
  543.         has the form a%b; otherwise the argument is left unchanged.
  544.         If either operand is a floating point number, the result
  545.         returned will be  a-(b*int(a/b)), where int(x) is the 
  546.         integer part of x. [e.g., int(3.5)=3; int(-4.8)=-4.]
  547.  
  548.     |    If its argument has the form a|b, where a and b are integer
  549.         constants, it returns the greatest common divisor of the
  550.         pair.  No change occurs if the argument lacks the prescribed
  551.         form and no check is made to ensure that a and b are 
  552.         integers; results are unpredictable in the latter case.
  553.         | may not be used as an operand in arithmetic expressions
  554.         to be evaluated by f.
  555. -
  556.     p    Accepts a single constant as argument and returns that
  557.         constant plus one, in a string of the same numeric type
  558.         as the original argument.  It will not alter its argument
  559.         if it isn't a constant.
  560.  
  561.     m    If its argument is a constant, it returns that constant minus
  562.         one, in a string of the same type; otherwise it leaves its
  563.         argument unchanged.
  564.  
  565.     =
  566.     >    These three skeletons take arguments in either of two
  567.     <    forms: a single number or two numbers separated by a comma.
  568.         In the case of a single number, say a, they return the 
  569.         letter t if a=0, a>0 or a<0, respectively, and the letter f
  570.         otherwise.  In the two-argument case of the form "a,b", t
  571.         is returned if a=b, a>b or a<b, respectively, and f if the
  572.         relation doesn't hold.  In this case, if a and b are two-byte
  573.         integers they are compared as unsigned operands, since 
  574.         two-byte integers are more often used in address 
  575.         calculations.
  576.  
  577.  
  578. -
  579.     l    Requires a single constant as argument; it converts it to
  580.         a string of the following larger numeric type.  For instance,
  581.         (#l,-1) yields 065535, (#l,010000000) yields 1.E7 and
  582.         (#l,3.1415) gives 3.1415D0.  Double precision constants and
  583.         non-numeric arguments remain unchanged, a null string as
  584.         argument returns the digit 0.
  585.  
  586.     s    Converts a single constant argument to next smaller numeric
  587.         type before rendering it back to ASCII.  Thus
  588.         (#s,3.141592653589D0) returns 3.14159265, (#s,-45.98) returns
  589.         -045, (#s,0100000) leaves 34464 (because of truncation modulo
  590.         2**16) and (#s,2000) leaves 208 (because of truncation modulo
  591.         256).  Non-numeric arguments remain unchanged; a null string
  592.         returns the digit 0.
  593.  
  594.     D    Leaves the binary form of a numeric constant in its place;
  595.         this will take the form of 2, 4, 5 or 8 bytes arranged in
  596.         Intel form (least significant byte first); the lengths
  597.         correspond to short integers, long integers, single precision
  598.         reals and double precision reals, respectively.  D is more
  599.         often used together with h to produce the ASCII hexadecimal
  600.         representation of a number.  
  601. -
  602.         No change takes place if the argument is non-numeric. 
  603.         Examples:    (#Dh,1.5)     produces     3FC0000000
  604.                 (#Dh,-1)     produces     FFFF
  605.                 (#Dh,01000000)     produces     000F4240
  606.  
  607.     H    Leaves the binary form of a string of ASCII hexadecimal 
  608.         digits (0-9, A-F).  Given a string of n bytes, it produces
  609.         a string of flr((n+1)/2) bytes, where flr(x) is the greatest
  610.         integer not exceeding x.  H is often used together with d
  611.         to convert from ASCII hexadecimal to ASCII decimal.  No
  612.         change is effected if the argument contains characters other
  613.         than hex digits.  Examples:
  614.         (#H,414243)     gives    CBA     (when interpreted as ASCII)
  615.         (#Hd,3FC0000000) gives    1.5
  616.         (#Hd,F)         gives  15
  617.  
  618.     d    Assumes its argument is the binary representation of a number
  619.         and converts it to an ASCII decimal string.  If the argument 
  620.         length is not 0, 1, 2, 4, 5 or 8 no change takes place.  
  621.         Examples: (#d,(^MJ)) yields 2573 (10*256+13, due to Intel 
  622.         ordering of bytes in binary operands being assumed); 
  623.         (#Hd,FFFF) yields 65535.
  624. -
  625.     h    Assumes its argument to be binary and converts it to a string
  626.         of ASCII hex.  An n-byte argument produces a 2n-byte result.
  627.         Examples: (#Dh,1.) produces 3F80000000;    (#h,jkl) produces 
  628.         6C6B6A (because Intel ordering of binary operands is assumed)
  629.  
  630.     As mentioned near the beginning of this section, in a skeleton of
  631. the form (#x,s), x may be a string.  When x consists of more than one
  632. character, each of the represented functions is applied to the argument
  633. from left to right, thus in (#Hd,FFFF), H is applied first to FFFF and
  634. d is then applied to the result left by H (the two byte binary representation
  635. of 65535).
  636.  
  637.     The entire section of the CNVRT library dealing with arithmetic may 
  638. be excluded from the compiled program file by the presence of INT in the
  639. [Exclude ...] comment at the beginning of the source program file.  Selected
  640. portions of the arithmetic section may be excluded by other three-letter
  641. keywords listed in this Help file under "Exclude feature".
  642.  
  643. :Character "Arithmetic".
  644.  
  645.     Character arithmetic skeletons have the form
  646.  
  647.             (&x,s)
  648.  
  649. where x may be a string of one or more of the character arithmetic  functions
  650. and s is the argument to which the functions given by x are applied.  When
  651. x consists of two or more characters, the function represented by each 
  652. character is applied in turn from left to right, the first one to the 
  653. original argument and the rest to the result left by the preceding function
  654. For instance, (&D!,1.5) applies D to the string 1.5 and ! to the resulting
  655. string.
  656.  
  657.     Functions available for character arithmetic are the following:
  658.  
  659.     D    Converts a string of one or more decimal integer ASCII
  660.         numbers optionally preceded by minus signs and separated by
  661.         commas or other nondecimal characters into binary, a pair
  662.         of bytes for each integer. Examples: (&D,2573<,>-1) yields  
  663.         4 consecutive bytes whose hex values are 0D, 0A, FF and FF;
  664.         (&D,ab) yields 6 zero bytes: a and b delimit 3 null strings.
  665. -
  666.     H    Converts a string of one or more hexadecimal ASCII numbers
  667.         into binary (modulo 2**16), a pair of bytes for each number.
  668.         For instance, (&H,F) yields two bytes whose values are, in
  669.         hex, 0F and 00; (&H,ABCDEf0123) produces 4 bytes whose
  670.         values expressed in hex are DE, BC, 23 and 01, in that order.
  671.         The inversion of high and low order bytes is due to the
  672.         Intel convention for binary data storage.  Notice also that
  673.         lowercase f is not considered a hex digit.
  674.  
  675.     d    Converts a string by pairs of bytes into ASCII decimal 
  676.         strings separated by commas; if the argument has an odd
  677.         number of bytes the rightmost byte is converted assuming
  678.         a zero high order byte.  Examples:
  679.             (#d,(^MJZ)) produces the string 2573,26
  680.             (#Hd,FFFE)  produces the string -2
  681.  
  682.     h    Converts a string by pairs of bytes into strings of 4 ASCII 
  683.         hexadecimal digits separated by commas; the rightmost byte
  684.         of a string of odd length gets converted to two hex digits.
  685.         Examples:
  686.             (#h,(^ABMJZ)) produces the string 0201,0A0D,1A
  687.             (#Dh,32767) produces the string 7FFF
  688. -
  689.     u    Shifts all lowercase letters (a-z) in its argument to
  690.         uppercase, e.g., (&u,Hello) yields HELLO.
  691.  
  692.     l    Shifts all uppercase letters (A-Z) in its argument to
  693.         lowercase, e.g., (&u,What IS it?) results in what is it?
  694.  
  695.     a    Turns off the sign bit of each byte in its argument.
  696.         For instance (&Dah,-1) results in the string 7F7F.
  697.  
  698.     s    Turns on the sign bit of each byte in its argument.
  699.         For instance (&sh,(^MJZ)) gives 8A8D,9A
  700.  
  701.     p    Substitutes a period for each byte in its argument
  702.         whose value is not a printable ASCII character.
  703.         Example: (&p,abc(^MJ)de) results in abc..de 
  704.  
  705.     n    Converts each byte in its argument into two ASCII hexadecimal
  706.         digits.  For example (&n,ABCDEF) produces 414243444546.
  707.  
  708.     b    Inverts the effect of n: converts pairs of ASCII hex digits
  709.         into bytes of the corresponding binary value.  Results are
  710.         unpredictable for odd-numbered arguments or non-hex digits.
  711. -
  712.     i    Converts a string of bytes into 3-digit ASCII octal numbers
  713.         (one for each byte) separated by commas; a null argument
  714.         produces 000.  Example:
  715.                 (&i,Zz) produces 132,172
  716.  
  717.     I    Converts a string of ASCII octal numbers separated by commas
  718.         to binary, a byte for each ASCII number.  For example,
  719.         (&I,116<,>117<,>77) yields the 3-byte ASCII string NO?
  720.  
  721.     8    Converts a string of bytes into 8-bit ASCII binary numbers 
  722.         (one for each byte) separated by commas; an isolated null
  723.         string produces 00000000.  Example:
  724.             (&8,Zz) produces 01011010,01111010
  725.  
  726.     B    Converts a string of ASCII binary numbers separated by commas
  727.         to binary, a byte to each ASCII number; a single null string 
  728.         produces a single zero byte.  For example,
  729.             (&HB,01011010<,>01111010) yields 7A5A.
  730.  
  731.     =    Yields the letter f if its argument is the null string or at 
  732.         least one of its bytes is non-null; leaves the letter t if 
  733.         all of the argument's bytes are binary 0.
  734. -
  735.     >    Yields the letter f if its argument is the null string or if 
  736.         the sign bit of its rightmost byte is on; t if this byte's 
  737.         sign bit is off.
  738.  
  739.     <    Yields the letter f if its argument is the null string or if
  740.         the sign bit of the rightmost byte is off; the letter t is
  741.         returned if the rightmost byte's sign bit is on.
  742.  
  743.     !    Returns the length of its argument as an ASCII decimal 
  744.         number.  For example, (&!,What<,> me worry?) returns 15.
  745.  
  746.     #    Returns the hash function of its argument as an ASCII decimal
  747.         number, always between 0 and 12.  The hash function is 
  748.         defined here as the remainder modulo 13 of the exclusive or 
  749.         of all the bytes in the argument.
  750.  
  751.     The entire section of the CNVRT library dealing with chracter 
  752. arithmetic may be excluded from the compiled program file by the presence of 
  753. CHR in the [Exclude ...] comment at the beginning of the source program 
  754. file.  Selected portions of the character arithmetic section may be excluded 
  755. by other three-letter keywords listed in this Help file under "Exclude 
  756. feature".
  757.  
  758. :Overlays.
  759.  
  760.     Overlays are an extremely useful feature which allow the running 
  761. of programs whose overall size is much larger than REC's compilation area.  
  762. Overlays may be used when a program can be divided into three or more 
  763. segments such that two or more of them are not needed simultaneously in 
  764. memory.
  765.  
  766.     For instance, suppose program A calls subroutines B and C, but
  767. neither B calls C nor C calls B.  Then program A could constitute a main
  768. overlay which loads B or C when either of them is required.  Thus B and
  769. C share the same memory area and the memory requirements for the entire
  770. program are smaller by the length of the smaller of B and C than the
  771. requirements for the non-overlaid A-B-C combination.  An overlay may
  772. load other overlays, and this way a very large program may be organized
  773. in a tree-like structure of overlays.  Since each overlay is a REC
  774. program compiled when loaded, no relocatability issue arises so that
  775. a given overlay may be loaded at different levels of an overlay tree.
  776.  
  777.     For the purpose of discussion, in what follows the main overlay
  778. will be called "driver" and the rest of the overlays will be called
  779. "secondaries".
  780. -
  781.     A driver is compiled with either CNVSM or CNVRT and should include
  782. in its library all functions needed by it and its secondaries.  Secondaries
  783. may be compiled by CNVSM or CNVRT, in which case they MUST have a directive
  784. [Exclude LIB] before their first procedure.  Alternatively, CCNVSM and CCNVRT
  785. may be used to compile secondaries, in which case no "Exclude" is necessary,
  786. since CCNVRT and CCNVSM are counterparts of CNVRT and CNVSM which have no
  787. provisions for library insertion; additionally, CCNVRT and CCNVSM may be 
  788. invoked as overlays by any CNVRT program.
  789.  
  790.     Overlays may be read from disk files or memory buffers; the latter 
  791. case essentially extends the compile area into REC's pushdown list, from 
  792. which space is procured for memory buffers.  Storing overlays in memory 
  793. buffers also has the advantage that overlay loading from them is 
  794. substantially faster than loading from a disk file.  The following skeleton 
  795. fragment shows how an overlay in a file called F77SY.REC is read from disk 
  796. and written into a MEM: pseudofile whose size is computed from the length
  797. of the original file itself:
  798.     >>(IF,(0),(%R,F77SY.REC,<-->(^Z)),<0>,<<
  799.         >>(%C,F77SY.REC)(,(%Ow,MEM:sy,(&!,<0>)))(%W,MEM:sy,<0>))<<
  800. Closing F77SY.REC before opening MEM:sy saves memory by releasing table and
  801. buffer space associated with F77SY.REC; the length of MEM:sy is determined
  802. by the length of the contents of F77SY.REC; <0> is bound to these contents.
  803. -
  804.     An overlay is loaded and executed by the skeleton
  805.  
  806.             (%V,name,arg)
  807.  
  808. where 'name' is the name of the disk file or memory buffer containing the
  809. overlay and 'arg' is a skeleton whose value is the argument received by the
  810. overlay in the workspace; 'arg' is optional and when omitted, the preceding
  811. comma may also be omitted.
  812.  
  813.     The last overlay loaded may be reexecuted any number of times without
  814. recompiling it (as long as no other overlay is loaded) by calling it with the
  815. skeleton
  816.             ( ,arg)
  817.  
  818. in which a single blank space appears between the left parenthesis and the
  819. comma, and 'arg' is the argument to be passed to the overlay; the skeleton
  820. ( ) (with a single blank) may be used if no argument is to be passed.
  821.  
  822.     Finally, if a program doesn't need the overlay feature, the library 
  823. code for %V may be excluded by writing OVR in the Exclude directive.
  824.  
  825. :"Exclude" feature
  826.  
  827.     Exclusion was already discussed in Section F of CNVRT.HLP, so this
  828. section is only an update on the options available, which are the following:
  829.  
  830.     DSK    Disk system (%Z, %Lr and %Lw)
  831.     BIO    Direct access to BIOS (%B)
  832.     DIR    Directory functions (%S, %A, %D, %N)
  833.     BOO    Return to CP/M (%M)
  834.     CTR    Counter pseudodevice
  835.     MEM    Memory buffer pseudodevice
  836.     NUL    NUL: pseudodevice
  837.     CLS    Close by name (%C)
  838.     PVR    "Print variable" debugging aid pattern
  839.     PRN    Printer skeletons (%P, %p)
  840.     OVR    Overlay feature (%V)
  841.     INT    All of the arithmetic skeletons.  Selected portions of this 
  842.         section of the library may be excluded with the following:
  843.         Keyword            Excludes
  844.           FOR               #f
  845.           FLT           Floating point in #f
  846.           PWR           ** or ^ in #f and #^
  847. -
  848.         Keyword            Excludes
  849.           MOD              % in #f and #%
  850.           GCD               #|
  851.           TWO       #+, #-, #*, #/ #|, #%, #^, #=, #> and #<
  852.           NCM              #=, #> and #<
  853.           IDC            #p and #m
  854.           NCV            #l and #s
  855.           NDH             #D, #d, #H and #h
  856.  
  857.     CHR    All of the character arithmetic skeletons.  Selected portions
  858.         of this section may be excluded as follows:
  859.         Keyword            Excludes
  860.           CDH             &D, &d, &H and &h
  861.           CSE            &u and &l
  862.           SBT            &a and &s
  863.           DOT               &p
  864.           NIB            &n and &b
  865.           233            &i and &I
  866.           BIT            &8 and &B
  867.           BCM              &=, &< and &>
  868.           LEN                &!
  869.           HSH                &#         
  870. -
  871.     All of the above options may be excluded by the directive
  872. [Exclude ALL]; the entire library must be excluded when compiling 
  873. secondary overlays, this is accomplished by [Exclude LIB].
  874.  
  875.  
  876. :Miscellaneous features.
  877.  
  878.     - PDL space is recovered when files are closed in the order opposite
  879. to that used when opening them.  This allows a CNVRT program to process an 
  880. indefinite number of files without leaving a trail of unused FCB's and 
  881. buffers on REC's pushdown list.
  882.  
  883.     - 'Dir full' and 'Disk full' diagnostics are issued if the respective
  884. conditions occur during the compilation of a CNVRT program.
  885.  
  886.     - All four compilers (CNVRT, CNVSM, CCNVRT and CCNVSM) may be loaded
  887. and executed by the overlay skeleton %V; the second argument of %V must be 
  888. the name of a disk file containing the CNVRT program whose compilation is 
  889. desired, e.g., (%V,CCNVSM.REC,FOO) loads CCNVSM, compiles the program in file
  890. FOO.CNV, produces the compiled program file FOO.REC and returns to the
  891. program invoking %V; since CCNVSM inserts no library, FOO.REC may be then
  892. used as an overlay by the same program.
  893.  
  894.  
  895. :[CNVADV.HLP]
  896. [Gerardo Cisneros, 13.8.84]
  897. [end]
  898.