home *** CD-ROM | disk | FTP | other *** search
/ minnie.tuhs.org / unixen.tar / unixen / PDP-11 / Trees / V6 / usr / doc / rat / rat
Encoding:
Text File  |  1975-06-26  |  4.3 KB  |  221 lines

  1. .ce 100
  2. RATFOR _ A Rational Fortran
  3. .sp 2
  4. B. W. Kernighan
  5. .sp
  6. Bell Laboratories
  7. Murray Hill, N. J. 07974
  8. .ce 0
  9. .fi
  10. .sp 
  11. .de PP
  12. .sp
  13. .ti +5
  14. ..
  15. .PP
  16. Fortran programs are hard to read, write and debug.
  17. To make program development easier,
  18. RATFOR 
  19. provides a set of decent control structures:
  20. .sp
  21. .nf
  22.   statement grouping
  23.   completely general \fBif - else\fR statements
  24.   \fBwhile\fR, \fBfor\fR and \fBdo\fR for looping
  25.   \fBbreak\fR and \fBnext\fR for controlling loop exits
  26. .sp
  27. .fi
  28. and some ``syntactic sugar'':
  29. .sp
  30. .nf
  31.   free form input (e.g., multiple statements/line)
  32.   unobtrusive comment convention
  33.   translation of >, >=, etc., into .GT., .GE., etc.
  34.   ``define'' statement for symbolic parameters
  35.   ``include'' statement for including source files
  36. .sp
  37. .fi
  38. .PP
  39. RATFOR
  40. not only
  41. makes programming in Fortran more enjoyable,
  42. but also allows structured programming, in the sense of
  43. coding without
  44. GOTO's.
  45. RATFOR
  46. programs tend to be markedly easier
  47. to write, read, and make correct than their equivalents
  48. in standard Fortran.
  49. .PP
  50. RATFOR
  51. is a preprocessor,
  52. translating the input into standard Fortran constructions.
  53. RATFOR
  54. programs may readily be written so the generated Fortran
  55. is portable;
  56. program transferability is easy to achieve.
  57. RATFOR
  58. is written in itself,
  59. so it is also portable.
  60. .sp
  61. .PP
  62. The grammar of
  63. RATFOR 
  64. is as follows:
  65. .nf
  66. .sp
  67. prog    : stat 
  68.     | prog  stat
  69. stat    : \fBif\fP( condition ) stat 
  70.     | \fBif\fP( condition ) stat \fBelse\fP stat
  71.     | \fBwhile\fP( condition ) stat
  72.     | \fBfor\fP( initialization; condition; increment ) stat
  73.     | \fBdo\fP do-part stat
  74.     | break
  75.     | next
  76.     | digits  stat
  77.     | { prog }
  78.     | anything unrecognizable
  79. .fi
  80. .sp
  81. In the grammar above,
  82. condition
  83. can be any legal Fortran condition like 
  84. "`A .EQ. B',"
  85. i.e., anything that could appear in a legal Fortran logical 
  86. IF
  87. statement.
  88. stat 
  89. is, of course, any Fortran or
  90. RATFOR
  91. statement,
  92. or any collection of these enclosed in braces.
  93. .PP
  94. The
  95. while
  96. statement performs a loop while some specified condition is true.
  97. The test is performed at the \fIbeginning\fR of the loop,
  98. so it is
  99. possible to do a
  100. while
  101. zero times,
  102. which can't be done with a Fortran
  103. DO.
  104. .PP
  105. The
  106. for
  107. statement
  108. is a somewhat generalized
  109. while
  110. statement
  111. that allows an initialization and an
  112. incrementing step as well as a termination condition
  113. on a loop.
  114. initialization
  115. is any single \fIFortran\fR statement, which gets done once
  116. before the loop begins.
  117. increment
  118. is any single \fIFortran\fR statement,
  119. which gets done at the end of each pass through the loop,
  120. before the test.
  121. .PP
  122. for
  123. and
  124. while
  125. are useful for
  126. backward loops, chaining along lists,
  127. loops that must be done zero times,
  128. and similar things which are hard to express with a 
  129. DO
  130. statement,
  131. and obscure to write out directly.
  132. .PP
  133. The
  134. do
  135. statement is like a Fortran 
  136. DO,
  137. except that no label or 
  138. CONTINUE
  139. is needed.
  140. The \fBdo-part\fP that follows the 
  141. do
  142. keyword has to be something that can legally go into
  143. a Fortran 
  144. DO
  145. statement.
  146. .PP
  147. A
  148. break
  149. causes an immediate exit from a
  150. for,
  151. while
  152. or
  153. do
  154. to the following statement.
  155. The
  156. next
  157. statement causes an immediate transfer to the
  158. increment
  159. part of a
  160. for
  161. or
  162. do,
  163. and the test part of a
  164. while.
  165. Both
  166. break
  167. and
  168. next
  169. refer to the innermost enclosing 
  170. for,
  171. while
  172. or
  173. do.
  174. .sp
  175. .br
  176. .PP
  177. Statements can be placed anywhere on a line;
  178. long statements are continued automatically.
  179. Multiple statements may appear on one line,
  180. if they are separated by semicolons.
  181. No semi-colon is needed at the end of a line,
  182. if
  183. RATFOR
  184. can guess whether the statement
  185. ends there.
  186. Lines ending with any characters
  187. obviously a continuation, like plus or comma,
  188. are assumed to be continued on the next line.
  189. Any statement that begins with an all-numeric field is
  190. assumed to be a Fortran label,
  191. and placed in columns 1-5.
  192. PP
  193. A
  194. `#'
  195. character in a line marks the beginning
  196. of a comment;
  197. the comment is terminated by the end of a line.
  198. .PP
  199. Text enclosed in matching single or double quotes
  200. is converted to
  201. nH...
  202. by
  203. RATFOR,
  204. but is otherwise unaltered.
  205. Characters like `>', `>=', and `&'
  206. are translated into their longer Fortran equivalents
  207. `.GT.', 
  208. `.GE',
  209. and
  210. `.AND',
  211. except within quotes.
  212. .PP
  213. Any string of alphanumeric characters can be defined as a name;
  214. thereafter, whenever that name occurs in the input
  215. (delimited by non-alphanumerics)
  216. it is replaced by the rest of the definition line
  217. (comments are stripped off).
  218. .PP
  219. An entire source file may be included by saying
  220. ``include filename'' at the appropriate place.
  221.