home *** CD-ROM | disk | FTP | other *** search
/ Amiga MA Magazine 1998 #6 / amigamamagazinepolishissue1998.iso / coders / jËzyki_programowania / oberon / text / exprprogramming.text (.txt) < prev    next >
Oberon Text  |  1977-12-31  |  17KB  |  290 lines

  1. Syntax12.Scn.Fnt
  2. StyleElems
  3. Alloc
  4. Paragraph
  5. Syntax12i.Scn.Fnt
  6. Syntax12m.Scn.Fnt
  7. Headline
  8. Syntax10.Scn.Fnt
  9. Paragraph
  10. Paragraph
  11. Paragraph
  12. Paragraph
  13. Figure
  14. KeplerElems
  15. Alloc
  16. KeplerGraphs
  17. GraphDesc
  18. KeplerGraphs
  19. StarDesc
  20. Kepler1
  21. TextureDesc
  22. Kepler1
  23. RectangleDesc
  24. KeplerFrames
  25. CaptionDesc
  26. Syntax12.Scn.Fnt
  27. tan( )
  28. Syntax12.Scn.Fnt
  29. Kepler1
  30. AttrDesc
  31. Syntax10.Scn.Fnt
  32. sin( )
  33. Syntax12.Scn.Fnt
  34. Syntax10.Scn.Fnt
  35. Syntax12.Scn.Fnt
  36. Syntax12.Scn.Fnt
  37. Caption
  38. ExprIcons
  39. Alloc
  40. ExprStd
  41. AllocSymbol
  42. ExprStd
  43. AllocFunction
  44. ExprStd
  45. AllocBinaryOp
  46. ExprStd
  47. AllocInteger
  48. ExprIcons
  49. AllocGraph
  50. ExprSlang
  51. Alloc
  52. Paragraph
  53. Paragraph
  54. Headline
  55. Paragraph
  56. Paragraph
  57. Paragraph
  58. Paragraph
  59. ExprSlang
  60. Alloc
  61. Paragraph
  62. Paragraph
  63. Paragraph
  64. Figure
  65. KeplerGraphs
  66. GraphDesc
  67. KeplerGraphs
  68. StarDesc
  69. Kepler1
  70. TextureDesc
  71. KeplerFrames
  72. CaptionDesc
  73. Expression
  74. Syntax12.Scn.Fnt
  75. Displayable Expr.
  76. Syntax12.Scn.Fnt
  77. Kepler1
  78. RectangleDesc
  79. Kepler1
  80. AttrDesc
  81. extends
  82. Syntax12.Scn.Fnt
  83. Syntax10.Scn.Fnt
  84. extends
  85. Syntax12.Scn.Fnt
  86. Syntax10.Scn.Fnt
  87. Syntax12.Scn.Fnt
  88. concrete Expr.
  89. Syntax12.Scn.Fnt
  90. Syntax12.Scn.Fnt
  91. concrete Box
  92. Syntax12.Scn.Fnt
  93. extends
  94. Syntax12.Scn.Fnt
  95. Syntax10.Scn.Fnt
  96. Syntax10.Scn.Fnt
  97. View Frame
  98. Syntax12.Scn.Fnt
  99. Syntax12.Scn.Fnt
  100. Caption
  101. Headline
  102. Paragraph
  103. Paragraph
  104. Figure
  105. KeplerGraphs
  106. GraphDesc
  107. KeplerGraphs
  108. StarDesc
  109. Kepler1
  110. TextureDesc
  111. Kepler1
  112. RectangleDesc
  113. KeplerFrames
  114. CaptionDesc
  115. Text Framework
  116. Syntax12.Scn.Fnt
  117. Model Component
  118. Syntax12.Scn.Fnt
  119. Viewing Component
  120. Syntax12.Scn.Fnt
  121. Icon Component
  122. Syntax12.Scn.Fnt
  123. Kepler1
  124. AttrDesc
  125. - immutable lists
  126. Syntax12.Scn.Fnt
  127. - abstract expression class
  128. Syntax12.Scn.Fnt
  129. Syntax10.Scn.Fnt
  130. - box type
  131. Syntax12.Scn.Fnt
  132. - abstract ports
  133. Syntax12.Scn.Fnt
  134. Syntax10.Scn.Fnt
  135. - abstract visualization method
  136. Syntax12.Scn.Fnt
  137. - text-conversion
  138. Syntax12.Scn.Fnt
  139. - concrete
  140.  ports
  141. Syntax12.Scn.Fnt
  142. Syntax10.Scn.Fnt
  143. - subselections
  144. Syntax12.Scn.Fnt
  145. Caption
  146. Paragraph
  147. Figure
  148. KeplerGraphs
  149. GraphDesc
  150. KeplerGraphs
  151. StarDesc
  152. Kepler1
  153. TextureDesc
  154. KeplerFrames
  155. CaptionDesc
  156. Expression
  157. Syntax12.Scn.Fnt
  158. Displayable Expr.
  159. Syntax12.Scn.Fnt
  160. Kepler1
  161. RectangleDesc
  162. Kepler1
  163. AttrDesc
  164. extends
  165. Syntax12.Scn.Fnt
  166. Syntax10.Scn.Fnt
  167. extends
  168. Syntax12.Scn.Fnt
  169. Syntax10.Scn.Fnt
  170. Syntax12.Scn.Fnt
  171. Standard Expr.
  172. Syntax12.Scn.Fnt
  173. Syntax12.Scn.Fnt
  174. concrete Box
  175. Syntax12.Scn.Fnt
  176. extends
  177. Syntax12.Scn.Fnt
  178. Syntax10.Scn.Fnt
  179. Syntax10.Scn.Fnt
  180. Expr. Icon
  181. Syntax12.Scn.Fnt
  182. Syntax10.Scn.Fnt
  183. Text Elem
  184. Syntax12.Scn.Fnt
  185. Syntax12.Scn.Fnt
  186. Syntax12.Scn.Fnt
  187. Syntax10.Scn.Fnt
  188. Texts
  189. Syntax12.Scn.Fnt
  190. Syntax12.Scn.Fnt
  191. Syntax12.Scn.Fnt
  192. Expr. Converter
  193. Syntax12.Scn.Fnt
  194. Syntax12.Scn.Fnt
  195. Syntax12.Scn.Fnt
  196. Syntax10.Scn.Fnt
  197. Syntax10.Scn.Fnt
  198. further Extension
  199. Syntax12.Scn.Fnt
  200. extends
  201. Syntax12.Scn.Fnt
  202. Syntax10.Scn.Fnt
  203. Syntax12.Scn.Fnt
  204. Caption
  205. Figure
  206. KeplerGraphs
  207. GraphDesc
  208. KeplerGraphs
  209. StarDesc
  210. Kepler1
  211. AttrDesc
  212. Kepler1
  213. TextureDesc
  214. Kepler1
  215. RectangleDesc
  216. KeplerFrames
  217. CaptionDesc
  218. Texts
  219. Syntax12.Scn.Fnt
  220. Expressions
  221. Syntax12.Scn.Fnt
  222. ExprViews
  223. Syntax12.Scn.Fnt
  224. ExprIcons
  225. Syntax12.Scn.Fnt
  226. ExprStd
  227. Syntax12.Scn.Fnt
  228. ExprLib0
  229. Syntax12.Scn.Fnt
  230. ExprTools
  231. Syntax12.Scn.Fnt
  232. Syntax12.Scn.Fnt
  233. Syntax12.Scn.Fnt
  234. ExprSlang
  235. Syntax12.Scn.Fnt
  236. Syntax12.Scn.Fnt
  237. Syntax12.Scn.Fnt
  238. ExprMaple
  239. Syntax12.Scn.Fnt
  240. ExprStdIcons
  241. Syntax12.Scn.Fnt
  242. Caption
  243. Headline
  244. Paragraph
  245. Paragraph
  246. Headline
  247. Paragraph
  248. This a preliminary document, meant as an introduction for the programmer to the concepts used in the framework. It discribes the paradigm, of the model, view, and icon components, and gives an overview of the modules involved. It is not (yet) a detailed description of the module interfaces. For the moment please refer to the example programs ExprBessel.Mod (a special expression extension) and ExprSubstituter.Mod (a evaluator command). Please feel free to discuss any particular question with me via e_mail.
  249. The Model Component
  250. The purpose of a framework for mathematical expressions is to represent expressions and make them accessible to client software like mathematical operators or evaluators. A service of this kind could be offered by an abstract data type. The structure of expressions is recursive - an expression may refer to an arbitrary number of subexpressions. Thus, expressions are represented as directed graphs: Each node represents an expression and the outgoing edges refer to the subexpressions.
  251. The framework must allow for extension with new types of expressions. On the other hand, an expression of a new type might occur as a subexpression of any other expression. Thus, the abstract data type must be generic. It is realized as an abstract class. This class needs to define all the features that are common to all expressions. Every concrete expression will be an extension of it.
  252. The main feature to be defined in the abstract class is the abstraction of the subexpression graph structure. We use immutable lists for that purpose. Every expression object is accompanied by a (possibly empty) list of references to other expressions. This list is accessible by clients, even without knowledge of the exact type of a node. This is important to allow for commands to operate on subexpressions of particular types, even if these subexpressions occur within an expression whose type is unknown.
  253. Expression objects are immutable. This has the advantage that multiple references to the same expression can be implemented without copying or special bookkeeping. Further, expressions can be stored in a DAG (directed acyclic graph) rather than in a tree. But, if a subexpression within an expression is being changed (i.e. replaced), the entire expression has to be rebuilt to incorporate the change. Thus, a copy is generated, but only of the objects that actually change. For all other objects, references are included (see figure 1). This type of operation is anchored in the abstract class with the definition of a clone method.
  254. Figure 1: The DAG representing 
  255.  (white objects) and additional nodes resulting when changing sin to tan (grey objects).
  256. As a consequence of this model the primitive for expression manipulation is the replacement of a subexpression. This has the advantage to assert the formal consistency of any expression at any time. For instance, for every fraction it is asserted that a numerator and a denominator exist.
  257. Further features are defined by methods serving to compare expressions for equality, and for generation of a normalized form.
  258. The View Component
  259. When expressions are made visible in a two_dimensional form, the types of the individual expressions have a strong influence on the exact presentation. In contrast to the text model, where at least the overall structure is always a sequence of objects (characters), even the placement of the subexpressions of an expression depends on the concrete kind of expression. From this follows that it is impossible to design a generic view component completely independent of the concrete expression classes. As a consequence, a second abstract class has been introduced, extending the model class discussed above. The only extension is the ability to visualize.
  260. The process of drawing an expression on a two_dimensional plane could be implemented by a recursive two phase protocol. In a first phase, for each node in the DAG the size of each subexpression needs to be determined, then the subexpressions can be positioned, and from this the size of the entire expression can be computed. In a second phase, the expressions can be drawn themselves.
  261. For efficiency reasons, the information about subexpressions computed during the first phase has to be stored for re_use during the second phase. Re_computation on demand would result in an algorithm exponential - rather than linear - in the number of nodes.
  262. Whereas the model component represents expressions and subexpressions as a DAG, for visualization a tree structure is more appropriate. The reason is mainly that the same expression might be represented differently, e.g. in different size. As a simple example, consider the expression 
  263.  where the two instances of the symbol x are printed in different size, though they might be represented by a single node of the expression DAG. Further, the visualization component has been designed to handle even very large expressions as are frequently generated by computer algebra tools. Therefore, from a certain depth of structural hierarchy on subexpressions are visualized by three dots only. Again, this may cause the same subexpression occuring twice in an expression graph to be displayed differently.
  264. To be able to deal with these requirements - for the model a DAG structure is preferred, while the viewing component needs a tree structure - an intermediate structure is introduced. It consists of a tree of boxes. In each box object the size of an expression and the position within its environmental expression is stored. For box objects a draw method is defined which can be used to actually display the respective expression. Drawing an expression thus means to call its method for production of the intermediate structure, i.e. a tree of boxes, and then calling the draw methods of these boxes.
  265. The intermediate tree structure has a further application: It can be used to identify a point on the two_dimensional drawing plane with an expression. This is achieved by traversing the tree structure until the smallest box containing the point in question is reached. This is used to implement the selection mechanism for subexpressions in a generic way.
  266. Figure 2 gives an overview over the classes involved in the kernel of the expression framework.
  267. Figure 2: Classes of the expression framework's kernel (white: abstract classes; grey: concrete classes)
  268. The Icon Component
  269. The icon component establishes the link between the expression framework introduced so far, and the text framework. From the text framework's view, the icon component is simply an extension which can exist in parallel with other extensions and can cooperate with all kinds of tools designed for the text model (e.g. specialized editors or AsciiCoder).
  270. From the perspective of the expression framework it is a specialized concrete view component. As such, it could be replaced e.g. by a separate individual expression editor, without affecting the rest of the framework. In fact, several such components could exist in parallel. As a concrete view component, the icon component implements concrete graphic ports, and the subselection feature. (See figure 3.)
  271. Figure 3: The individual components and their tasks
  272. As an implementation detail, it should be noted that the converter between text and internally represented expressions, i.e. the expression parser, is implemented in a separate module. This makes the icon component independent from the concrete syntax and semantics of the expression language in use. Also, the expression classes necessary to represent objects read by the parser need not to be known by the icon component. This leads to a clean separation between the general editing issues implemented in the framework and the expression class library. To abstract from text converters, the icon component defines an abstract class Converter. Figure 4 presents the complete set of classes involved in the resulting nested framework. Figure 5 shows the modules involved.
  273. Figure 4: Classes of the Nested Framework (white: abstract classes; grey: concrete classes)
  274. Figure 5: Simplified module import graph (extension and client modules marked grey)
  275. Selections
  276. To allow clients of the framework to abstract from the representation of a parameter expression (text, single icon, mixture of both, or subselection) module ExprViews also implements a special mechanism to retrieve the least recent selected expression and to update it in place after some operation. The following simple version of the collapse command serves as an example for the usage of the selection objects:
  277.     PROCEDURE Collapse*;
  278.         VAR sel: ExprViews.Selection;
  279.     BEGIN
  280.         sel := ExprViews.LatestSelection();    (* get least recent selection (no matter whether text or subselection *)
  281.         IF (sel # NIL) & ~sel.promise THEN    (* selection exists and selected expression might be changed *)
  282.             ExprStd.DoSubstitutions(sel.exp);    (* do all registered standard substitutions *)
  283.             sel.notify(sel, sel)    (* update selection to new value *)
  284.         END
  285.     END Collapse;
  286. For a more detailed discussion of the concept of icons within text in general you may want to take a look at:
  287. W. Weck: Putting Icons into (Con_) Text,
  288. Proceedings of the Thirteenth International Conference on Technology of Object_Oriented Languages and Systems,
  289. TOOLS EUROPE '94, Versailles, France, Prentice Hall, 1994.
  290.