V7/usr/man/man1/bas.1
.TH BAS 1
.SH NAME
bas \- basic
.SH SYNOPSIS
.B bas
[ file ]
.SH DESCRIPTION
.I Bas
is a dialect of Basic.
If a file argument is provided,
the file is used for input before the terminal
is read.
.I Bas
accepts lines of the form:
.PP
statement
integer statement
.PP
Integer numbered statements
(known as internal statements)
are stored for later execution.
They are stored in sorted ascending order.
Non-numbered statements are immediately executed.
The result of an immediate expression statement
(that does not have `=' as its highest operator) is printed.
Interrupts suspend computation.
.PP
Statements have the following syntax:
.HP 5
expression
.br
The expression is executed for its side
effects (assignment or function call)
or for printing as described above.
.HP 5
.B comment
.li
...
.br
This statement is ignored.
It is used to interject commentary in a program.
.HP 5
.B done
.br
Return to system level.
.HP 5
.B dump
.br
The name and current value of every
variable is printed.
.HP 5
.B edit
.br
The UNIX editor,
.I ed,
is invoked with the
.I file
argument.
After the editor exits,
this file is recompiled.
.HP 5
.B for
name
.B =
expression expression statement
.br
.br
.ns
.HP 5
.B for
name
.B =
expression expression
.br
.li
...
.br
.ns
.HP 5
.B next
.br
The
.I for
statement
repetitively executes a
statement (first form)
or a group of statements (second form)
under control of a named variable.
The variable takes on the value of
the first expression,
then is incremented by one on each loop,
not to exceed the value of
the second expression.
.HP 5
.B goto
expression
.br
The expression is evaluated, truncated to an integer
and execution goes to the corresponding integer numbered statment.
If executed from immediate mode,
the internal statements are compiled first.
.HP 5
.B if
expression statement
.br
.br
.ns
.HP 5
.B if
expression
.br
.li
...
.br
.ns
.HP 5
[
.B else
.br
.li
... ]
.br
.ns
.HP 5
.B fi
.br
The statement (first form)
or group of statements (second form)
is executed if the expression evaluates
to non-zero.
In the second form,
an optional
.B else
allows for a group of statements to be
executed when the first group is not.
.HP 5
.B list
[expression [expression]]
.br
.br list
is used to print out the stored internal statements.
If no arguments are given, all internal statements are printed.
If one argument is given, only that
internal statement is listed.
If two arguments are given, all internal statements
inclusively between the arguments are printed.
.HP 5
.B print
list
.br
The list of expressions and strings are concatenated and
printed.
(A string is delimited by " characters.)
.HP 5
.B prompt
list
.br
.I Prompt
is the same as
.I print
except that no newline character is
printed.
.HP 5
.B return
[expression]
.br
The expression is evaluated and the result is passed
back as the value of a function call.
If no expression is given, zero is returned.
.HP 5
.B run
.br
The internal statements are compiled.
The symbol table is re-initialized.
The random number generator is reset.
Control is passed to the lowest numbered internal
statement.
.HP 5
.B save
[expression [expression]]
.br
.I Save
is like
.I list
except that the output
is written on the
.I file
argument.
If no argument is given on the command,
.B b.out
is used.
.PP
Expressions have the following syntax:
.HP 5
name
.br
A name is used to specify a variable.
Names are composed of a letter
followed by letters and digits.
The first four characters of a name are significant.
.HP 5
number
.br
A number is used to represent a constant value.
A number is written in Fortran style,
and contains digits, an optional decimal point,
and possibly a scale factor consisting
of an
.B e
followed by a possibly signed exponent.
.HP 5
.B (
expression
.B )
.br
Parentheses are used to alter normal order of evaluation.
.HP 5
_ expression
.br
The result is the negation of the expression.
.HP 5
expression operator expression
.br
Common functions of two arguments are abbreviated
by the two arguments separated by an operator denoting the function.
A complete list of operators is given below.
.HP 5
expression
.B (
[expression [
.B ,
expression] ... ]
.B )
.br
Functions of an arbitrary number of arguments
can be called by an expression followed by the arguments
in parentheses separated by commas.
The expression evaluates to the
line number of the entry of the function in the
internally stored statements.
This causes the internal statements to be compiled.
If the expression evaluates negative,
a builtin function is called.
The list of builtin functions appears below.
.HP 5
name
.B [
expression
[
.B ,
expression
] ...
.B ]
.br
Each expression is truncated to an integer
and used as a specifier for the name.
The result is syntactically identical to a name.
.B a[1,2]
is the same as
.B a[1][2].
The truncated expressions are restricted to
values between 0 and 32767.
.PP
The following is the list of operators:
.TP
=
=
is the assignment operator.
The left operand must be a name or an array element.
The result is the right operand.
Assignment binds right to left,
.TP
& |
&
(logical and)
has result zero if either of its arguments are zero.
It has result one if both its arguments are non-zero.
|
(logical or)
has result zero if both of its arguments are zero.
It has result one if either of its arguments are non-zero.
.TP
< <= > >= == <>
The relational operators
(< less than, <= less than or equal,
> greater than,
>= greater than or equal,
== equal to,
<> not equal to)
return one if their arguments are in the specified
relation.
They return zero otherwise.
Relational operators at the same level extend as follows:
a>b>c is the same as a>b&b>c.
.TP
+ \-
Add and subtract.
.TP
* /
Multiply and divide.
.TP
^
Exponentiation.
.PP
The following is a list of builtin functions:
.TP 7
.B arg(i)
is the value of the
.IR i " -th"
actual parameter on the current level
of function call.
.TP 7
.B exp(x)
is the exponential function of
.IR x .
.TP 7
.B log(x)
is the natural logarithm of
.IR x .
.TP 7
.B sqr(x)
is the square root of
.IR x .
.TP 7
.B sin(x)
is the sine of
.IR x ""
(radians).
.TP 7
.B cos(x)
is the cosine of
.IR x ""
(radians).
.TP 7
.B atn(x)
is the arctangent of
.IR x .
Its value
is between \-\(*p/2 and \(*p/2.
.TP 7
.B "rnd( )"
is a uniformly distributed random
number between zero and one.
.TP 7
.B "expr( )"
is the only form of program input.
A line is read from the input and
evaluated as an expression.
The resultant value is returned.
.TP 7
.B abs(x)
is the absolute value of
.IR x .
.TP 7
.B int(x)
returns
.I x
truncated (towards 0) to an integer.
.SH FILES
/tmp/btm? temporary
.br
b.out save file
.br
/bin/ed for
.B edit
.SH DIAGNOSTICS
Syntax
errors cause the incorrect line to be typed
with an underscore where the parse failed.
All other diagnostics are self explanatory.
.SH BUGS
Has been known to give core images.
.br
Catches interrupts even when they are turned off.