03-BASIC Compiler User's Manual
03-BASIC Compiler User's Manual
COMPILER
User’s Manual
. ........ . ... I
Ta
BASIC
COMPILER
User’s Manual
Sample Compilation
Error Messages
©Microsoft, 1979
8102-510-01
Microsoft
BASIC Compiler User’s Manual
CONTENTS
2.1 Procedure
2.2 Sample Compilation
objprog-dev:filename.ext,list-dev:filename.ext=
source-dev:filename.ext
objprog-dev:
The device on which the object program is to be written.
list-dev:
The device on which the program listing is written.
source-dev:
The device from which the source-program input to BASIC is
obtained. If a device name is omitted, it defaults to the
currently selected drive.
filename.ext
The filename and filename extension of the object program
file, the listing file, and the source file. Filename
extensions may be omitted. The default filename extensions
with CP/M are:
BASIC Compiler User’s Manual Page 1-2
Examples
Switch Action
FORI=ATOBSTEPC
Examples:
2.1 PROCEDURE
Error check
Before attempting to compile the program and
produce object code for the first time, it is
advisable to do a simple syntax check. This will
help eliminate the necessity of recompiling later
due to syntax errors or other easy-to-fix errors.
One way to check for errors is to run the program
on Microsoft's BASIC-80 interpreter.
A>BASCOM ,=MAX1/N
A>BASCOM MAX1,MAX1=MAX1
A>L80 MAX1/G
A>L80 MAX1/E
A>SAVE 48 MAX1.COM
NOTE
A>L80 MAX1,MAX1/N/E
A>MAX1
BASIC Compiler User's Manual Page 2-3
A>BASCOM =TEST
A>BASCOM
*=TEST
A>
BASIC Compiler User's Manual Page 2-4
ERROR MESSAGES
FATAL ERRORS
Code Error
Missing semicolon
Name too long
Expected GOTO or GOSUB
String assignment required
String expression required
String varible required here
Illegal syntax
Variable required here
Wrong number of arguments
Formal parameters must be unique
Single variable only allowed
Missing TO
Illegal FOR loop index variable
Missing THEN
Missing BASE
Illegal subroutine name
OM Out of Memory
Array too big
Data memory overflow
Too many statement numbers
Program memory overflow
SQ Sequence Error
Duplicate statement number
Statement out of sequence
TM Type Mismatch
Data type conflict
Variables must be of same type
TC Too Complex
Expression too complex
Too many arguments in function call
Too many dimensions
Too many variables for LINE INPUT
Too may variables for INPUT
BS Bad Subscript
Illegal dimension value
Wrong number of subscripts
UC Unrecognizable Command
Statement unrecognizable
Command not implemented
OV Math Overflow
/0 Division by Zero
FN FOR/NEXT Error
FOR loop index variable already in use
FOR without NEXT
NEXT without FOR
WE WHILE/WEND Error
WHILE without WEND
WEND without WHILE
WARNING ERRORS
SI Statement Ignored
Statement ignored
Unimplemented command
BASIC Compiler User's Manual Page 3-4
Number Message
2 Syntax error z
A line is encountered that contains an incorrect
sequence of characters in a DATA statement.
4 Out of data
A READ statement is executed when there are no DATA
statements with unread data remaining in the program.
11 Division by zero
A division by zero is encountered in an expression, or
the operation of involution results in zero being
raised to a negative power. Machine infinity with the
sign of the numerator is supplied as the result of the
division, or positive machine infinity is supplied as
the result of the involution, and execution continues.
21 Unprintable error
An error message is not available for the error
condition which exists. This is usually caused by an
ERROR with an undefined error code.
50 Field overflow
A FIELD statement is attempting to allocate more bytes
than were specified for the record length of a random
file.
51 Internal error
An internal malfunction has occurred in Disk BASIC-80.
Report to Microsoft the conditions under which the
message appeared.
61 Disk full
All disk storage space is in use.
CHAPTER 1 INTRODUCTION
Software
Documentation
Software
Documentation
3.1 Compiling
3.2 Linking
3.3 Running a Program
CHAPTER 4 EDITING
CHAPTER 7 LINKING
INTRODUCTION
3. Source-code secure.
Organization
1.3 SOFTWARE
1.4 DOCUMENTATION
IMPORTANT
2. MACRO-80
3. LIB-80
4. CREF-80
INTRODUCTION TO COMPILATION
Interpretation
Compilation
2.2 VOCABULARY
this library does not support the CLEAR command, the RUN
cline-number> option of the RUN command, and COMMON between
CHAINed subprograms. It does support a version of CHAIN
that is semantically equivalent to the simple RUN command.
------------------------ r 1. Create
BASIC-80 and edit Other
Interpreter BASIC Text Editor
—---------- —I- source
BASIC Source «
2. RUN and
BASIC-80 debug program
Interpreter with interpreter
yes v Assembler
*-----------bugs? Source
v no
3. Compile BASIC
BASIC Source, creating
Compiler .REL file
MACRO-80
4. Assemple ASM Assembler
yes V sources if any
------- bugs?
I no BASLIB.REL
I
ASM.REL
Relocatable
object file
+
LINK-80 . Link compiled .REL file to
Linker library, and ASM routines
--------------- BRUN.COM
DEMONSTRATION RUN
IMPORTANT
I
DEMONSTRATION RUN Page 3-2
3.1 COMPILING
BASCOM DEMO,DEM0=DEM0
ERA DEMO.PRN
3.2 LINKING
1. Invoke LINK-80.
L80
DEMO,DEMO/N/E
Type as follows:
DIR A:
DEMO
COMPILING
3. Compiler switches.
The general format for the BASIC Compiler command line is:
<objectfile>][,[<listfile>]]=<sourcefile
Note that the above syntax is concise and accurate, but can
be fairly cryptic^ We will clear up questions in the
following paragraphs, by examining several sample compiler
invocations.
BASCOM <objectfile>,<listfile>=<sourcefile>
BASCOM =<sourcefile>
BASCOM <objectfile>=<sourcefile>
BASCOM ,<listfile>=<sourcefile>
BASCOM ,LST:=<sourcefile>
BASCOM ,=<sourcefile>
You may want to create output files on a disk other than the
defaults provided by the compiler, or you may want to create
output files with different extensions or base names than
that of of your BASIC source file. To do so, you must
actually specify the filenames with the desired extensions
or device designations, as described below:
Filename Extensions
Device Designations
B:DEMO
DESIGNATIONS DEVICES
A:, B:, C:, etc Disk Drives
LST: Line Printer
CRT (or Teletype)
BASCOM =B:DEMO
BASCOM DEMO,DEMO=B:DEMO
BASCOM ,DEMO=B:DEMO
BASCOM FOO,FOO=FOO/T/4/X
1. Conventions
2. Error Trapping
3. Special Code
Conventions
Error Trapping
Special Code
CONVENTIONS
Switch Action
FORI=ATOBSTEPC
NOTE
COMPILING Page 6-12
ERROR TRAPPING
Switch Action
NOTE
SPECIAL CODE
Switch Action
LINKING
>L80
*PROG.COM/N,PROG.REL/E
The caret (>) is the CP/M prompt; the asterisk (*) is the
linker prompt. Note that linker switches have no relation
whatsoever to the compiler switches discussed in the
preceding chapter.
>L80
*PROG/N,PROG/E
LINKING Page 7-2
>L80 PROG/N,PROG/E
>L80
*PROG,MYASM,PROG/N/E
Memory *
COMMON
1.—> - u ( ■■
RUNTIME MODULE
Bottom T”111 ■■■ I1
of CPM vectors
Memory
First of all, before you can link any BASIC .REL file, you
must have the file BCLOAD on the currently logged disk.
BCLOAD contains two pieces of information: the hexadecimal
load address of your program, and the drive in which to find
BRUN.COM at runtime.
L80 FOO/G
L80 FOO/G may not work if BRUN.COM does not reside on the
disk you have specified in BCLOAD. CHAINing of programs
does not work properly if you use SAVE after a link.
Once you have compiled a .REL file, you need to link your
program to modules that contain runtime support routines.
Runtime support is the body of routines that, in essence,
implement the BASIC language. Your compiled .REL file, on
the other hand, implements the particular algorithm that
makes your program a unique BASIC program.
10 RUN "PROG"
A COMPILER/INTERPRETER COMPARISON
CALL %INCLUDE
CHAIN ON ERROR GOTO
CLEAR REM
COMMON RESUME
DEFxxx RUN
DIM STOP
END TRON/TROFF
ERASE USRn
FOR/NEXT WHILE/WEND
CALL
The CALL statement allows you to call and transfer
program. control to a precompiled FORTRAN-80
subroutine, or to an assembly language routine that
you have created with MACRO-80. The format of the
CALL Statement is:
NOTE
2. CHAIN
The BASIC Compiler does not support the ALL, MERGE,
DELETE, and <line number> options to CHAIN. If you
wish to pass variables, it is recommended that the
COMMON statement be used. Note that files are left
open during CHAINing.
A COMPILER/INTERPRETER COMPARISON Page 9-4
3. CLEAR
The BASIC Compiler supports the CLEAR command as
described in the BASIC-80 Reference Manual, with
the restriction that <expressionl> and
<expression2> must be integer expressions. If a
value of 0 is given for either expression, the
appropriate default is used. The default stack
size is 256 bytes and the default top of memory is
the current top of memory. The CLEAR statement
performs the following actions:
COMMON
DEFDBL, DEFINT, DEFSNG, DEFSTR
DIM
•OPTION BASE
REM
%INCLUDE
IMPORTANT
MENU.BAS
10 %INCLUDE COMDEF
PROG1.BAS
10 %INCLUDE COMDEF
COMDEF.BAS
100 DIM A(100),B$(200)
110 COMMON I,J,K,A()
120 COMMON A$,B$(),X,Y,Z
5. DEFINT/SNG/DBL/STR
DEFxxx statements designate the storage class and
data type of variables listed as parameters. The
compiler does not "execute" DEFxxx statements as it
does a PRINT statement, for example.
A COMPILER/INTERPRETER COMPARISON Page 9-6
1. INTeger,
4. STRing.
DIM A1(I)
DIM Al(3+4)
DIM A1(3.4E5)
A COMPILER/INTERPRETER COMPARISON Page 9-7
END
During execution of a compiled program, an END
statement closes files and returns control to the
operating system. The compiler assumes an END
statement at the end of the program, so "running
off the end" (omitting an END statement at the end
of the program) produces proper program termination
by default.
8. ERASE
The ERASE statement is not implemented for the
compiler. ERASE in BASIC-80 allows you to
re-dimension arrays, something that is not done in
the compiled environment.
FOR/NEXT
Double precision FOR/NEXT loops can be used with
the . compiler. Also, FOR/NEXT loops must be
statically nested. Static nesting means that each
FOR must have a single corresponding NEXT.
FOR I
FOR J
FOR K
NEXT J
NEXT K
NEXT I
FOR I
FOR J
FOR K
NEXT K
NEXT J
NEXT I
A COMPILER/INTERPRETER COMPARISON Page 9-8
50 GOTO 100
90 FOR I = 1 to 10
200 NEXT I
10. %INCLUDE
The format of the % INCLUDE compiler directive is:
% INCLUDE <filename>
ON ERROR GOTO
If a program contains ON ERROR GOTO and RESUME
<line number> statements, the /E compilation switch
must be given in the compiler command line. If the
RESUME NEXT, RESUME, or RESUME 0 form is used, the
/X switch must be used instead.
12. REM
REM statements are REMarks starting with a single
quotation mark or the word REM. Since REM
statements do not take up time or space during
execution, REM may be used as freely as desired.
This practice is encouraged for improving the
readability of your programs.
13. RESUME
See the preceding discussion of ON ERROR GOTO.
14. RUN
The compiler supports both the RUN and RUN <line
number> forms of the RUN statement. The BASIC
Compiler does not support the ”R" option with RUN.
If this feature is desired, the CHAIN statement
should be used. Note that RUN is used to execute
.COM files created by the BASIC Compiler, and does
not support the execution of BASIC source files as
does the interpreter.
15. STOP
The STOP statement is identical to the END
statement, except that it terminates your program
at a point that is not necessarily its end. It
also prints a message telling you at which
hexadecimal address you have stopped. If the /D,
/E, or /X compiler switches are turned on, then the
message prints the line number at which you have
stopped. As with the END statement, STOP closes
all open files and returns control to the operating
system. STOP is normally used for debugging
purposes.
16. TRON/TROFF
In order to use TRON/TROFF, the compiler /D Debug
switch must be switched on. Otherwise, TRON and
TROFF are ignored and a warning message is
generated.
CALL $U%+const
SHLD X%
CALL $U%+const
LD (X%), HL
18. WHILE/WEND
WHILE/WEND constructions should be statically
nested. Static nesting means that each WHILE/WEND
pair, when nested within other FOR/NEXT or
WHILE/WEND pairs, cannot reside partly in, and
partly outside, the nesting pair. For example, the
following construction is not allowed:
FOR I = 1 to 10 -----
A = COUNT
WHILE A = 1 -------
NEXT I -----------------------
A = A - 1
WEND ---------------------
EXPRESSION EVALUATION
QR=J%+A’+Q#
INTEGER VARIABLES
ERROR MESSAGES
FATAL ERRORS
CODE MESSAGE
BS Bad Subscript
Illegal dimension value
Wrong number of subscripts
FN FOR/NEXT Error
FOR loop index variable already in use
FOR without NEXT
NEXT without FOR
IN INCLUDE Error
%INCLUDE file not found
OM Out of Memory
Array too big
Data memory overflow
Too many statement numbers
Program memory overflow
OV Math Overflow
TC Too Complex
Expression too complex
Too many arguments in function call
Too many dimensions
Too many variables for LINE INPUT
Too many variables for INPUT
Type Mismatch
Data type conflict
Variable must be of same type
UC Unrecognizable Command
Statement unrecognizable
Command not implemented
WHILE/WEND Error
WHILE without WEND
WEND without WHILE
/0 Division by Zero
ERROR MESSAGES Page 10-4
WARNING ERRORS
CODE MESSAGE
SI Statement Ignored
Statement ignored
Unimplemented command
ERROR MESSAGES Page 10-5
NUMBER MESSAGE
2 Syntax Error
A line is encountered that contains an incorrect
sequence of characters in a DATA statement.
Out of Data
A READ statement is executed when there are no
DATA statements with unread data remaining in
the program.
5 Illegal Function Call
A parameter that is out of range is passed to a
math or string function. A function call error
may also occur as the result of:
21 Unprintable Error
An error message is not available for the error
condition that exists. This is usually caused
by an ERROR with an undefined error code.
50 Field Overflow
A FIELD statement is attempting to allocate more
bytes than were specified for the record length
of a random file.
51 Internal Error
An internal malfunction occurs in the BASIC
Compiler. Report to Microsoft the conditions
under which the message appeared.
52 Bad File Number
A statement or command references a file with a
file number that is not OPEN or is out of the
range of file numbers specified at
initialization.
61 Disk Full
All disk storage space is in use.
62 Input Past End
An INPUT statement reads from a null (empty)
file, or from a file in which all data has
already been read. To avoid this error, use the
EOF function to detect the end of file.
MENU
For the above diagram, the use of CHAIN and RUN in each of
the major programs is outlined in the following program
fragments:
MENU.BAS
1000 If MENU=1 THEN RUN "GL"
1010 IF MENU=2 THEN RUN "AP"
1020 IF MENU=3 THEN RUN "AR"
ROM-able Code
The only way that you can put a compiled BASIC program into
ROM is by linking to the OBSLIB.REL runtime library. This
library is searched by default at linktime only if at
compiletime you compile with the /0 switch.
Memory Map
Top
of CPM
Memory
Stack Grows Downward
AAAAAAAAAAAAA/
RUNTIME MODULE
16K BRUN.COM
Contains most
commonly used
library routines
Bottom
of CPM vectors
Memory
INDEX
TROFF 9-10
TRON 9-10
VARPTR.............................................................. 9-11