~ubuntu-branches/ubuntu/karmic/maxima/karmic

« back to all changes in this revision

Viewing changes to share/contrib/gentran/man/appA1.ms

  • Committer: Bazaar Package Importer
  • Author(s): Camm Maguire
  • Date: 2004-11-13 18:39:14 UTC
  • mto: (2.1.2 hoary) (3.2.1 sid) (1.1.5 upstream)
  • mto: This revision was merged to the branch mainline in revision 3.
  • Revision ID: james.westby@ubuntu.com-20041113183914-ttig0evwuatnqosl
Tags: upstream-5.9.1
ImportĀ upstreamĀ versionĀ 5.9.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
.nr LL 6.5i
 
2
.nr FL 6.0i
 
3
.ND
 
4
.SH
 
5
A.  TRANSLATABLE VAXIMA STATEMENTS & EXPRESSIONS
 
6
.LP
 
7
A substantial subset of all VAXIMA statements and expressions can be
 
8
translated by GENTRAN into semantically equivalent code in the target
 
9
numerical language[9].  This
 
10
.FS
 
11
[9] It should be noted that call-by-value parameter passing is used in
 
12
VAXIMA, while call-by-address parameter passing is normally used in
 
13
FORTRAN and RATFOR.  GENTRAN does not attempt to simulate call-by-value
 
14
passing when generating code.
 
15
.FE
 
16
appendix is divided into two sections.  The first section contains a
 
17
formal definition of all translatable VAXIMA statements and expressions.  The
 
18
second section contains examples of several statement types
 
19
translated into FORTRAN, RATFOR and C code.
 
20
.SH
 
21
A.1.  Formal Definition
 
22
.LP
 
23
This section contains a formal definition of all VAXIMA statements and
 
24
expressions that can be translated by GENTRAN into numerical
 
25
code.  First the VAXIMA user level syntax is given, and then the
 
26
LISP level syntax is given.
 
27
.LP
 
28
Note:  Terminals are \fIunderlined\fR.
 
29
.LP
 
30
       \fIeps\fR  represents the empty string.
 
31
.SH
 
32
User Level
 
33
.RS
 
34
.SH
 
35
Preliminary Definitions
 
36
.LP
 
37
\fIid\fR     - an identifier (i.e., atom).
 
38
.br
 
39
\fIstring\fR - any number of characters (excluding double quotes)
 
40
.br
 
41
         enclosed in double quotes.
 
42
.SH
 
43
Expressions
 
44
.LP
 
45
Arithmetic Expressions:
 
46
.RS
 
47
.LP
 
48
exp  ::=  \fInumber\fR  |  var  |  funcall |  \fIabs( \fRexp )  |
 
49
.br
 
50
          - exp  |  exp + exp  |  exp - exp  |
 
51
.br
 
52
          exp * exp  |  exp / exp  |  exp ** exp  |
 
53
.br
 
54
          exp ^ exp  |  ( exp )
 
55
.LP
 
56
exp'  ::=  , exp exp'  |  \fIeps\fR
 
57
.LP
 
58
exp''  ::=  exp exp'  |  \fIeps\fR
 
59
.LP
 
