Version I.5, September 1978
This section is designed for programmers who are already
familiar with Basic. Its intent is to describe to those experienced
users the details of UCSD Basic in a manner sufficiently detailed so
as to enable the writing or modification of programs to be compatible
with the UCSD Basic Compiler.
The first section contains a brief description of the features
included in UCSD Basic; the second, the descriptions of the features
unique to UCSD Basic, and the third a list of those features which we
intend UCSD Basic to allow, but which are not yet implemented.
The UCSD Basic Compiler has been written in the Pascal
language. Some of the intrinsics of the Pascal language, which are not
found in standard Basic, are found within the UCSD version of Basic.
Many of these are noted in the first section, all of them are noted or
recapped in the second.
|IX SYSTEM.COMPILER
The UCSD BASIC Compiler is invoked just like the Pascal
compiler, provided the compiler code is named *SYSTEM.COMPILER.
Originally it will be named BASIC.COMPILER. If you want a disk to be
BASIC oriented, you must change the name of, or remove, the Pascal
compiler, and change the name of BASIC.COMPILER to
*SYSTEM.COMPILER.
That disk, and any copies of it, will now compile BASIC programs as a
result of the
C(ompile or
R(un command.
Description of Features Included
The Basic compiler has only real and string variables. When
applying a real to indexing or other integer purposes the rounded value
of the number is used. In the functions below x and y can be real
variables or expressions which evaluate to real values. Similarly s1
and s2 can be string variables or expressions which evaluate to a
string.
Variable Names
Real variables: letter(digit). The digit is optional.
String variables: letter(digit)$. The digit is optional.
Intrinsic Arithmetic Functions
-
ATN(x)
-
Returns the angle in radians whose tangent is x.
-
EXP(x)
-
Returns the base of the natural logarithm raised to the power x.
-
INT(x)
-
Returns the value of x rounded to the nearest integer.
-
LOG(x)
-
Returns the log (base 10) of x.
-
LN(x)
-
Returns the natural log of x.
-
MOD(x, y)
-
Returns x modulo y.
-
SIN(x)
-
Returns the sine of the angle x, where x is in radians.
-
COS(x)
-
Returns the cosine of an angle x, where x is in radians.
Intrinsic String Functions
-
CAT$(s1, s2, ...)
-
Returns a string which is equal to the concatenation of
all the strings in the parameter list.
-
COP$(s1, x, y)
-
Returns a copy of the portion of the string s1, y
consecutive characters, starting with the character at position x.
-
DEL$(s1, x, y)
-
Returns the contents of the string s1 with y consecutive
characters deleted. The deletion starts with the character at
position x.
-
INS$(s1, s2, x)
-
Returns the contents of string s2 with string s1 inserted
immediately before the character which is at position x.
-
LEN(s1)
-
Returns the length of the string s1.
-
POS(s1, s2)
-
Returns an integer which is equal to the position of the
first character in the first occurrence of the string s1 in the
string s2.
Other Functions
-
ORD(s)
-
Returns the ASCII value of the first character of the string s.
-
STR$(x)
-
Returns the string containing the character associated with the ASCII
value x.
-
GET$
-
Reads a single character from the keyboard without prompt or echoing,
and returns it as a string. GET$ requires no arguments.
-
OLD(c, s)
-
NEW(c, s)
-
c is a numeric constant without a fraction part, which becomes
associated with the disk file whose name is in s.
OLD expects that
file to already exist, NEW creates a new one with the name s,
removing
any previous file of that name. These functions must occur before
associated print or input statements. The numbers may not be
reassigned and must be in the range 1..16. For best results, use only
at the top of a program. In order that a file created by NEW be
editable with either of the system editors, ‘.TEXT’
must be appended to the file title.
These functions return IORESULT as described in section
2.1.
Arithmetic Operators
-, + | subtract, add |
/, * | divide, multiply |
** | exponentiation |
Relational operators
= | equals |
<>, >< | not equals |
> | greater than |
< | less than |
>=, => | greater than or equal |
<=, =< | less than or equal |
Programming Statements
-
INPUT list
- INPUT #c list
-
Inputs from the main system device, usually the keyboard. If the
optional #c is present, INPUT inputs from the disk file number
c. The input list may contain any combination of real
variables and string variables. When a program expects input the
prompt “?” is printed. Input of real numbers may be
terminated with any non-numeric character. Input of strings must be
terminated with a return.
-
PRINT list
- PRINT #c list
-
Writes to the main output device the list following the PRINT
command. If the optional #c is present, PRINT outputs to the
diskfile number c. The output list may contain any
variable, subscripted array variable, any arithmetic or string
expression, or any literal text. The list may be separated by
commas or semi-colons. If the list ends in a semi-colon the
carriage return is suppressed. Literals may be enclosed in either
type of quotation marks. Double quotation marks prints a single
quotation mark.
-
FOR var = exp1 TO exp2 STEP exp3
-
NEXT var
-
Each execution of the loop increments the loop counter
“var” by the amount of the third expression. If
the STEP is omitted it is assumed to be 1. Only increasing
STEP values are allowed. Evaluation of limits and
increments is done at the beginning of the loop. Note that RETURNs
into or GOTOs into a FOR loop may cause the loop to be undefined.
- IF exp1 (relation operator) exp2 THEN (line number)
- IF exp1 (relation operator) exp2 GOTO (line number)
-
Either the reserved word THEN or GOTO can be used
in this statement. If the relation between the exp1 and
exp2 is found to be true the branch occurs. A string is
considered to be less than another string if it is lexicographically
smaller.
- ON exp GOTO (ln1, 1n2 ...)
-
If the expression, when rounded, evaluates to 1 it goes to the
first line number (ln1), if it evaluates to 2 it goes to
ln2, etc. This is the only form of the computed
GOTO which is available. If the expression is out of range
an error occurs.
- DEF FNname(list) = expression
- DEF FNname(list)
:
FNEND
-
Single line and multi-line functions are allowable. The function
name must be a legal variable name for the type of value returned.
Functions may be defined recursively. The parameter list is called
by value, that is, changes inside the function don't affect the
value of the external parameters.
- LET var = exp
- var = exp
-
This command assigns a new value to the variable.
If the variable is a string, the expression must evaluate to a string.
If the variable is a real, the expression must evaluate to a real.
- DIM var (n1, n2, ...)
-
A single or multi-dimensional array may be declared with this
command. The variable name determines the type of the array. The
array indices are 0..n1, 0..n2, ... Both real and
string multidimensional arrays can be used. If no dimensions are
declared the dimensions are assumed to be 0..1O, 0..1O, 0..1, 0..1,
... The number of dimensions automatically declared depends on the
number of dimensions which are used in the program, but must be
consistent over all uses of any given array.
-
GOSUB line-number
-
Executes a subroutine call. The calling address is placed on the
subroutine stack. Subroutine calls may be recursive.
- RETURN
-
Returns to the line after the last GOSUB which is still pending. It pops
the top address off the stack and uses it as the return address. A
return when no GOSUBs are pending is an error.
- GOTO line-number
-
Program execution jumps to the given line number.
- REM text
This line is a remark (a comment).
Unique Features of UCSD Basic
- For loops:
-
Note that var = exp1 is done before exp2 or
exp3 are evaluated.
- Continuation of statements is allowed.
-
Any line not beginning with a line number is assumed to be the
continuation of the line above.
- Functions:
-
All parameters of functions are call by value. You are not
allowed to use the parameters to return values from a function.
Function calls are allowed to be recursive.
- Strings:
-
The string functions and procedures are those found in the
UCSD Pascal language.
- Arrays:
-
Arrays of more than two dimensions are allowed.
- Print:
-
Tab stops are not allowed. All list elements are printed without
spaces between them. The carriage return can be suppressed by
“;” as the last symbol in the line.
- Subroutines:
-
Subroutines may be recursive.
- Comments:
-
In line comments may be inserted. The portion of any line
following the “@” symbol is ignored by the compiler.
- PASCAL FUNCTIONs:
-
The code of PASCAL FUNCTIONs may be added to the
BASIC compiler as new standard BASIC functions. This is
accomplished by a straight-forward addition to the BASIC compiler.
Features to be Added
Certain features of the UCSD Basic compiler are still in the
process of being implemented. The most important of these are listed
below.
- Data and Read:
-
The standard initialization statements.
- Matrix
-
A MATRIX statement for standard matrix operations.
- Integer variables.
-
and expressions.
- Functions
-
More standard functions.
Running a Basic Program
Create the BASIC program using one of the system text editors.
Once you have ensured that the BASIC compiler has been named
SYSTEM.COMPILER, you can use the commands C(ompile and R(un at the
command level, just as if you were using Pascal on a disk which has the
Pascal compiler as its SYSTEM.COMPILER. For a more detailed
description of the command level see Section
1.1.
This page last regenerated Sun Jul 25 01:09:11 2010.