home *** CD-ROM | disk | FTP | other *** search
/ rtsi.com / 2014.01.www.rtsi.com.tar / www.rtsi.com / OS9 / OSK / APPS / lout2.lzh / LOUT2 / DOC / TR.IMPL / s5.4 < prev    next >
Text File  |  1994-01-25  |  5KB  |  98 lines

  1. @SubSection
  2.     @Tag { lookahead }
  3.     @Title { The limited lookahead problem }
  4. @Begin
  5. @PP
  6. Basser Lout assumes that there will be enough internal memory to hold
  7. the symbol table plus a few pages, but not an entire document.  This
  8. section describes the consequent problems and how they were solved.
  9. Other interpreters, notably interactive editors running on virtual
  10. memory systems, would not necessarily need this assumption.
  11. @PP
  12. Although Basser Lout can read and format any legal input, its memory
  13. consumption will be optimized when the bulk of the document resides in
  14. galleys whose targets can be identified at the moment they are
  15. encountered.  Let us take the typical example of a root galley which
  16. is a list of pages, a @Code "@BodyText" galley targeted into the
  17. pages, @Code "@Chapter" galleys targeted into {@Code "@BodyText"},
  18. and @Code "@Section" galleys targeted into the @Code "@Chapter"
  19. galleys:
  20. @ID @Code {
  21. "@PageList"
  22. "//"
  23. "@BodyText"
  24. "//"
  25. "@Chapter {"
  26. "    @Section { ... }"
  27. "    @Section { ... }"
  28. "    ..."
  29. "    @Section { ... }"
  30. "}"
  31. "@Chapter {"
  32. "    ..."
  33. "}"
  34. }
  35. Basser Lout is able to read and process such galleys one paragraph at
  36. a time (strictly, from one @Code "//" at the outer level of a galley
  37. to the next), as we now describe.
  38. @PP
  39. When the parser encounters the beginning of a galley, like @Code "@Chapter"
  40. or {@Code "@Section"}, it initiates a new galley process.  The special
  41. receptive symbol @Code "@Input" is substituted for the as yet
  42. unread right parameter of the galley.  As each paragraph of the right
  43. parameter is read, it is deleted from the parse tree and injected into
  44. the galley's {@Code "@Input"}.  The galley is then resumed.  The parser
  45. thus acts as an extra
  46. concurrent process; it has low priority, so that input is read only when
  47. there is nothing else to do.  Since galleys may be nested, a stack of
  48. @Code "@Input" symbols is needed, each with its own environment and
  49. style.  If a galley is encountered for which a target is not immediately
  50. identifiable (a footnote, for example), it is read in its entirety and
  51. hung in pure parse tree form from an @I UNATTACHED index in the usual way,
  52. with an environment but without a style.  It will be flushed later
  53. when its component is promoted.
  54. @PP
  55. In addition to producing a steady flow of components from input, we must
  56. also ensure that receptive symbols do not unduly block their
  57. promotion.  The @Code "@FootSect" symbol at the foot of each page is a
  58. typical example:  until it is deleted the page cannot be printed.
  59. @PP
  60. Receptive symbols are expanded only on demand, so @Code "@FootSect" can
  61. be deleted as soon as we can prove that it is not wanted.  The symbol
  62. table can tell us that only @Code "@FootNote" galleys (with
  63. @Code "@FootPlace&&following" targets) want it, so it might be possible
  64. to deduce that @Code "@FootSect" may be deleted as soon as body text
  65. enters the following page.
  66. @PP
  67. The author was unable to make this work, so Basser Lout requires the
  68. user to identify those galleys which will carry the bulk of the document
  69. ({@Code "@Chapter"}, {@Code "@Section"}, {@Code "@BodyText"}) as
  70. {@I {forcing galleys}}, by writing @Code "force into" instead of
  71. @Code "into" in their definitions.  As described in the previous
  72. section, when a forcing galley attaches to a target, all receptive
  73. symbols preceding the target in its galley are deleted, removing all
  74. impediments to flushing.  For example, when a forcing body text galley
  75. enters a new page, the @Code "@FootSect" symbol on the preceding page
  76. will be deleted.  It seems likely that a system which could afford to
  77. wait until all input was read before deleting any receptive symbols
  78. would not need forcing galleys.
  79. @PP
  80. Galleys whose targets are a long way from their invocation points can be
  81. a problem.  If the direction is {@Code "following"}, such galleys are
  82. held in internal memory for a long time, unless they are to be
  83. sorted.  If the direction is
  84. {@Code "preceding"}, then either the entire intervening document must be
  85. held in memory (prevented by the target from flushing), or else some
  86. forcing galley prematurely deletes the target, leaving the galley bereft.
  87. @PP
  88. The typical example of the latter case occurs when the galley is an
  89. entry in the table of contents, launched backwards from the beginning of
  90. a chapter or section.  Its target in the table of contents will have
  91. been deleted long before, to permit the rest of the document to print,
  92. so the galley ultimately emerges as an unattached galley promoted out of
  93. the root galley.  All such galleys are written to an auxiliary file,
  94. indexed by the missing target.  On the next run, just before that target
  95. is deleted, the auxiliary file is checked and any galleys for it are
  96. read in and flushed.
  97. @End @SubSection
  98.