60
var  ::=  \fIid\fR  |  \fIid [ \fRexp exp' ]
 
61
.LP
 
62
funcall  ::=  \fIid( \fRarg' )
 
63
.LP
 
64
arg  ::=  exp  |  logexp  |  \fIstring\fR
 
65
.LP
 
66
arg'  ::=  arg arg'  |  \fIeps\fR
 
67
.LP
 
68
arg0  ::=  arg  |  \fIeps\fR
 
69
.LP
 
70
string0  ::=  \fIstring\fR  |  \fIeps\fR
 
71
.LP
 
72
id'  ::=  \fIid\fR id''  |  \fIeps\fR
 
73
.LP
 
74
id''  ::=  , \fIid\fR id''  |  \fIeps\fR
 
75
.RE
 
76
.LP
 
77
Logical Expressions:
 
78
.RS
 
79
.LP
 
80
logexp  ::=  \fItrue\fR  |  \fIfalse\fR  |  var  |  funcall  |
 
81
.br
 
82
             exp > exp  |  exp >= exp  |  exp = exp  |
 
83
.br
 
84
             exp # exp  |  exp < exp  |  exp <= exp  |
 
85
.br
 
86
             \fInot\fR logexp  |  logexp \fIand\fR logexp  |
 
87
.br
 
88
             logexp \fIor\fR logexp  |  ( logexp )
 
89
.RE
 
90
.SH
 
91
Operator Precedence
 
92
.LP
 
93
Parentheses are automatically generated when expressions are
 
94
translated which contain operators whose precedence in VAXIMA
 
95
differs from that in the target language.  Thus the meaning of
 
96
the original expression is preserved.
 
97
.LP
 
98
For example, in VAXIMA,
 
99
.DS L
 
100
    not a = b    and    not (a = b)
 
101
.DE
 
102
are equivalent, whereas in C,
 
103
.DS L
 
104
    ! a == b     and    (!a) == b
 
105
.DE
 
106
are equivalent.  Therefore,
 
107
.DS L
 
108
    not a = b
 
109
.DE
 
110
is translated into C code which forces the VAXIMA precedence rules:
 
111
.DS L
 
112
    !(a == b)
 
113
.DE
 
114
.SH
 
115
Statements
 
116
.RS
 
117
.LP
 
118
stmt  ::=  assign  |  loop  |  cond  |  go  |  call  |
 
119
.br
 
120
            return  |  iostmt  |  stmtgp
 
121
.LP
 
122
stmt'  ::=  , stmt stmt'  |  \fIeps\fR
 
123
.LP
 
124
assign  ::=  var : exp  |
 
125
\fIid : matrix( \fRrow row' )
 
126
.LP
 
127
row  ::=  [ exp exp' ]
 
128
.LP
 
129
row'  ::=  , row row'  |  \fIeps\fR
 
130
.LP
 
131
loop  ::=  \fIfor\fR var initval nextexp thruexp loopcond \fIdo\fR
 
132
.br
 
133
           stmt
 
134
.LP
 
135
initvar  ::=  : exp  |  \fIeps\fR
 
136
.LP
 
137
nextexp  ::=  \fIstep\fR exp  |  \fInext\fR exp  |  \fIeps\fR
 
138
.LP
 
139
thruexp  ::=  \fIthru\fR exp  |  \fIeps\fR
 
140
.LP
 
141
loopcond  ::=  \fIwhile\fR logexp  |  \fIunless\fR logexp  |  \fIeps\fR
 
142
.LP
 
143
cond  ::=  \fIif\fR logexp \fIthen\fR stmt elsestmt
 
144
.LP
 
145
elsestmt  ::=  \fIelse\fR stmt  |  \fIeps\fR
 
146
.LP
 
147
go  ::=  \fIgo( \fRid )
 
148
.LP
 
149
call  ::=  \fIid( \fRexp'' )
 
150
.LP
 
151
return  ::=  \fIreturn( \fRarg0 )
 
152
.LP
 
153
iostmt[10]  ::=  var : \fBreadonly( \fRstring0 )  |
 
154
.br
 
155
                 \fIprint( \fRarg arg' )
 
156
.FS
 
157
[10] I/O statements cannot be translated into C code.
 
158
.FE
 
159
.LP
 
160
stmtgp  ::=  ( stmt stmt' )[11]  |
 
161
.br
 
162
             \fIblock( \fRstmt stmt' )[12]
 
163
.FS
 
164
[11] VAXIMA compound statements are translated into (undelimited) statement
 
165
\fIsequences\fR.
 
166
.FE
 
167
.FS
 
168
[12] VAXIMA statement blocks are translated into statement \fIgroups\fR
 
169
(delimited by { and }) when RATFOR or C code is being generated.  However,
 
170
they are translated into (undelimited) statement \fIsequences\fR when the
 
171
target language is FORTRAN.
 
172
.FE
 
173
.RE
 
174
.SH
 
175
Subprograms
 
176
.RS
 
177
.LP
 
178
subprog  ::=  \fIid( \fRid' ) := body ;
 
179
.LP
 
180
body  ::=  stmt  |  exp  |  logexp
 
181
.RE
 
182
.RE
 
183
.SH
 
184
LISP Level
 
185
.RS
 
186
.SH
 
187
Preliminary Definitions
 
188
.LP
 
189
\fIid     \fR- an identifier (i.e., atom whose first character is
 
190
.br
 
191
         not &).
 
192
.br
 
193
\fIstring\fR - an atom whose first character is &.
 
194
.SH
 
195
Expressions
 
196
.LP
 
197
Arithmetic Expressions:
 
198
.RS
 
199
.LP
 
200
exp  ::=  \fInumber\fR  |  var  |  funcall  |
 
201
.br
 
202
          \fI((mabs) \fRexp)  |  \fI((mminus) \fRexp)  |
 
203
.br
 
204
          \fI((mplus) \fRexp exp')  |  \fI((mtimes) \fRexp exp')  |
 
205
.br
 
206
          \fI((mquotient) \fRexp exp)  |  \fI((mexpt) \fRexp exp)
 
207
.LP
 
208
exp'  ::=  exp exp'  |  \fIeps\fR
 
209
.LP
 
210
var  ::=  \fIid\fR  |  \fI((id) \fRexp exp')
 
211
.LP
 
212
funcall  ::=  \fI((id) \fRarg')
 
213
.LP
 
214
arg  ::=  exp  |  logexp  |  \fIstring\fR
 
215
.LP
 
216
arg'  ::=  arg arg'  |  \fIeps\fR
 
217
.LP
 
218
arg0  ::=  arg  |  \fIeps\fR
 
219
.LP
 
220
string0  ::=  \fIstring\fR  |  \fIeps\fR
 
221
.LP
 
222
id'  ::=  \fIid \fRid'  |  \fIeps\fR
 
223
.RE
 
224
.LP
 
225
Logical Expressions:
 
226
.RS
 
227
.LP
 
228
logexp  ::=  \fIt\fR  |  \fInil\fR  |  var  |  funcall  |
 
229
.br
 
230
             \fI((mgreaterp) \fRexp exp)  |
 
231
.br
 
232
             \fI((mgeqp) \fRexp exp)  |
 
233
.br
 
234
             \fI((mequal) \fRexp exp)  |
 
235
.br
 
236
             \fI((mnotequal)\fR exp exp)  |
 
237
.br
 
238
             \fI((mlessp) \fRexp exp)  |
 
239
.br
 
240
             \fI((mleqp) \fRexp exp)  |  \fI((mnot) \fRlogexp)  |
 
241
.br
 
242
             \fI((mand) \fRlogexp logexp logexp')  |
 
243
.br
 
244
             \fI((mor) \fRlogexp logexp logexp')
 
245
.LP
 
246
logexp'  ::=  logexp logexp'  |  \fIeps\fR
 
247
.RE
 
248
.SH
 
249
Statements
 
250
.RS
 
251
.LP
 
252
stmt  ::=  assign |  loop  |  condR  |  go  |  call  |
 
253
.br
 
254
           return  |  iostmt  |  stmtgp
 
255
.LP
 
256
stmt'  ::=  stmt stmt'  |  \fIeps\fR
 
257
.LP
 
258
assign  ::=  \fI((msetq) \fRvar exp)  |
 
259
.br
 
260
             \fI((msetq) id (($matrix) \fRrow row'))
 
261
.LP
 
262
row  ::=  \fI((mlist) \fRexp exp')
 
263
.LP
 
264
row'  ::=  row row'  |  \fIeps\fR
 
265
.LP
 
266
loop  ::=  \fI((mdo) \fRvar initexp stepexp nextexp thruexp
 
267
.br
 
268
           loopcond stmt)
 
269
.LP
 
270
initexp  ::=  exp  |  \fInil\fR
 
271
.LP
 
272
stepexp  ::=  exp  |  \fInil\fR
 
273
.LP
 
274
nextexp  ::=  exp  |  \fInil\fR
 
275
.LP
 
276
thruexp  ::=  exp  |  \fInil\fR
 
277
.LP
 
278
loopcond  ::=  logexp  |  \fInil\fR
 
279
.LP
 
280
cond  ::=  \fI((mcond) \fRlogexp stmt \fIt\fR elsestmt)
 
281
.LP
 
282
elsestmt  ::=  stmt  |  \fI$false\fR
 
283
.LP
 
284
go  ::=  \fI((mgo) id)\fR
 
285
.LP
 
286
call  ::=  \fI((id) \fRexp')
 
287
.LP
 
288
return  ::=  \fI((mreturn) \fRarg0)
 
289
.LP
 
290
iostmt[13]  ::=  \fI((msetq) \fRvar \fI(($readonly) \fRstring0))  |
 
291
.br
 
292
.FS
 
293
[13] I/O statements cannot be translated into C code.
 
294
.FE
 
295
                 \fI(($print) \fRarg arg')
 
296
.LP
 
297
stmtgp  ::=  \fI((mprogn) \fRstmt stmt')[14]  |
 
298
.br
 
299
              \fI((mprog) \fRstmt stmt')[15]
 
300
.FS
 
301
[14] VAXIMA compound statements are translated into (undelimited) statement
 
302
\fIsequences\fR.
 
303
.FE
 
304
.FS
 
305
[15] VAXIMA statement blocks are translated into statement groups (delimited
 
306
by { and }) when RATFOR or C code is being generated.  However, they are
 
307
translated into (undelimited) statement \fIsequences\fR when the
 
308
target language is FORTRAN.
 
309
.FE
 
310
.RE
 
311
.SH
 
312
Subprograms
 
313
.RS
 
314
.LP
 
315
subprog  ::=  \fI((mdefine) ((id) \fRid') body)
 
316
.LP
 
317
body  ::=  stmt  |  exp  |  logexp
 
318
.RE
 
319
.RE
 
320
.SH
 
321
A.2.  Examples
 
322
.LP
 
323
The following table contains a list of VAXIMA statement types
 
324
that can be translated by GENTRAN.  Examples of each statement
 
325
type, along with equivalent FORTRAN, RATFOR and C code, are given.
 
326
.bp
 
327
 .
 
328
.bp
 
329
 .