home *** CD-ROM | disk | FTP | other *** search
/ Programmer 7500 / MAX_PROGRAMMERS.iso / INFO / PASCAL / PT01.ZIP / MACRO.MAN < prev    next >
Encoding:
Text File  |  1983-09-07  |  2.9 KB  |  133 lines

  1. .im man.im
  2. .NM macro expand string definitions, with arguments
  3. .SY macro
  4. .FU
  5. .ital macro
  6. reads its input, looking for macro definitions of the form
  7. .Q1
  8.     define(ident,string)
  9. .Q2
  10. and writes its output with each subsequent instance of the identifier
  11. .ital ident
  12. replaced by the arbitrary sequence of characters
  13. .ital string.
  14.  
  15. Within a replacement string, any dollar sign
  16. .ital $
  17. followed by a digit is replaced by an argument corresponding to that digit.
  18. Arguments are written as a parenthesized list of strings following an
  19. instance of the identifier, e.g.,
  20. .Q1
  21. ident(arg1,arg2,...)
  22. .Q2
  23. So
  24. .ital $1
  25. is replaced in the replacement string by
  26. .ital arg1,
  27. .ital $2
  28. by
  29. .ital arg2,
  30. and so on;
  31. .ital $0
  32. is replaced by
  33. .ital ident.
  34. Missing arguments are taken as null strings;
  35. extra arguments are ignored.
  36.  
  37. The replacement string in a definition is expanded before the definition
  38. occurs, except that any sequence of characters between a grave
  39. .ital `
  40. and a balancing apostrophe
  41. .ital \'
  42. is taken literally, with the grave and apostrophe removed.
  43. Thus, it is possible to make an alias for define by writing
  44. .Q1
  45.     define(def,`define($1,$2)')
  46. .Q2
  47.  
  48. Additional predefined built-ins
  49. are:
  50.  
  51. .ital ifelse(a,b,c,d)
  52. is replaced by the string
  53. .ital c
  54. if the string
  55. .ital a
  56. exactly matches the string
  57. .ital b;
  58. otherwise it is replaced by the string
  59. .ital d.
  60.  
  61. .ital expr(expression)
  62. is replaced by the decimal string representation of the numeric value of
  63. .ital expression.
  64. For correct operation, the expression must consist of
  65. parentheses, integer operands written as decimal digit strings, and
  66. the operators
  67. .ital +,
  68. .ital -,
  69. .ital *,
  70. .ital /
  71. (integer division), and
  72. .ital %
  73. (remainder).
  74. Multiplication and division bind tighter than addition and subtraction,
  75. but parentheses may be used to alter this order.
  76.  
  77. .ital substr(s,m,n)
  78. is replaced by the substring of
  79. .ital s
  80. starting at location
  81. .ital m
  82. (counting from one)
  83. and continuing at most
  84. .ital n
  85. characters.
  86. If
  87. .ital n
  88. is omitted, it is taken as a very large number;
  89. if
  90. .ital m
  91. is outside the string, the replacement string is null.
  92. .ital m
  93. and
  94. .ital n
  95. may be expressions suitable for
  96. .ital expr.
  97.  
  98. .ital len(s)
  99. is replaced by the string representing the length of its argument
  100. in characters.
  101.  
  102. .ital changeq(xy)
  103. changes the quote characters
  104. to
  105. .ital x
  106. and
  107. .ital y.
  108. .ital changeq()
  109. changes them back to
  110. .ital `
  111. and
  112. .ital \'.
  113.  
  114. Each replacement string is rescanned for further possible
  115. replacements, permitting multi-level definitions to be expanded to final
  116. form.
  117. .EG
  118. The macro
  119. .ital len
  120. could be written in terms of the other built-ins as:
  121. .Q1
  122. define(`len',`ifelse($1,,0,`expr(1+len(substr($1,2)))')')
  123. .Q2
  124. .BUGS
  125. A recursive definition of the form
  126. .ital define(x,x)
  127. will cause an infinite loop.
  128. .br
  129. Expression evaluation is fragile.
  130. There is no unary minus.
  131. .br
  132. It is unwise to use parentheses as quote characters.
  133.