Research V7 development
[unix-history] / usr / doc / eqn / e3
CommitLineData
220e3522
BK
1.NH
2Language Design
3.PP
4The fundamental principle upon which we based our language design
5is that the language should be easy to use
6by people (for example, secretaries) who know neither mathematics nor typesetting.
7.PP
8This principle implies
9several things.
10First,
11``normal'' mathematical conventions about operator precedence,
12parentheses, and the like cannot be used,
13for to give special meaning to such characters means
14that the user has to understand what he or she
15is typing.
16Thus the language should not assume, for instance,
17that parentheses are always balanced,
18for they are not in
19the half-open interval $(a,b]$.
20Nor should it assume that
21that $sqrt{a+b}$ can be replaced by
22$(a+b) sup roman \(12$,
23or that $1/(1-x)$ is better written as $1 over 1-x$
24(or
25vice versa).
26.PP
27Second, there should be relatively few rules,
28keywords,
29special symbols and operators, and the like.
30This keeps the language easy to learn and remember. Furthermore, there should be few exceptions to
31the rules that do exist:
32if something works in one situation,
33it should work everywhere.
34If a variable can have a subscript,
35then a subscript can have a subscript, and so on without limit.
36.PP
37Third, ``standard'' things should happen automatically.
38Someone who types ``x=y+z+1'' should get ``$x=y+z+1$''.
39Subscripts and superscripts should automatically
40be printed in an appropriately smaller size,
41with no special intervention.
42Fraction bars have to be made the right length and positioned at the
43right height.
44And so on.
45Indeed a mechanism for overriding default actions has to exist,
46but its application is the exception, not the rule.
47.PP
48We assume
49that the typist has a reasonable picture
50(a two-dimensional representation)
51of the desired final form, as might be handwritten
52by the author of a paper.
53We also assume that
54the input is typed on a computer terminal much like an ordinary typewriter.
55This implies an input alphabet
56of perhaps 100 characters,
57none of them special.
58.PP
59A secondary, but still important, goal in our design
60was that the system should be easy to implement,
61since neither of the authors had any desire to make
62a long-term project of it.
63Since our design was not firm,
64it was also necessary that the program be easy to change
65at any time.
66.PP
67To make the program easy to build and to change,
68and to guarantee regularity
69(``it should work everywhere''),
70the language is defined by a
71context-free grammar, described in Section 5.
72The compiler for the language was built using a compiler-compiler.
73.PP
74A priori,
75the grammar/compiler-compiler approach seemed the right thing to do.
76Our subsequent experience leads us to believe
77that any other course would have been folly.
78The original language was designed in a few days.
79Construction of a working system
80sufficient to try significant examples
81required perhaps a person-month.
82Since then, we have spent a modest amount of additional time
83over several years
84tuning, adding facilities,
85and occasionally changing the language as users
86make criticisms and suggestions.
87.PP
88We also decided quite early that
89we would let
90.UC TROFF
91do our work for us whenever possible.
92.UC TROFF
93is quite a powerful program, with
94a macro facility, text and arithmetic variables, numerical computation and testing,
95and conditional branching.
96Thus we have been able to avoid writing
97a lot of mundane but tricky software.
98For example, we store no text strings,
99but simply pass them on to
100.UC TROFF .
101Thus we avoid having to write a storage management package.
102Furthermore, we have been able to isolate ourselves
103from most details of the particular device and character set
104currently in use.
105For example, we let
106.UC TROFF
107compute the widths of all strings of characters;
108we need know nothing about them.
109.PP
110A third design goal is special to our environment.
111Since our program is only useful for typesetting mathematics,
112it is necessary that it interface cleanly with the underlying typesetting language
113for the benefit of users
114who want to set intermingled mathematics and text
115(the usual case).
116The standard mode of operation
117is that when a document is typed,
118mathematical expressions are input as part of the text,
119but marked by user settable delimiters.
120The program reads this input and treats as comments
121those things which are not mathematics,
122simply passing them through untouched.
123At the same time it converts the mathematical input
124into the necessary
125.UC TROFF
126commands.
127The resulting ioutput is passed directly to
128.UC TROFF
129where the comments and the mathematical parts both become
130text and/or
131.UC TROFF
132commands.