home *** CD-ROM | disk | FTP | other *** search
/ Oakland CPM Archive / oakcpm.iso / sigm / vol166 / howtouse.doc < prev    next >
Encoding:
Text File  |  1984-04-29  |  22.0 KB  |  408 lines

  1.  
  2. [HOWTOUSE.DOC]
  3. [Harold V. McIntosh, 28 December 1983]
  4.  
  5. This disk is intended as a collection of examples for the programming
  6. language REC, although many of the examples are useful in their own
  7. right, particularly CNVRT.REC which compiles the programming language
  8. CONVERT. The files REC80.COM and REC86.CMD are binary files containing
  9. object code for REC destined respectively for the Intel 8080 and the
  10. Intel 8086. REC80 may be executed by the Intel 8080, Intel 8085, or the
  11. Zilog Z80, since it uses none of the instructions which differentiate
  12. these CPU's. REC86 will presumably execute in any of the Intel family
  13. of 8086 CPU's, that is the 8088, 80186, 80286, although in fact it has
  14. only been proven on Godbout's dual 8085-8088 board.
  15.  
  16. REC80 partitions the available memory in the ratio 5-4-1 for compile
  17. area, pushdown area and workspace, after setting aside space for the
  18. 8080's pushdown stack and having lost whatever space was occupied by the
  19. binary program and the tables FXT and VRT.  REC86 is configured for 8080
  20. mode with a 64K code segment, and a fixed partition for the available
  21. memory. Thus REC80 will work in almost any system - at least 16K or
  22. larger, but since the source code is available on the companion disk,
  23. either of the two versions can be reassembled to suit whatever system
  24. desired by changing the EQU's defining the memory partition or else
  25. by reprogramming the partitioning alogrithm.
  26.  
  27. The assumed operating system is CP/M 2.2, on the one hand, or CP/M86
  28. on the other hand. However, deliberate advantage is taken of the CP/M
  29. transfer vector in BIOS to get direct access to console I-O. This was
  30. necessary in some editor-like applications of REC, for which CP/M's
  31. tampering with the data stream was too slow and conflicted with the
  32. natural editing functions of the programs involved. The source code
  33. contains provision to restore the CP/M I-O. We have observed that the
  34. direct access prevents REC programs from working with MicroShell in all
  35. respects. REC80 will run with CP/M 1.4, because it does not use any of
  36. the features which distinguish the two versions.
  37.  
  38. There are some minor aspects in which the programs are dependent on
  39. the nature of the console equipment, again when used for editing and
  40. similar purposes. Although some ASCII standards are universally res-
  41. pected, such as for the assignment of carriage return and line feed,
  42. many others are not, or do not even exist. Thus screen clear, and the
  43. cursor movements may require some adjustment, although this adjustment
  44. can be made in the applications programs and would not require any
  45. change in the binary REC programs.  As written, they have all worked
  46. successfully with the TeleVideo 912-C and TeleVideo 910 terminals.
  47.  
  48. REC has operators which give direct access to the I-O ports. None of
  49. these applications programs use them.   Anyone planning to use them
  50. would clearly have to know the configuration of his own system to do
  51. so.  The operators in REC86 are literal transcriptions of those in
  52. REC80, and have not been tested for 16-bit port addresses.
  53.  
  54. REC expects to find one or two file names on its command line.  If it
  55. finds neither, it enters a conversational mode, in which it displays
  56. a logo with the version date.  In this mode REC expressions may be
  57. entered, using CP/M's editing facilities [which means that you can get
  58. back to CP/M by typing ^C at the beginning of a blank line].  They are
  59. compiled and promptly executed, giving one an opportunity to experiment
  60. with REC as a language.  Try ('hello'TL;) for example. A line may be
  61. edited, but once a carriage return is given, it is compiled and cannot
  62. be retrieved for additional changes. As many lines will be prompted as
  63. required to balance parentheses; there is no guarantee that the program
  64. entered makes sense, of course.
  65.  
  66. When REC encounters a file name on the command line, it supposes that
  67. it is the name of a source file which is to be loaded and executed. A
  68. second file name is preserved and transmitted to the executing program
  69. in the CP/M location 05CH, which means that an application program can
  70. make use of CP/M's file handling facilities. REC does not preserve the
  71. remainder of the command line, however.
  72.  
  73. There is no such thing as REC object code, because the compiler is a
  74. loader, which loads for immediate execution.
  75.  
  76. REC, as a language, can be described rather simply. There are four
  77. control symbols - the two parentheses, colon and semicolon. There are
  78. also operations, and some of these can have truth values [true or
  79. false], and are designated predicates. Operations are executed in the
  80. sequence they are written, which can be interrupted in two ways. A
  81. colon means to repeat the sequence from the beginning, a semicolon means
  82. to quit entirely. A predicate can interrupt the sequence in one further
  83. way - when it is false you take up a new sequence. The new sequence can
  84. be written after the nearest colon or semicolon, a place which otherwise
  85. is inaccessible. After mentioning two idiosyncracies the description of
  86. the control is complete.
  87.  
  88. First, several predicates in a sequence all go over to the same alternate
  89. sequence in the case they are false. Instead of giving a program the form
  90. of a binary tree in which the point at which execution has arrived is
  91. well defined by the hisory of previous definitions, many of the branches
  92. are allowed to overlap. Often this is of no concern, but it will now and
  93. then happen that it is necessary to know how the program got to a given
  94. point. Setting and testing variables is a simple resolution which goes
  95. outside the framework of a simple control structure - it implies a theory
  96. of variables. Repeating a past predicate may be inconvenient [say there
  97. is a very long calculation involved] or impossible [a real-time event
  98. has passed]. This quandray already appears in the calculation of an
  99. exclusive or [a and not-b or not-a and b; you may have to do one or the
  100. other twice].  Recognizing the existence of this point goes a long way
  101. toward meeting the confusion it may cause, which in many years of REC
  102. programming has seemed to be the only really serious source of indecision
  103. in laying out programs.
  104.  
  105. The second point is that logical negatives are essential in setting up
  106. a program, and can be obtained in a slightly backhanded way by reversing
  107. the sense of all predicates in the final segment of a REC expression. In
  108. a simpler form, if p is a predicate, (p) is its negative.
  109.  
  110. Indeed, boolean combinations of predicates can be realized through the
  111. flow of control set up by the syntactic elements we have mentioned. If
  112. p and q are two predicates, (p;q;) is their logical or, (pq;) is their
  113. and. (p(q);(p)q;) is the exclusive or but, as remarked, it may involve
  114. doing p or q twice. Since the evaluation of a series of predicates is
  115. sequential, from left to right, no more of them will be executed than is
  116. necessary to reach a decision. As a consequence the boolean operations are
  117. not really commutative, and care must be taken  with their ordering. In
  118. practice this situation is more of an advantage than a disadvantage.
  119.  
  120. Few programs can subsist without subroutines, and REC is no exception.
  121. The mechanism of subroutine definition is to enclose a list of the
  122. desired subroutines and their names, together with the program which
  123. is to use them, in a pair of curly braces. The combination might show
  124. the form {(www) a (xxx) b ... (yyy) n (zzz)}, in which the first
  125. parenthesis [which itself could be enclosed in braces because of some
  126. subroutine nesting] the definition of the subroutine a, and so on. It 
  127. is agreed that all the subroutine definitions will be valid within the
  128. main program and each other, but only within the curly braces, and
  129. unless superceded at a lower level by a new subroutine definition on
  130. that level.
  131.  
  132. In reality, the syntactical definition of REC says nothing whatsoever
  133. about the choice of operators or predicates for the language, nor about
  134. the symbolism used to represent them, beyond the reservation of the
  135. symbols which have been mentioned.  It is a historical custom that REC
  136. has used single letters for symbols, mainly because of the convenience
  137. of a single keystroke in its interactive use, and the resulting economy
  138. of not having to parse identifiers. REC80, which is linguistically
  139. identical to REC86, displays a collection of operators and predicates
  140. assigned to slightly less than the 96 printable characters of the ASCII
  141. alphabet, whose detailed description is often quite intricate, and which
  142. may be deduced from the explanations given in the source listings. Some
  143. twenty years of experience, and the influence of several people have gone
  144. into the choice of a relatively general-purpose collection. Anyone could
  145. start afresh and create a new version of REC by changing its inherent
  146. function library; something which has been done from time to time in the
  147. past.
  148.  
  149. The REC in this collection makes use of three principal data structures,
  150. to which a proportionate share of the available memory is dedicated. They
  151. are: the compiling area, the pushdown list, and the workspace. The first
  152. of these is where the program which REC compiles is normally stored;
  153. if access to the compiler itself is granted in the choice of functions
  154. [C, in the present example], the use of this area can be programmed.
  155. The second, the pushdown list, reflects a decision to work on the level
  156. of reversed Polish notation, passing arguments to functions through a
  157. stack and recovering results from the same place. Chains of characters
  158. are likely to be the principal data type used, which means that some
  159. provision must be made for handling variable length arguments.  The
  160. third structure is a sort of accumulator for long character strings,
  161. and is serviced by specialized functions such as searches, insertions,
  162. and deletions.
  163.  
  164. The source listings contain descriptions of each of the operators and
  165. predicates, and should be consulted for the details of their functioning.
  166. The listing is broken down into separate modules according to these
  167. functional groupings, namely compiler, pushdown list, workspace, main
  168. program and input-output.
  169.  
  170. REC interacts with the CP/M operating system by treating BDOS as a
  171. subroutine [k, or K] to which the necessary parameters are passed.
  172. Space for buffers, file control blocks and the like can be taken from
  173. the pushdown list, the workspace, or from absolute locations in the
  174. memory.
  175.  
  176. The disk is mostly filled with applications programs.  Five of them
  177. are compilers for "languages," such as one would meet in a Computer
  178. Science course. Indeed, in Puebla they are used for exercises in just
  179. such courses. Consequently, a certain background in things mathematical
  180.  - symbolic logic,  for example - would probably be useful preparation
  181. for the examples. Be that as it may, the applications of these languages
  182. are in turn readily comprehensible and rather amusing.  Much sport can
  183. be had making up Turing Machines or Markov Algorithms to do simple
  184. things.
  185.  
  186. The languages are:
  187.  
  188.         Turing Machine
  189.         Markov Algorithm
  190.         Post Production
  191.         LISP
  192.         CONVERT.
  193.  
  194. They range from simple to complex; by far the most attention was
  195. devoted to the last of these, because it is a practical language of
  196. many applications.  So is LISP, of course, but here it was written in
  197. REC as an exercise, which means that one should turn to one of the
  198. many serious LISP processors available if the intention is to use it
  199. for a major undertaking.
  200.  
  201. In all cases one or two sample programs are shown for these languages
  202. so that some comparisons can be made between the ways that each of
  203. these languages goes about doing things; a binary sum is one example,
  204. a self-compiler of the language where appropriate is another.  The
  205. user of this disk is urged to prepare for unpleasant surprises by
  206. making a backup copy before doing any experimentation. The REC versions
  207. of the sample programs will actually run, and are intended to be
  208. significant and illustrative in their own right. However, the five
  209. programs cited above will compile them from their own source programs.
  210. If this compilation is botched, one will be deprived of the enjoyment
  211. of the sample programs until the art of compilation has been mastered;
  212. this may or may not take a while.
  213.  
  214. One of the great stimulants for the evolution of REC in particular
  215. directions was the desire to have a language with which CONVERT could
  216. be compiled; CONVERT has previously existed as an interpreter within
  217. LISP. Even yet there are details to be mastered in the generation of
  218. search patterns for CONVERT, so that CNVRT.REC will suffice for a time.
  219. CONVERT is a pattern matching language whose evolution from a scheme
  220. such as Post Productions is relatively evident. The idea behind its
  221. operation is to isolate segments of a text, either because they satisfy
  222. some requirement or because they are situated in a prescribed envoiron-
  223. ment [letters between a pair of parentheses, for example]. The segments
  224. so isolated are to be combined into new text, preferably with the help
  225. of very general functions and control structures. The whole process can
  226. be repeated over and over until a desired result is obtained.
  227.  
  228. A brief outline of CNVRT is the following. The same structure that REC
  229. has is followed, to facilitate compilation. Thus a string of subroutines
  230. is to be written terminated by a main program; CNVRT.REC will insert the
  231. curly braces and the set of system subroutines.
  232.  
  233. Each individual program is a quadruple, (()()()()), consisting of a list
  234. of pattern definitions, a list of skeleton definitions, a list of the
  235. variables to be used, and a rule set. Some of these elements may be null,
  236. but they must nevertheless be represented in the quadruple by a parenthesis
  237. pair.
  238.  
  239. Pattern and skeleton lists follow the convention of alternating the body
  240. of the definition with the name which will represent it. Variables are
  241. simply numbers, in the range 0 to 20 or so (32, minus variables used by
  242. the system), separated by spaces. The only penalty attached to listing
  243. more variables than are needed is that they will be needlessly saved and
  244. unsaved many times.
  245.  
  246. The rule set is a sequence of pairs, each pair must be followed by a
  247. colon or semicolon; in the nature of REC this determines whether the
  248. rule is a repetitive rule or a terminal rule. The pair consists of a
  249. pattern and a skeleton; the pattern is a predicate which ascertains
  250. whether the content of REC's workspace has a prescribed form or not.
  251. If it does, it may have identified some strings and labelled them as
  252. values of the variables. A successful pattern match is followed by
  253. substitution in the skeleton, an unsuccessful match results in passing
  254. to the next rule. If no rules remain, the process halts, the workspace
  255. remains unchanged.
  256.  
  257. The skeleton portion of the rule determines the new content of the
  258. workspace. The workspace may be transformed iteratively by a repetitive
  259. rule, in which case the same rule set is scanned anew. Among the patterns
  260. are functions, whose arguments fill the workspace, and whose own rule set
  261. determines the further course of transformation. Several functions can
  262. work in sequence, each building up its part of the new workspace.
  263.  
  264. Patterns are primitive and composite. Primitive patterns can be constants
  265. or variables. Implicitly, any character string which is not otherwise a
  266. pattern is a constant, recognizing the same character string in the
  267. workspace text. An interplay between round parentheses and angular
  268. brackets is used to quote these syntactic elements. Variables are strings
  269. of characters which are identified by special symbols, and which ought to
  270. have been selected in advance of the pattern matching. Part of the intricacy
  271. of CNVRT.REC, whose development has still not been brought to completion,
  272. lies in the mixing of the generation of variable candidates with the search
  273. and matching mechanism. If they are not mixed, however, the search becomes
  274. even more time consuming than it already is.
  275.  
  276. Composite patterns are either boolean combinations of simpler patterns, or
  277. pattern definitions, or recursive combinations of the two. Two special
  278. cases, maximal iteration and minimal iteration, handle the majority of
  279. applications of recursively defined patterns [a parenthesis nest, a list
  280. of even length, or something similar], and may indeed be sufficient for
  281. all such combinations.
  282.  
  283. Skeletons are either constants, variables, or functions. Again, anything
  284. which is not explicitly something else is implicitly a constant, which
  285. saves a great deal of quotation. Variables are character strings which
  286. were dissected out of the source text by the matching pattern paired with
  287. the skeleton. For the moment, functions are defined externally, but with
  288. time and experience inherent functions will probably be included in the
  289. language - counterparts of such things as do, while, or if in some of the
  290. other popular languages.
  291.  
  292. Two principal examples of the use of CNVRT are included; one is the
  293. traditional symbol manipulation exercise of calculating symbolic
  294. derivatives without deltas and epsilons, but rather from a systematic
  295. application of the rules for the construction of algebraic expressions
  296. and the rules for the derivatives of these constructions; both can be
  297. given a very elegant formulation in recursive terms.
  298.  
  299. The second example is not complete, but is included because of its
  300. utility in understanding another popular language - "C". The five
  301. programs
  302.  
  303.         ASMBL.CNV
  304.         STMNT.CNV
  305.         DCLRN.CNV
  306.         EXPRN.CNV
  307.         PRGRM.CNV
  308.  
  309. each illustrate one aspect of"C".  They can be used to test one's
  310. understanding of respectively, "C", Kernighan and Ritchey's book,
  311. CNVRT, or any combination of the three.  In particular, STMNT does
  312. not exactly handle "CASE" correctly; this can be easily corrected,
  313. it is a useful exercise to see how to do so.  It is interesting that
  314. the five programs were written in one month's time, using appendix
  315. A of the book, with little previous understanding of many of the
  316. principal ingredients.  Two months are still lacking to realize the
  317. hypothetical goal of establishing a "C" compiler in a new machine,
  318. and will evidently be spent in learning how to bring down the size
  319. of all the intermediates a little.
  320.  
  321. As a final illustration, a CNVRT "compiler" of REC is shown, which
  322. in turn may be examined for some insight into how REC works.
  323.  
  324. One portion of the REC compiler, which occupies about 1.5K bytes,
  325. does the actual compilation, and functions just about as efficiently
  326. as a loader would.  In fact, the custom of restricting REC functions
  327. to single letters results in the compiled code occupying about three
  328. times the volume of the source code.  This is understandable in terms
  329. of the jumps and calls, each three byte instructions, into which the
  330. majority of REC characters translate.  Particularly in the days of
  331. paper tape readers or punched card readers, the saving in volume amply
  332. repaid the time dedicated to compilation.
  333.  
  334. A second portion of REC contains functions managing the pushdown list,
  335. with another third involved in the operation of the workspace. Some
  336. space is dedicated to tables, and to input-output routines.  However,
  337. the majority of these depend upon CP/M for their operation, which is
  338. a part of the system overhead.  All told, REC for either machine, 8080
  339. or 8086, occupies 5K bytes of code.
  340.  
  341. There is obviously some inefficiency resulting from compiling a program
  342. in REC rather than writing it in assembly language.  The restriction of
  343. the number of functions to the ASCII alphabet has resulted in some
  344. ingenious combinations and programming conventions which all take their
  345. toll in space.  As usual, the rapidity with which certain tasks can be
  346. programmed in any language overshadows many of the penalties which are
  347. paid for a systematic and stylized way of doing things.
  348.  
  349. The situation becomes more pronounced in CNVRT; to program every
  350. possible combination within a general class without fail requires
  351. elaborate precautions which are hardly ever necessary in the simpler
  352. examples.  One has only to think of the similar situation in "C",
  353. FORTRAN, and other languages where the generality of indexing in
  354. arrays leads to formulations which appear excessive when applied to
  355. one-dimensional character strings.  CNVRT seems to inflate by a
  356. factor between two and five when compared to REC, again depending
  357. on the proportion of comments present.  This can mean a factor of
  358. ten to twenty compared to machine language.
  359.  
  360. This condition will have to be overcome before a "C" compiler written
  361. in CNVRT becomes a practical reality. As it would seem, the same could
  362. be said of a "C" compiler written in "C".
  363.  
  364. The programming examples are intended to be self-sufficient.  Thus,
  365. when executed, say by a command line such as:
  366.  
  367. A>REC80 DERIV.REC
  368.  
  369. they will respond with an indication of the kind of input that they
  370. expect.  Many are one-shot, running through a single cycle of oper-
  371. ation before returning to CP/M, others will cycle indefinitely until
  372. given null input.  A person who wishes to improvise some programs of
  373. his own should note the trick employed by the five language compilers.
  374. Any commentary enclosed between double square brackets - [[...]] -
  375. will be echoed by the program as part of its initialization.  Also,
  376. the source programs have three blank lines near their beginning, which
  377. designates a preferred location for the pre-defined subroutines which
  378. the compiler will incorporate into its object program.
  379.  
  380. In general, these two features must be found within the first 1K bytes
  381. of the source program, and considerable caution should be exercised
  382. regarding the placement of parentheses, double square brackets, and
  383. triple blank lines at the beginning of programs.  Also, a title such
  384. as [PROGRAM.XXX] will be changed to [PROGRAM.REC], helping to identify
  385. the compiled program.
  386.  
  387. The compilers require a command line of the form:
  388.  
  389. A>REC80 LANGUAGE.REC PROGRAM.LNG
  390.  
  391. where LNG is the extension - TNG, MKV, PST, LSP, or CNV - identifying
  392. the language.  In each case, the program will expect the user to employ
  393. it as an editor, compiling the source code line by line.  Inexperienced
  394. users will probably not want to follow this procedure; therefore when
  395. the language extension is omitted:
  396.  
  397. A>REC80 LANGUAGE.REC PROGRAM
  398.  
  399. the compiler will follow an automatic sequence which will require no
  400. operator intervention. However, the file must already exist on the disk
  401. with the appropriate extension.  The usual CP/M conventions for designating
  402. alternative disks may be used, nor need REC80 reside on disk A. In this
  403. mode of operation there is no interaction via the console, and thus there
  404. need be no preoccupation with the cursor controls and screen clearing
  405. commands.
  406.  
  407. [end]
  408.