5
A. TRANSLATABLE VAXIMA STATEMENTS & EXPRESSIONS
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
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.
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.
21
A.1. Formal Definition
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.
28
Note: Terminals are \fIunderlined\fR.
30
\fIeps\fR represents the empty string.
35
Preliminary Definitions
37
\fIid\fR - an identifier (i.e., atom).
39
\fIstring\fR - any number of characters (excluding double quotes)
41
enclosed in double quotes.
45
Arithmetic Expressions:
48
exp ::= \fInumber\fR | var | funcall | \fIabs( \fRexp ) |
50
- exp | exp + exp | exp - exp |
52
exp * exp | exp / exp | exp ** exp |
56
exp' ::= , exp exp' | \fIeps\fR
58
exp'' ::= exp exp' | \fIeps\fR
60
var ::= \fIid\fR | \fIid [ \fRexp exp' ]
62
funcall ::= \fIid( \fRarg' )
64
arg ::= exp | logexp | \fIstring\fR
66
arg' ::= arg arg' | \fIeps\fR
68
arg0 ::= arg | \fIeps\fR
70
string0 ::= \fIstring\fR | \fIeps\fR
72
id' ::= \fIid\fR id'' | \fIeps\fR
74
id'' ::= , \fIid\fR id'' | \fIeps\fR
80
logexp ::= \fItrue\fR | \fIfalse\fR | var | funcall |
82
exp > exp | exp >= exp | exp = exp |
84
exp # exp | exp < exp | exp <= exp |
86
\fInot\fR logexp | logexp \fIand\fR logexp |
88
logexp \fIor\fR logexp | ( logexp )
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.
98
For example, in VAXIMA,
100
not a = b and not (a = b)
102
are equivalent, whereas in C,
104
! a == b and (!a) == b
106
are equivalent. Therefore,
110
is translated into C code which forces the VAXIMA precedence rules:
118
stmt ::= assign | loop | cond | go | call |
120
return | iostmt | stmtgp
122
stmt' ::= , stmt stmt' | \fIeps\fR
124
assign ::= var : exp |
125
\fIid : matrix( \fRrow row' )
129
row' ::= , row row' | \fIeps\fR
131
loop ::= \fIfor\fR var initval nextexp thruexp loopcond \fIdo\fR
135
initvar ::= : exp | \fIeps\fR
137
nextexp ::= \fIstep\fR exp | \fInext\fR exp | \fIeps\fR
139
thruexp ::= \fIthru\fR exp | \fIeps\fR
141
loopcond ::= \fIwhile\fR logexp | \fIunless\fR logexp | \fIeps\fR
143
cond ::= \fIif\fR logexp \fIthen\fR stmt elsestmt
145
elsestmt ::= \fIelse\fR stmt | \fIeps\fR
147
go ::= \fIgo( \fRid )
149
call ::= \fIid( \fRexp'' )
151
return ::= \fIreturn( \fRarg0 )
153
iostmt[10] ::= var : \fBreadonly( \fRstring0 ) |
155
\fIprint( \fRarg arg' )
157
[10] I/O statements cannot be translated into C code.
160
stmtgp ::= ( stmt stmt' )[11] |
162
\fIblock( \fRstmt stmt' )[12]
164
[11] VAXIMA compound statements are translated into (undelimited) statement
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.
178
subprog ::= \fIid( \fRid' ) := body ;
180
body ::= stmt | exp | logexp
187
Preliminary Definitions
189
\fIid \fR- an identifier (i.e., atom whose first character is
193
\fIstring\fR - an atom whose first character is &.
197
Arithmetic Expressions:
200
exp ::= \fInumber\fR | var | funcall |
202
\fI((mabs) \fRexp) | \fI((mminus) \fRexp) |
204
\fI((mplus) \fRexp exp') | \fI((mtimes) \fRexp exp') |
206
\fI((mquotient) \fRexp exp) | \fI((mexpt) \fRexp exp)
208
exp' ::= exp exp' | \fIeps\fR
210
var ::= \fIid\fR | \fI((id) \fRexp exp')
212
funcall ::= \fI((id) \fRarg')
214
arg ::= exp | logexp | \fIstring\fR
216
arg' ::= arg arg' | \fIeps\fR
218
arg0 ::= arg | \fIeps\fR
220
string0 ::= \fIstring\fR | \fIeps\fR
222
id' ::= \fIid \fRid' | \fIeps\fR
228
logexp ::= \fIt\fR | \fInil\fR | var | funcall |
230
\fI((mgreaterp) \fRexp exp) |
232
\fI((mgeqp) \fRexp exp) |
234
\fI((mequal) \fRexp exp) |
236
\fI((mnotequal)\fR exp exp) |
238
\fI((mlessp) \fRexp exp) |
240
\fI((mleqp) \fRexp exp) | \fI((mnot) \fRlogexp) |
242
\fI((mand) \fRlogexp logexp logexp') |
244
\fI((mor) \fRlogexp logexp logexp')
246
logexp' ::= logexp logexp' | \fIeps\fR
252
stmt ::= assign | loop | condR | go | call |
254
return | iostmt | stmtgp
256
stmt' ::= stmt stmt' | \fIeps\fR
258
assign ::= \fI((msetq) \fRvar exp) |
260
\fI((msetq) id (($matrix) \fRrow row'))
262
row ::= \fI((mlist) \fRexp exp')
264
row' ::= row row' | \fIeps\fR
266
loop ::= \fI((mdo) \fRvar initexp stepexp nextexp thruexp
270
initexp ::= exp | \fInil\fR
272
stepexp ::= exp | \fInil\fR
274
nextexp ::= exp | \fInil\fR
276
thruexp ::= exp | \fInil\fR
278
loopcond ::= logexp | \fInil\fR
280
cond ::= \fI((mcond) \fRlogexp stmt \fIt\fR elsestmt)
282
elsestmt ::= stmt | \fI$false\fR
284
go ::= \fI((mgo) id)\fR
286
call ::= \fI((id) \fRexp')
288
return ::= \fI((mreturn) \fRarg0)
290
iostmt[13] ::= \fI((msetq) \fRvar \fI(($readonly) \fRstring0)) |
293
[13] I/O statements cannot be translated into C code.
295
\fI(($print) \fRarg arg')
297
stmtgp ::= \fI((mprogn) \fRstmt stmt')[14] |
299
\fI((mprog) \fRstmt stmt')[15]
301
[14] VAXIMA compound statements are translated into (undelimited) statement
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.
315
subprog ::= \fI((mdefine) ((id) \fRid') body)
317
body ::= stmt | exp | logexp
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.