Home | Up | Questions? |
This note describes the procedure for using the Pascal
compiler on the Nova computer system of the Department of Computer
Sciences at the University of Texas at Austin. It also indicates
the limitations of the system and how they can be overcome.
A compiler for a Pascal-like language (hereafter called Pascal for brevity) has been written and is operational on the Nova computer system. The compiler translates programs written in a subset of Pascal into Nova assembly language. These assembly language programs can then be assembled, loaded, and executed in the normal manner.
The language subset which is compiled is defined further in [1] and the code generation approach is discussed in [2]. This note describes how to use the compiler, the language subset which is accepted and how to live with this subset, and how to interact with the current operating system, RDOS. This is the principal users manual for the Nova Pascal.
The compiler exists as a set of files as follows,
PASC.PA - The Pascal compiler (in Pascal) PASC.SR - The Pascal compiler in Nova assembly language PASC.RB - The Pascal compiler in relocatable binary PASC.SV - The executable core image Pascal compiler
Figure 1. The relationships amongst the Pascal compiler files. This also illustrates the steps involved in compiling, assembling, loading, and executing a Pascal program.
The compiler translates from Pascal source code directly into Nova assembly code, and needs no run-time support or library routines. All code is generated in-line. No subroutine calls, macros, or interpretation is used. (This is in contrast to other Pascal compilers based on the Pascal-P4 compiler which generates code for a hypothetical stack machine which must then be interpreted.)
The compiler is meant to run under RDOS 6.10, the Data General operating system, and makes appropriate system calls for all input/output. It requires at least 26K words of memory, plus whatever is needed for the operating system. The 26K memory allows a symbol table of up to 650 symbols. Since each symbol table entry is 11 words, over a fourth of the compiler is dedicated to the symbol table. Over 600 symbols are needed to compile the compiler, but for smaller user programs, a small compiler with a symbol table of about 200 symbols would reduce the memory requirements of the compiler to approximately 21K words.
The amount of memory needed increases if excessive syntactic nesting occurs. Nesting refers to such syntactic items as:
The compiler is not exactly a robust program and is best when no errors occur. Three types of errors may occur: file errors, syntax errors, and compiler errors.
File errors involve any errors with the operating system interface; the input and output file definitions and operations. No errors are recognized by the compiler. This can result in an infinite loop in the compiler. For example, a non-existent input file will be treated as an infinitely long file of null characters.
Syntax errors are detected by the compiler and simple recovery
techniques are attempted. Errors are indicated by an output line of
the following form:
ERR n COL m
after the line which caused the error. This indicates that error n
occurred in column m. Errors are listed in Figure
2. The line in error may be the immediately previous line or the
one before it. For error number 3 (looking for one syntactic token
type but found a different one), the additional information of what
token type was found and what type was expected is indicated on the
next line as,
F=(found token type) (expected token type)
Token types are listed in Figure 3.
A further problem is unrecoverable errors in the compiler.
Unrecoverable errors are indicated by a line of the following form
at the end of the output file,
**n
where n is the error number as indicated below.
As indicated in SPL/1 [1], the language provided is a subset of the language Pascal. The following language features are NOT provided by the compiler.
In other cases, alternative methods exist for the omitted items,
As one minor extension to the language, the compiler allows
compile-time constant expressions to be used wherever a constant may
be used, as in,
CONST SPACE = 2*n+1;
TYPE INDEX = 0..n-1;
All input/output is done by the operating system in response to users requests. To allow these requests to be made from any Pascal program, two intrinsic functions have been defined and added to the compiler. SYSTEM is a function which takes a variable number of parameters and makes a system call to RDOS. Since some of the system calls must pass addresses as parameters to the system, another intrinsic function ADR returns as its value the address of its argument.
Note that although the function ADR allows addresses to be
manipulated by the Pascal programmer, the programmer has no mechanism,
except the operating system, to interpret the integer number which is
produced as an address; that is there is no MEMORY array or function
which returns the value of the location in memory whose address is
given as an integer. Hence ADR is useful only for system calls.
The SYSTEM function can have up to five parameters. The first parameter defines the type of system call to be made, and the second is an optional channel number. The remaining three parameters specify the values for registers AC0, AC1, and AC2 in the system call. Parameters that are not needed need not be given.
The system call,
STATUS := SYSTEM(call,channel,a0,a1,a2);
load AC0 with a0
load AC1 with a1
load AC2 with a2
.SYSTM
.call channel
if error, then STATUS := 1 + RDOS error code
else STATUS := 0;
To illustrate the use of this facility, consider a
program which inputs characters from a file INPUT and outputs
them to a file OUTPUT. First the input file must be opened
to a channel, say channel 3. The open call requires a byte
pointer to the name of the file in AC0 and a mask in AC1.
Status := system(open,3,2*ADR("INPUT"),0);
status := system(creat,2*ADR("OUTPUT"));
status := system(open,2,2*adr("OUTPUT"),0);
To read a character into a variable C of type 0..127, we use
the RDS (read sequentially n bytes) system call with a byte count of
one. Note that RDOS only reads into the lower byte, so the upper
byte must be zeroed to avoid incorrect comparisons with other characters.
c := 0;
status := system(rds,3,2*adr(c)+1,1);
status := system(wrs,2,2*adr(c)+1,1);
Strings can be output for messages by,
status := system(wrs,2,2*adr("BEGIN TEST"), 10);
Numbers are output by changing them to characters and outputting each character.
I := 0; REPEAT I := I + 1; DIGIT[I] := N MOD 10; N := N DIV 10; UNTIL N = 0; REPEAT C := 48+DIGIT[I]; STATUS := SYSTEM(WRS,2,2*ADR(C)+1,1); I := I - 1; UNTIL I = 0;
The generality of this operating system interface should allow programs to be freely written which modify files, directories, devices, memory, and interact with the operating system in all possible ways.
The compiler has some known problems. At this point they are felt to be minor inconveniences which are however difficult to fix, and so have not been.
X: array [0..512] of integer;
X[512] := 0;
<load zero into register r>
LDA 2,X load address of array X into register 2
STA r,512,X store zero into X[512]
I := 512;
X[I] := 0;
The compiler has some obvious problems, but it is also, we hope, a useful tool for programming on the Nova. A new and better compiler will be written to correct the problems of this compiler. Your comments, suggestions, and experience will be very useful in the revisions of this compiler (and others).
It should be noted that the present compiler is written in Pascal. This allows modifications to be made to the existing system to correct problems of a severe nature, or to produce local user variants of the subset language. Such changes which may occur in the near future include changing the compiler call to automatically look on the command line and search for a .PA extension, produce a listing file, detect and react to errors in operating system I/O, or adding some missing syntactic structures (like the FOR statement, GO TOs, labels). Your suggestions are encouraged.
Figure 2. List of Error messageserror ( 2) (* symbol table overflow *); error ( 3) (* found wrong token type *); error ( 4) (* symbol not a type name *); error ( 5) (* subrange type conflict *); error ( 6) (* subscript not simple type *); error ( 7) (* missing field name *); error ( 8) (* constant for field name *); error ( 9) (* delimiter missing in field list *); error (10) (* type definition missing *); error (11) (* period after nonrecord symbol *); error (12) (* illegal field name *); error (13) (* field name not found *); error (14) (* subscripted var not array *); error (15) (* subscript wrong type *); error (16) (* looking for a variable name *); error (17) (* too many actuals *); error (18) (* paramter type mismatch *); error (19) (* delimiter missing in list *); error (20) (* too few actuals *); error (21) (* looking for a factor *) error (22) (* symbol is wrong kind *); error (23) (* type conflict in term *); error (24) (* type conflict in expression *); error (26) (* uncomparable types *); error (27) (* AND operand not boolean *); error (28) (* OR operand not boolean *); error (29) (* expression not boolean *); error (30) (* mismatched assignment types *); error (31) (* illegal symbol on left of assign *); error (32) (* bad cons definition *); error (33) (* missing parm name *); error (34) (* constant for parm name *); error (35) (* delimiter missing in parms *); error (36) (* period missing after program *); error (37) (* undefined symbol *); error (38) (* multiply defined symbol *); error (41) (* adding non-integer *); error (42) (* subing non-integer *); error (43) (* muling non-integer *); error (44) (* diving non-integer *); error (49) (* improper statement terminator *); error (50) (* illegal genop call *); error (51) (* subscripted non-array *); error (206) (* constants not compatible *);
1 minus - 2 divide / 3 multiply * 4 AND 5 OR 6 NOT 7 left parenthesis ( 8 right parenthesis ) 9 left bracket [ 10 right bracket ] 11 MOD 12 DIV 13 equal sign = 14 not equal sign 15 greater than > 16 greater or equal >= 17 less than < 18 less or equal <= 19 assignment := 20 period . 21 comma , 22 semicolon ; 23 colon : 24 IF 25 THEN 26 ELSE 27 WHILE 28 DO 29 REPEAT 30 UNTIL 31 BEGIN 32 END 33 CONST 34 TYPE 35 VAR 36 PROCEDURE 37 FUNCTION 38 ARRAY 39 RECORD 40 OF 41 FILE 42 PACKED 43 EXTERN 44 FORWARD 45 plus + 47 identifier 48 string "..."
Home | Comments? |