Useful as background to MORTRAN3 which we use.
- SLAC COMPUTATION GROUP CGTM No. 206
Stanford, California August 1981
- Using Mortran2 on VM
- Roger B. Chaffee
Computation Research Group
Stanford Linear Accelerator Center
- This is a Working Paper
Do not quote, cite, abstract,
or reproduce without prior
permission of the author.
- Chapter 1
+ Chapter 1
0 MORTRAN 2.79
+ MORTRAN 2.79
- I have adapted the Mortran processor to my own needs.
This note describes my version, which is running on SLAC's
VM system, and has been sent out with Top Drawer. Most of
the code is the same as Jim Cook's Mortran, and much of this
note has been copied from Jim's technical memos.
0 The primary guide to using Mortran is A User's Guide to
+ _ ______ _____ __
MORTRAN2, by Jim Cook and Len Shustek, CGTM No. 165. Read
that one first.
- 1.1 MORTRAN SYNTAX
+ 1.1 MORTRAN SYNTAX
+ _______ ______
0 With a few exceptions involving strings, any Fortran
statement, followed by a semicolon, is sent to the output
file. No checking is done by the Mortran processor that the
statements are in fact legal Fortran.
1. Strings within apostrophes (e.g. 'string') are turned
into Hollerith form.
2. Multiple blanks in the input, not within apostrophes,
are turned into a single blank. This includes blanks
+ ____ ________ ______
within a Hollerith string.
+ ______ _ _________ ______
0 The above statements about the Mortran processor result
in the following general rules about writing Mortran code:
0 1. Statements are free-form, terminated by a semicolon
(;). Card boundaries are irrelevant.
2. Comments are enclosed in quotation marks ("comment")
and may appear anywhere.
3. Character strings are enclosed in apostrophes
4. Alphanumeric statements labels are enclosed in colons
(:label:) and may appear anywhere a Fortran statement
label is legal.
- 1 -
1.2 MORTRAN STATEMENTS
+ 1.2 MORTRAN STATEMENTS
+ _______ __________
0 In the following, "stmts;" means zero or more Fortran
statements, each followed by a semicolon, and "loop" means
WHILE-loop, UNTIL-loop, BLOCK, LOOP, FOR-loop or DO-loop.
0 1.2.1 Conditionals
+ 1.2.1 Conditionals
0 IF (lexpr) stmt; (This, of course, is Fortran.)
IF lexpr ELSE
IF lexpr ELSEIF lexpr ELSE
0 1.2.2 Loops
+ 1.2.2 Loops
0 WHILE lexpr < stmts; >
UNTIL lexpr < stmts; >
BLOCK < stmts; >
LOOP < stmts; >
LOOP < stmts; > UNTIL lexpr;
LOOP < stmts; > WHILE lexpr;
LOOP < stmts; > REPEAT;
FOR v=e BY e TO e < stmts; >
FOR v=e TO e BY e < stmts; >
FOR v=e TO e < stmts; >
DO v=e,e,e < stmts; > (Fortran DO-loop.)
DO v=e,e,e < stmts; > FALL THRU
These loops may all be nested. E.g.
IF I.NE.J <
OUTPUT I,M(J+1); (' Chain',I4,' ends with ',A4);
- Within one of these loops, the statement EXIT; means
"branch to the statement following the end of the loop".
The statement NEXT; means "start at the beginning of the
loop". (For DO-loops and FOR-loops, the counter is incre-
0 LOOP < INPUT X; (F10.0); IF X.EQ.0.0 EXIT; SUM=SUM+X;>
0 - 2 -
- A loop may be labeled. A NEXT or EXIT statement may
refer to the loop at any nesting level above it by using
the label. E.g.
0 :FIND BLANK:
INPUT CARD; (80A1);
Note that there must not be a semicolon between the label
and the following keyword. (This would cause a labelled
'continue' statement, but would not associate the label with
1.2.3 Local Subroutines
+ 1.2.3 Local Subroutines
+ _____ ___________
0 Within a Fortran subroutine, local procedures can be
defined with the following syntax:
0 :procname: PROCEDURE < stmts; >
- A procedure can be invoked by the statement
0 EXECUTE :procname:;
- Within the body of the procedure, the statement EXIT
:procname:; effects a 'return' to the statement following
the EXECUTE statement, as does the final '>'.
0 Returns from local procedures are implemented with an
ASSIGN statement and an assigned GOTO, which are legal but
unusual constructs. The 'call' is done with a GOTO, which
is always legal in Fortran IV. However, the new Fortran 77
explicitly prohibits branching out of the range of a DO-loop
and then returning, so this construct will produce illegal
code if an EXECUTE statement inside a DO-loop calls a
PROCEDURE outside it.
- 3 -
+ 1.2.4 Abbreviations
0 18.104.22.168 Multiple Assignment
+ 22.214.171.124 Multiple Assignment
0 /v1,v2,...,vn/ = e;
126.96.36.199 INPUT and OUTPUT Statements
+ 188.8.131.52 INPUT and OUTPUT Statements
0 OUTPUT; (fmtlist);
OUTPUT varlist; (fmtlist);
INPUT varlist; (fmtlist);
0 Resulting Fortran:
0 WRITE (6,20)
20 FORMAT (fmtlist)
0 WRITE (6,30) varlist
30 FORMAT (fmtlist)
0 READ (5,40) varlist
40 FORMAT (fmtlist)
1.3 QUOTED STRINGS
+ 1.3 QUOTED STRINGS
+ ______ _______
0 %Vn in columns 1 to 3 controls the treatment of quoted
0 %V0 is the default setting, which causes strings within
apostrophes to be converted to equivalent Hollerith values.
A double apostrophe, i.e. a null string, is changed to a
0 %V1 causes strings within apostrophes to be passed along
unchanged. In this case, there is no way to produce an
unpaired apostrophe in the output.
0 - 4 -
+ 1.4 COMMENTS
0 %K in columns 1 and 2 of a card causes that entire card to
be copied as a comment card in the Fortran output.
- %Ynn starting in column 1 causes Mortran comments, enclosed
in quotes in the input, to appear in comment cards in the
output. The comment text will start in column nn+1 of the
card, where nn is a 1- or 2-digit unsigned decimal integer.
nn=0 or blank inhibits this feature. No more than one com-
ment card will be produced between normal output lines, so
large blocks of comments will not be passed.
- The internal operator @NN performs the same function for the
Fortran output that the @NM operator performs for the list-
ing, that is, the first actual parameter in the macro being
expanded is written to the file in question. (In CGTM No.
185 and No. 167, the @NM operator is incorrectly given as
@MM. The original intent may have been to use @MM, but all
implementations I have seen have used @NM, as does my ver-
1.5 CONDITIONAL GENERATION OF CODE
+ 1.5 CONDITIONAL GENERATION OF CODE
+ ___________ __________ __ ____
0 In addition to the usual GENERATE and NOGENERATE control
words, I have added an ELSEGENERATE. For example,
GENERATE; A=B; ELSEGENERATE; C=D; ENDGENERATE;
produces the code line A=B, but
NOGENERATE; A=B; ELSEGENERATE; C=D; ENDGENERATE;
produces C=D. All GENERATE controls can be nested in the
- - 5 -
+ 1.6 LISTING
0 There are three levels of listing possible. Level 0
gives no listing at all. Level 1 lists only the %E lines,
which are normally page ejects and can be used for comments.
Level 2 is the full listing. %Ln or %Nn in columns 1
through 3 sets the listing level to n. %L is the same as
%L2, and %N is the same as %L1.
1.7 MORTRAN KEYWORDS
+ 1.7 MORTRAN KEYWORDS
+ _______ ________
0 Mortran programs may be written using either 'reserved-word'
or 'bracketed' keywords. A program using reserved-word key-
words might look like this:
FOR I=1 TO 8
instead of LOOP,
instead of DO, etc.
0 The specification of macros depends on the particular
system. Each macro set is in a different input file, and
one or the other must be read in by the processor at execu-
tion time. Since Mortran is invoked in different ways on
different systems, I can't tell you here how to use it on
- - 6 -
1.8 LINE NUMBERS
+ 1.8 LINE NUMBERS
+ ____ _______
0 Identification can be added in columns 73-80 of the Fortran
output. Mortran tries to be clever about what it uses:
0 1) If the input is Wylbur EDIT format, then the Wylbur line
number is used.
0 2) If the first line of the input file is not blank in col-
umns 73-80, then the contents of columns 73-80 is used
for the entire file.
0 3) Otherwise, the sequence number of the line in the file is
0 %J0 in columns 1-3 of a card disables this feature and
leaves column 73-80 blank in the Fortran output.
%J1 in columns 1-3 enables it. This is the default.
0 Because of the way Mortran reads input cards, the con-
tents of columns 73-80 may come from a line which is near,
but not the same as, the line which gives the code in the
rest of the line. The discrepancy is not usually more than
0 The characters '' appearing in the input cause a
pointer to be added to a stack which saves the current state
of the macros. The characters '' pop that stack and
restore the macros to the state that existed when the corre-
sponding command was encountered.
1.10 COMPILE-TIME ARITHMETIC
+ 1.10 COMPILE-TIME ARITHMETIC
+ ____________ __________
0 Mortran has an arithmetic stack, and allows manipulation
of the contents of that stack through commands which can be
imbedded in the input code. This feature is somewhat eso-
teric, but can be useful for writing simple macros, e.g. for
funny dimension statements.
0 nnnn push the integer nnnn onto the top of the stack.
nnnn is a decimal integer.
- 7 -
pop the number on the top of the stack into the
code stream. (It is in the same format as other
Mortran-generated numbers, i.e. as the two char-
acters @n, and is not translated to a decimal-
character representation until it is moved to the
0 name; Create a macro pattern 'name', and use the number
on top of the stack as the replacement part.
This number is popped, i.e. removed, from the
stack. Note that the semicolon is required, but
is not part of 'name' and is not put in the out-
put stream. ( differs from in that
macros involving usually pop a new number
off the stack each time they are expanded, and
pops the stack once, when 'name' is defined
as a macro pattern.)
0 <+> perform the indicated operation between the sec-
<-> ond number on the stack and the top of the stack,
<*> pop both those numbers from the stack and push
> the result onto the stack. Division by zero is
not performed, but no other checks are made on
the values used.
0 Duplicate the top of the stack. (The stack
becomes one value longer, and the top two are the
0 The value on top of the stack is removed from the
stack and compared to zero. If the comparison is
satisfied, a macro is generated. If
not, a macro is generated.
0 This is the same as .
0 For n=1,...,9, this swaps the value at the top of
the stack (the zero-th value) with the n-th value
in the stack. For instance, exchanges
the top two values in the stack.
0 %S1 appearing in columns 1-3 is a debugging aid which
will cause the printing of the stack contents each time an
arithmetic stack operation is done.
- 8 -
+ 1.10.1 Example
BUFSIZ GE999; XXXXXX=
BUFSIZ LE999; YYYY=
-15 4 <+> ;
BUFSIZ GE999; XXXXXX=
BUFSIZ LE999; YYYY=
-15 4 <+> ;
0 - 9 -
+ _______ ______
0 Mortran 2.0 (VERSION OF 4/01/79)
0 107 0 %U5
108 0 %'$BUFSIZ'='500'
109 0 $BUFSIZ2>
110 0 DIMENSION X();
111 0 $BUFSIZ999
112 0 <->
113 0 BUFSIZ GE999; XXXXXX=
114 0 BUFSIZ LE999; YYYY=
115 0 -15 4 <+> ;
116 0 %S1
117 0 %'$BUFSIZ'='5000'
118 0 DIMENSION X($BUFSIZ2>);
ARITH STACK 0 5000
ARITH STACK 0 5000 2
ARITH STACK 0 2500
ARITH STACK 0
119 0 $BUFSIZ999
ARITH STACK 0 5000
ARITH STACK 0 5000 999
120 0 <->
ARITH STACK 0 4001
ARITH STACK 0 4001 4001
121 0 BUFSIZ GE999; XXXXXX=
122 0 BUFSIZ LE999; YYYY=
123 0 -15 4 <+> ;
ARITH STACK 0 -15
ARITH STACK 0 -15 4
ARITH STACK 0 -11
ARITH STACK 0
124 0 %%
0 Mortran ERRORS ENCOUNTERED
+ _______ ______
0 C Mortran 2.0 (VERSION OF 4/01/79)
- - 10 -
- Chapter 2
+ Chapter 2
0 USING MACROS
+ USING MACROS
- The only guide to using the full power of the Mortran
processor is C. T. Zahn's A User Manual for the MORTRAN2
+ _ ____ ______ ___ ___ ________
Macro-translator, CGTM No. 167. Zahn's SKOL language,
implemented in Mortran macros, is a demonstration of the
remarkable power of Mortran.
0 Some of the physics groups at SLAC have developed macro
sets for common programming applications, using the standard
macros as a starting point and sample. 'Mortran Macro' is a
difficult language to program in, but the possibility of
extending the language to match a particular application is
to my knowledge unmatched in a Fortran environment. Appen-
dix B, which is mostly copied from Zahn, gives a list of the
@-operators currently available. It should be emphasized
that these operators are processed when they are found in
the replacement part of a macro-rule, when that rule is
found to match a pattern in the code. An '@' in the code
itself has no significance.
2.1 A USEFUL AND INSTRUCTIVE EXAMPLE
+ 2.1 A USEFUL AND INSTRUCTIVE EXAMPLE
+ _ ______ ___ ___________ _______
0 The following example illustrates some of the techniques
and one of the problems of extending the Mortran language.
The problem is to make a macro which will allow parameters
to be defined, as in the Pascal or Fortran-77 PARAMETER
statement. This already exists, of course, in the form
0 which will replace aaaa by bbbb everywhere, but a nicer way
0 PARAMETER aaaa = bbbb ;
0 A first cut at the macro definition was
0 which would replace the statement
0 PARAMETER aaaa = bbbb ;
- - 11 -
by the statement
0 Note that the template in the macro definition is
0 PARAMETERsomething=something else
0 The replacement is given as
0 %''something''=''something else''
0 which becomes
0 %'something'='something else'
0 when it is placed in the input stream. Unfortunately, this
replaced the PARAMETER statement by
0 causing aaaa to be deleted.
0 The error is that the second # in the %'PARAMETER...
statement is matched by anything, including the null string.
In order to specify the strings which will match, a delim-
iter is needed to show the END of the string. The correct
macro (meta-macro?) definition is
0 The additional semicolon requires that the second # match
the entire string between the '=' and the ';', which is the
- 12 -
- Chapter 3
+ Chapter 3
0 USING MORTRAN ON SLAC VM
+ USING MORTRAN ON SLAC VM
- Mortran is on the system U-disk, and is available through
the Mortran command:
0 MORTRAN [fn|fn ft|fn ft fm] [( [RES|BRK] [ONTO filemode] ]
0 The default filetype is MORTRAN, MORTRANB, or MORTRANR (in
The default filemode is *, i.e. all disks are searched.
- This command will use the given file for input, and will
write two output files, one with filetype FORTRAN, which is
the Fortran output, and one with filetype MORTLIST, which is
the listing for the printer. (To print it, give the command
"PRINT fn MORTLIST fm (CC)", since the carriage control
characters are in it.)
0 3.1 SPECIFYING THE MACRO SET
+ 3.1 SPECIFYING THE MACRO SET
+ __________ ___ _____ ___
0 The choice of macros is one of style. You may specify it in
0 1) An input file which has a filetype of MORTRANR requires
the reserved-word macros. Similarly, MORTRANB requires
0 2) For any other filetype, you may use BRK or RES as a
parameter when you invoke the exec.
E.g. MORTRAN NEW PROGRAM (BRK
0 3) The FIRST line in a file named -name- MORTDEF (where
-name- is the filename of your program) may be either BRK
or RES, which will invoke the corresponding macro set if
it has not been specified by any of the above.
0 4) The FIRST line in a file named PROFILE MORTDEF may be
either BRK or RES, which will invoke the corresponding
macro set if it has not been specified by any of the
0 5) If none of the above, then RES is the default.
0 - 13 -
3.2 OUTPUT FILES
+ 3.2 OUTPUT FILES
+ ______ _____
0 MORTRAN writes three files:
0 Unit OS equivalent Filetype Contents
4 SYSTERM Error messages and %E lines
6 SYSPRINT MORTLIST Full listing.
7 SYSPUNCH FORTRAN Fortran cards.
0 The SYSTERM output is normally written directly to the ter-
minal, so there is no default file name. The other two are
disk files. The filename for both is the program name,
which you use in the MORTRAN statement. The filetypes are
MORTLIST and FORTRAN.
0 The output disk mode can be set in one of four ways.
0 1) Explicitly, by an 'ONTO diskmode' parameter in the
invocation, e.g. MORTRAN XXX (ONTO A5)
0 2) If not set explicitly, the disk mode is set to the same
value as that for the input file.
0 3) If neither of these points to a disk for which you have
write access, then the disk mode is set to 'A1'.
0 4) Finally, a FILEDEF command in your 'PROFILE MORTDEF' or
'name MORTDEF' file overrides any of the above set-
tings, and can be used to set filename, filetype, and
disk for any Mortran input or output file.
0 - 14 -
3.3 FILEDEFS FOR ADDITIONAL INPUT FILES
+ 3.3 FILEDEFS FOR ADDITIONAL INPUT FILES
+ ________ ___ __________ _____ _____
0 When MORTRAN is executed on a file named 'name', first
the default input and output files are FILEDEF'd. Then your
disks are searched for a file named PROFILE MORTDEF, which
could contain additional FILEDEF commands. With a PROFILE
MORTDEF file you can set up FILEDEFs for the files that your
Mortran programs normally require. Finally, the same search
and read is performed using the filename 'name MORTDEF', so
you can set up FILEDEFs which are specific to the particular
'name' you are working with.
0 The MORTDEF files should be in CARD (F 80) format, or some
other format which can be read by the DISKIO program. This
is a consideration only if you create them from WYLBUR.
0 For instance, if you have a set of lines which you want to
include in many places in your program, the following
arrangement will work:
0 The file NAME COMMON A contains lines to be inserted.
The file NAME MORTDEF A contains the line
FILEDEF 22 DISK NAME COMMON A
0 The input, in the file NAME MORTRAN A, contains the lines
where ever the insertion is to occur.
0 Mortran is then invoked by the statement MORTRAN NAME.
(Of course, for inserting up to a few tens of lines, it
would be better to create a macro, such as
%'INSERTION'='lines or statements to be inserted'
In this case, the statement INSERTION; in the source will be
replaced by the lines to be inserted, without the I/O activ-
0 - 15 -
- Appendix A
+ Appendix A
0 CONTROL COMMANDS
+ CONTROL COMMANDS
- For reference, these are the commands for program con-
trol, all of which start with '%' in column 1, and have a
key symbol in column 2. These commands are processed before
they reach the normal input stream, which means that they do
not affect the other input, and also that one cannot create
a macro which produces the same result.
- %An Annotation
n=0: Source not put in Fortran output
1: Source starts in col. 2 of Fortran comment cards
2: Source starts in col. 41 of Fortran comment cards
0 %Cnn Card length. nn from 10 to 200. (More than 80 may not
be possible at your installation.)
0 %Dn Macro Definitions Trace
n=0: Trace Off.
n=1,2,3: Trace On.
0 %E Page Eject.
New page is started. (Entire card is listed.)
0 %F Fortran mode. (See %M.)
Input lines are copied to the output, until a %M.
0 %Inn Indentation.
Lines are listed with indentation of nn*L spaces,
where L is the current nesting level.
0 %Jn Labels in Fortran output
n=0: Columns 73-80 left blank in Fortran output.
n=1: Columns 73-80 get a line id from the source.
0 %K Komment Kopy
The entire card is passed as a comment card to the
0 %Ln Listing control. (See %N.)
n=0: No listing.
1: List only %E lines.
2: Full listing.
blank: same as %L2
- - 16 -
%M Enter Mortran mode. (See %F.)
0 %Nn Disable Listing. (See %L.)
n=0: No listing.
1: List only %E lines.
2: Full listing.
blank: same as %N1
0 %Onn Output Unit.
nn=1,99 sets the Fortran unit for normal listing.
0 %Qn Comment Termination
n=0: Comments must be terminated explicitly.
1: Comments end at the end of line, regardless.
0 %Rnn REWIND Fortran unit nn.
0 %Sn Arithmetic Stack Trace.
n=0: Trace off.
1: Trace on.
2: Internal gut-dumping time.
0 %Tn Macro Recognition Trace
n=0: Trace off.
1: Trace selected macros. (Those containing '@MT')
2: Full trace. (List each pattern matched.)
3: Super trace. (List each attempted match.)
Beware the super trace, my son,
because that might produce in batch
a listing so immense that one
could not perform a fetch.
0 %Unn Unit.
Start reading from Fortran Unit nn.
0 %U filename filetype filemode (SLAC VM version only.)
A command is issued using the KMAND subroutine,
with 'FILEDEF nn DISK' followed by whatever text
is on the %U card. nn=99 for the first such card,
followed by 98, 97, etc., for subsequent cards.
Mortran then starts reading from unit nn.
0 %U file specification (VAX version only.)
Columns 3-27 of the %U card are used in the NAME=
parameter of an OPEN statement. The unit number
is determined as for the VM verson, above.
0 %Vn Hollerith Conversion.
n=0: Quoted strings converted to Hollerith.
1: Quoted strings passed without conversion.
- - 17 -
%Xn Line-end Characters. (See @LE in Appendix B.)
n=0: No line-end character.
n=1: Line-end char in first non-significant column.
n=2: Line-end char in first non-significant column,
semicolon in second.
0 %Ynn Comments in Fortran Output.
n=0: Comments in source are ignored.
n=1,78: Comments in source are passed as comments in
Fortran output, with text starting in column nn.
(No more than one comment card is generated
between Fortran statements.)
0 %Znn Error Message Unit. ('SYSTERM')
nn=1,99 sets the Fortran unit number for error
messages and %E lines. This is useful in an
0 %% End of Input Unit
Reading resumes from previous input unit. (Current
unit is not rewound, and could be continued.)
0 %%R End of Input Unit
Reading resumes from previous input unit. (Current
unit is rewound. On some machines, this will
release buffer space, with a consequent saving of
0 %? Show Program Statistics
%?? Show More Program Statistics
%??? Show More Than You Would Ever Want to Know
Refer to the Mortran source code to interpret what
is put out by these commands. If you don't have a
source listing, you don't need to use them.
- 18 -
- Appendix B
+ Appendix B
0 OPERATORS IN REPLACEMENT PARTS OF MACROS
+ OPERATORS IN REPLACEMENT PARTS OF MACROS
- Operator Subs.Text Side Effect
+ ________ ____ ____ ____ ______
0 @LD - (Label display.) Causes the contents of
the macro and label stacks to be listed.
No effect on the code itself.
0 @LE l 'l' is the end-of-line character. (See
the %X command in Appendix A.)
0 @LG @n (Label generate.) n is a unique inte-
ger > 10000 and divisible by 10.
0 @L0 (Label zero.) Resets the @LG value to
0 @n@L= (Label set.) Sets the @LG value to n.
0 @n@LSd - (Label stack.) integer n is pushed into
the label stack at position indicated by
character decimal digit d.
@LUd - (Label unstack.) integer in label stack
at position d is popped and discarded.
0 @MSx - (Macro stack) character x is pushed onto
the symbol stack.
@MU @x (Macro unstack) character at top of sym-
bol stack ('x') is popped.
@MRx - (Macro replace) character x replaces
current symbol on top of symbol stack.
0 @MT - (Macro trace) marks this macro rule for
selective tracing whenever it is matched
while selective tracing mode is in
effect. (See %T in Appendix A.)
0 @I0 - internal integer counter set to zero.
@I+ - internal integer counter increased by 1.
@I- - internal integer counter decreased by 1.
@IC @n n is the current value of the counter
@n@I= - integer counter set to n.
- - 19 -
The following '@J' operators operate on
36 integer counters, indexed by the
character 'c'. 'c' must be alphanu-
meric, i.e. 0-9 or A-Z.
0 c@J0 - 'c' counter set to zero.
c@J+ - 'c' counter increased by 1.
c@J- - 'c' counter decreased by 1.
c@JC @n n is the current value of the 'c'
@nc@J= - 'c' counter set to n.
0 @MG - generate macro-rule #1 --> #2
@MC - change existing macro #1--> to
#1-->rep#2. If no existing macro, then
create new macro #1-->#2.
@MD - Most recent macro-rule for #1 is
deleted. (Buffer space is not
0 @CN - 'nogenerate' performed
@CG - 'generate' performed
@CE - 'endgenerate' performed
@CL - 'elsegenerate' performed
0 @N+ - nest-level counter increased by 1
@N- - nest-level counter decreased by 1
0 @ND date 'date' is characters containing today's
date. The exact form depends on the
computer you are using, since date
information is not part of standard For-
tran. The 'vanilla' version of Mortran
will give a null string. The VM version
gives the characters dd mmm yyyy, where
dd and yyyy are digits, and mmm is the
three-character abbreviation. You can
get Hollerith out of this by using some-
or you can pick it apart with #@n pat-
0 @NH @n n is character count from most recent
0 @NL @n n is card number
0 @NM - copy of text string matching first # in
macro pattern is printed as a line of
the source listing.
0 - 20 -
@NN - copy of text string matching first # in
macro pattern is sent as a a line of the
0 @MF - ("freeze") current macro-rule status is
stacked in the 'reset' stack.
0 @MM - ("melt") 'reset' stack is popped and
macro status restored.
0 @n@LT ccccc ccccc is the 5-column character repre-
sentation of the number n.
0 @LCij @n n is an integer equal to the sum of
decimal digit j and the integer in the
label stack at position indicated by
decimal digit i.
- - 21 -
The following description of the arithmetic stack assumes
that the stack starts with the 4 values a b c d on it. The
top of the stack, i.e. the last number pushed, is on the
- Operator Resulting Stack Comment
+ ________ _________ _____ _______
@A+ (a+b) c d
@A- (b-a) c d
@A* (b*a) c d
@A/ (b/a) c d result is b if a=0
0 j@AQ [j] b c...[j-1] a [j+1] swap (top is )
0 @AR a a b c d dup
0 ccccc@AS v a b c d v is the integer given by the
signed decimal characters cccccc
0 @AT b c d @a is put into the text stream
0 @AU b c d if a=0, perform @CG, otherwise @CN
0 @AV b c d if a is non-zero, perform @CG, oth-
0 @AW b c d if a<0, perform @CG, otherwise @CN
0 @AX b c d if a<=0, perform @CG, otherwise @CN
0 @AY b c d if a>=0, perform @CG, otherwise @CN
0 @AZ b c d if a>0, perform @CG, otherwise @CN
0 - 22 -
- Appendix C
+ Appendix C
0 OPERATORS IN PATTERN PARTS OF MACROS
+ OPERATORS IN PATTERN PARTS OF MACROS
- The rules for the pattern side of macro definitions is
pretty straightforward, but there are some subtilties which
aren't obvious on the first (or even second) reading of the
0 The magic character in the patter part of a macro is the
'#', commonly called a 'sharp', 'pound-sign', or 'hashmark'.
Characters which are not part of a '#-operator' must be
matched exactly for a match to succeed. Various #-operators
will match patterns which may be more or less arbitrary.
When a match succeeds, each #-operator in the pattern part
will have matched a (possibly null) string in the text. As
the matched text is expanded, the characters '#n' in the
replacement part are replaced by the corresponding string
from the text. The characters '#1' will be replaced by the
text which matched the first #-operator in the pattern, '#2'
will be replaced by the text which matched the second
#-operator, and so on. The match for the tenth #-operator
replaces '#A', the eleventh replaces '#B', and so on, up to
'#O'. There is an arbitrary limit of 25 parameters in all,
which has never been reported to be a severe restriction.
C.1 ARBITRARY PATTERNS
+ C.1 ARBITRARY PATTERNS
+ _________ ________
0 The simplest #-operator is simply '#', which can be followed
in the pattern by any character except a '@'. This operator
will match any text of any length, including the null
string, subject to these rules:
1) It can't contain a ';'.
2) Parentheses must balance.
3) It can't start with a blank.
- 23 -
C.2 PATTERNS OF A SPECIFIC LENGTH
+ C.2 PATTERNS OF A SPECIFIC LENGTH
+ ________ __ _ ________ ______
0 The other #-operators have the form '#@n' where n is a char-
acter in 0-9 or A-Z. Normally, these will match any text of
a given length. '#@1' matches any one character, including
blank, ';', all flavors of parentheses, '@', etc. '#@2'
matches any two characters, '#@A' matches any ten, and so
on, up to #@S, which matches 28 characters. (The character
count is affected by the fact that multiple blanks are con-
verted to a single blank during the input process, and that
multiple blanks may be introduced by macro replacement. In
general, long text like this is difficult to get right.)
C.3 MATCHING SYNTACTIC ELEMENTS
+ C.3 MATCHING SYNTACTIC ELEMENTS
+ ________ _________ ________
0 I have stolen from the high end of the alphabet to provide
some other matching functions. These are experimental func-
tions, and it remains to be seen whether they will be useful
in real applications. In case of conflict between function
and computing cost, I have reduced the function in this part
of the processor, which may account for some of the strange-
ness in the definitions.
1) '#@T' matches a 'token' of any length, i.e. a string
of characters in 0-9 or A-Z. Leading blanks are deleted,
and a trailing blank will end the match.
2) '#@V' matches a 'token', as above, but will also match
a 'token' followed immediately by anything in parentheses.
For instance, it will match 'A', 'AB', 'AB(C)', and
'A(B+C)', but only the 'AB' of 'AB+C' or 'AB (C)'.
- 24 -
- Appendix D
+ Appendix D
0 CHARACTER SET
+ CHARACTER SET
- The character set used by Mortran is read in as the sec-
ond line of the macro set. Some of the characters, such as
the digits and the alphabet, shouldn't be changed, if only
to protect the sanity of the programmer. Others, for
instance the special characters, might be changed to accomo-
date a special terminal, or a different user language. The
following table gives the position on line 2 of the macro
set for each character, the usual character, and any special
use of that character. Note that it shows only usage that
is defined ("hard-wired") in the processor itself. Trans-
formations set by macros could change it beyond recognition.
- Col char Comments
+ ___ ____ ________
0 1-37 0-9, A-Z, blank
38 not used
39 . Not used.
40-41 () Arbitrary strings in macro patterns are not
matched by sequences containing unbalanced
42 , Not used.
43 = Used in the macro that defines macros.
44-47 +-*/ Used by compile-time arithmetic macros.
50-51 < > Used to calculate nest levels, printed at left
52 ; Logical line-end.
53 : Not used.
54 ' Used in the macro that defines macros, and in
specifying strings to convert to Hollerith for-
55 " Comment delimiter.
56-59 Not used.
60 % Used in the macro that defines macros, in con-
trol commands, and in some @-operators.
61 # Used in the macro that defines macros.
62 @ Used for '@-operators'.
63-64 ¢: Not used.
65 ? Used for debugging in the %? command.
- 25 -
0 1. MORTRAN 2.79 . . . . . . . . . . . . . . . . . . . . 1
+ 1. MORTRAN 2.79 1
0 Mortran Syntax . . . . . . . . . . . . . . . . . . 1
Mortran Statements . . . . . . . . . . . . . . . . 2
Conditionals . . . . . . . . . . . . . . . . . 2
Loops . . . . . . . . . . . . . . . . . . . . . 2
Local Subroutines . . . . . . . . . . . . . . . 3
Abbreviations . . . . . . . . . . . . . . . . . 4
Multiple Assignment . . . . . . . . . . . . 4
INPUT and OUTPUT Statements . . . . . . . . 4
Quoted Strings . . . . . . . . . . . . . . . . . . 4
Comments . . . . . . . . . . . . . . . . . . . . . 5
Conditional Generation of Code . . . . . . . . . . 5
Listing . . . . . . . . . . . . . . . . . . . . . 6
Mortran Keywords . . . . . . . . . . . . . . . . . 6
Line Numbers . . . . . . . . . . . . . . . . . . . 7
. . . . . . . . . . . . . . . . . . . . . 7
Compile-Time Arithmetic . . . . . . . . . . . . . 7
Example . . . . . . . . . . . . . . . . . . . . 9
0 2. USING MACROS . . . . . . . . . . . . . . . . . . . . 11
+ 2. USING MACROS 11
0 A Useful and Instructive Example . . . . . . . . . 11
0 3. USING MORTRAN ON SLAC VM . . . . . . . . . . . . . . 13
+ 3. USING MORTRAN ON SLAC VM 13
0 Specifying the Macro Set . . . . . . . . . . . . . 13
Output Files . . . . . . . . . . . . . . . . . . . 14
Filedefs for Additional Input Files . . . . . . . 15
0 A. CONTROL COMMANDS . . . . . . . . . . . . . . . . . . 16
+ A. CONTROL COMMANDS 16
0 B. OPERATORS IN REPLACEMENT PARTS OF MACROS . . . . . . 19
+ B. OPERATORS IN REPLACEMENT PARTS OF MACROS 19
0 C. OPERATORS IN PATTERN PARTS OF MACROS . . . . . . . . 23
+ C. OPERATORS IN PATTERN PARTS OF MACROS 23
0 Arbitrary Patterns . . . . . . . . . . . . . . . . 23
Patterns of a Specific Length . . . . . . . . . . 24
Matching Syntactic Elements . . . . . . . . . . . 24
- - i -
D. CHARACTER SET . . . . . . . . . . . . . . . . . . . . 25
+ D. CHARACTER SET 25
- ii -