home *** CD-ROM | disk | FTP | other *** search
/ Programmer's ROM - The Computer Language Library / programmersrom.iso / ada / educ / object.doc < prev    next >
Encoding:
Internet Message Format  |  1988-05-03  |  8.6 KB

  1. Date: Fri 8 Mar 85 07:20:26-MST
  2. From: Rick Conn <RCONN@SIMTEL20.ARPA>
  3. Subject: Re: A Validated Ada Compiler for the IBM PC/XT!
  4. To: Stachour@HI-MULTICS.ARPA
  5.  
  6. Paul,
  7.  
  8.     Your point is well-taken.  For very large projects, especially
  9. when a good CM system or library management system is not available
  10. to keep the libraries in sync, offloading may not be feasible.  However,
  11. I continue to feel that there are many situations in which offloading
  12. (at least during unit coding and testing) is quite feasible.
  13.  
  14.     I am just now completing involvement in a spelling checker
  15. program, which is a small- to medium-sized effort.  The design was
  16. oriented around two major objects: the DOCUMENT to be checked and
  17. the DICTIONARY (there can be more than one) to check against.  There
  18. are two packages which deal with these objects, DOCUMENT_HANDLER and
  19. DICTIONARY_MANAGER, and each package was assigned to one person to
  20. code and unit test.  The specifications, which, of course, were subject
  21. to change, were planned during the design phase, and the development
  22. (including coding and unit testing) of the bodies was done in complete
  23. independence.  Such development could easily have been offloaded to
  24. a PC if an Ada compiler existed for one.  The only requirement for this
  25. would be that the MACHINE_DEPENDENCIES packages be duplicated on each
  26. PC.  Each package was in complete control of its object; the
  27. DOCUMENT_HANDLER was given the name of a file containing a
  28. document and provided words and context information to its user.
  29. The user was never concerned with details of document structure or
  30. manipulation.  To illustrate, MICRO:<ADA.EDUCATION> contains the
  31. spec to DOCUMENT_HANDLER as the file DH.ADA.
  32.  
  33.     Integration of these and other independently-written packages
  34. is now taking place with a high degree of success.  I feel that this
  35. object-oriented mindset is key to this success, and Ada is instrumental
  36. in supporting it.
  37.  
  38.         Rick
  39. -------
  40. ---- DH.ADA ----
  41.  
  42.  
  43. -- 
  44. -- DOCUMENT_HANDLER by Richard Conn, TI Ada Technology Branch
  45. -- 27 Feb 85
  46. -- 
  47. with TEXT_IO,
  48.      MACHINE_DEPENDENCIES,
  49.      TOKEN_DEFINITION;
  50. package DOCUMENT_HANDLER is
  51. --------------------------------------------------------------------------
  52. -- Abstract   : DOCUMENT_HANDLER provides input from a document, which
  53. --               is specified to OPEN_SOURCE by a pathname/filename.
  54. --               It returns a WORD from this document each time the routine
  55. --               GET_WORD is called.  When there are no more WORDs in the
  56. --               document, the exception NO_MORE_WORDS is raised.
  57. -- 
  58. --              DOCUMENT_HANDLER can also create a second document, the
  59. --               destination, or output, document.  This facility is
  60. --               enabled when the routine OPEN_DESTINATION is called,
  61. --               where the pathname/filename of the new document is the
  62. --               passed parameter.  The destination document is a mirror
  63. --               of the source document, except that selected words can
  64. --               be replaced with other words via the RESTORE_WORD routine.
  65. --               RESTORE_WORD replaces the last word returned by GET_WORD
  66. --               with a new word.
  67. -- 
  68. --              The context, or lines surrounding the last word returned
  69. --               by GET_WORD, can be obtained from the CONTEXT_OF_LAST_
  70. --               GET_WORD routine.  This routine returns LINES, which is
  71. --               an array of strings, and an INDEX, which is the offset
  72. --               to the first character of the last word returned by
  73. --               GET_WORD, and LENGTH, which is the number of characters
  74. --               in this word.  The constant, TARGET_LINE_IN_CONTEXT,
  75. --               is the index of the line of the context which contains
  76. --               the indicated word.
  77. -- 
  78. --------------------------------------------------------------------------
  79.  
  80.     subtype TOKEN is TOKEN_DEFINITION.TOKEN_TYPE;
  81.  
  82.     MAX_LINE                   : constant POSITIVE :=
  83.                                  MACHINE_DEPENDENCIES.FILE_LINE_LENGTH;
  84.     NUMBER_OF_LINES_IN_CONTEXT : constant NATURAL := 3;
  85.     TARGET_LINE_IN_CONTEXT     : constant NATURAL := 2;
  86.     type CONTEXT_ELEMENT is
  87.         record
  88.             LINE : STRING (1 .. MAX_LINE);
  89.             LAST : NATURAL;
  90.         end record;
  91.     type CONTEXT is array (1 .. NUMBER_OF_LINES_IN_CONTEXT) of CONTEXT_ELEMENT;
  92.  
  93.     -- Note: Exceptions from TEXT_IO may also be raised
  94.     RESTORE_FAILED  : exception;
  95.     NO_MORE_WORDS   : exception;
  96.     SOURCE_NOT_OPEN : exception;
  97.  
  98.     procedure OPEN_SOURCE (FILE_NAME : STRING);
  99. --------------------------------------------------------------------------
  100. -- Abstract   : The source document from which future words are to be
  101. --               returned is opened for input.  GET_WORD returns these
  102. --               words.
  103. --------------------------------------------------------------------------
  104. -- Parameters : FILE_NAME      - Pathname/Filename of file containing
  105. --                               document
  106. --------------------------------------------------------------------------
  107.  
  108.  
  109.     procedure OPEN_DESTINATION (FILE_NAME : STRING);
  110. --------------------------------------------------------------------------
  111. -- Abstract   : The destination document which is built of words from the
  112. --               source document and new, correctly-spelled words provided
  113. --               through RESTORE_WORD
  114. --------------------------------------------------------------------------
  115. -- Parameters : FILE_NAME      - Pathname/Filename of file to contain
  116. --               the destination document
  117. --------------------------------------------------------------------------
  118.  
  119.  
  120.     procedure CLOSE_SOURCE_AND_DESTINATION;
  121. --------------------------------------------------------------------------
  122. -- Abstract   : Close both the source document and destination document
  123. --               files
  124. --------------------------------------------------------------------------
  125. -- Parameters : None
  126. --------------------------------------------------------------------------
  127.  
  128.  
  129.     procedure GET_WORD (WORD : out TOKEN; WORD_IN_BOUNDS : out BOOLEAN);
  130. --------------------------------------------------------------------------
  131. -- Abstract   : Return the next word from the Source Document
  132. --------------------------------------------------------------------------
  133. -- Parameters : WORD           - the next word from the source document;
  134. --                               this structure includes the word itself
  135. --                               (as a string) and the word length
  136. --              WORD_IN_BOUNDS - TRUE if WORD is small enough to fit in
  137. --                               a TOKEN; FALSE if WORD is larger than
  138. --                               the maximum size of a TOKEN; if FALSE,
  139. --                               the full word can be obtained from
  140. --                               the procedure CONTEXT
  141. --------------------------------------------------------------------------
  142.  
  143.  
  144.     procedure RESTORE_WORD (WORD : STRING);
  145. --------------------------------------------------------------------------
  146. -- Abstract   : Replace the last word obtained from GET_WORD with the
  147. --               passed string (WORD); the replacement is done in the
  148. --               destination document only (the source document is not
  149. --               affected)
  150. --------------------------------------------------------------------------
  151. -- Parameters : WORD           - the string containing the new word
  152. --------------------------------------------------------------------------
  153.  
  154.  
  155.     procedure CONTEXT_OF_LAST_GET_WORD (LINES  : out CONTEXT;
  156.                                         INDEX  : out NATURAL;
  157.                                         LENGTH : out NATURAL);
  158. --------------------------------------------------------------------------
  159. -- Abstract   : Return the lines surrounding and including the last word
  160. --               returned by GET_WORD; also return the INDEX and LENGTH
  161. --               of the last word returned by GET_WORD which indicate
  162. --               its position in the TARGET_LINE_IN_CONTEXT
  163. --------------------------------------------------------------------------
  164. -- Parameters : LINES          - the context (lines) surrounding the last
  165. --                               word
  166. --              INDEX          - the offset to the first character of the
  167. --                               last word in TARGET_LINE_IN_CONTEXT
  168. --              LENGTH         - number of characters in the last word
  169. --                               in TARGET_LINE_IN_CONTEXT
  170. --------------------------------------------------------------------------
  171.  
  172. end DOCUMENT_HANDLER;
  173.