In the following pages syntactic categories are in \fIitalics\fP;
literals are in \fBbold\fP; material in brackets [\|] is optional.
Tokens consist of keywords, identifiers, constants, operators,
Token separators may be blanks, tabs or comments.
Newline characters or semicolons separate statements.
Comments are introduced by the characters /* and terminated by
There are three kinds of identifiers \- ordinary identifiers, array identifiers
and function identifiers.
All three types consist of single lower-case letters.
Array identifiers are followed by square brackets, possibly
enclosing an expression describing a subscript.
Arrays are singly dimensioned and may contain up to 2048
Indexing begins at zero so an array may be indexed from 0 to 2047.
Subscripts are truncated to integers.
Function identifiers are followed by parentheses, possibly enclosing arguments.
The three types of identifiers do not conflict;
a program can have a variable named \fBx\fP,
an array named \fBx\fP and a function named \fBx\fP, all of which are separate and
The following are reserved keywords:
Constants consist of arbitrarily long numbers
with an optional decimal point.
The hexadecimal digits \fBA\fP\-\fBF\fP are also recognized as digits with
values 10\-15, respectively.
The value of an expression is printed unless the main
operator is an assignment.
Precedence is the same as the order
of presentation here, with highest appearing first.
Left or right associativity, where applicable, is
discussed with each operator.
places where values are stored.
named expressions are legal on the left
The value of a named expression is the value stored in the place named.
Simple identifiers are named expressions.
They have an initial value of zero.
\fIarray-name\fP\|[\|\fIexpression\fP\|]
Array elements are named expressions.
They have an initial value of zero.
\fBscale\fR, \fBibase\fR and \fBobase\fR
\fBscale\fP, \fBibase\fP and \fBobase\fP are all named expressions.
\fBscale\fP is the number of digits after the decimal point to be
retained in arithmetic operations.
\fBscale\fR has an initial value of zero.
\fBibase\fP and \fBobase\fP are the input and output number
Both \fBibase\fR and \fBobase\fR have initial values of 10.
\fIfunction-name\fB\|(\fR[\fIexpression\fR\|[\fB,\|\fIexpression\|\fR.\|.\|.\|]\|]\fB)
A function call consists of a function name followed by parentheses
containing a comma-separated list of
expressions, which are the function arguments.
A whole array passed as an argument is specified by the
array name followed by empty square brackets.
All function arguments are passed by
As a result, changes made to the formal parameters have
no effect on the actual arguments.
If the function terminates by executing a return
statement, the value of the function is
the value of the expression in the parentheses of the return
statement or is zero if no expression is provided
or if there is no return statement.
sqrt\|(\|\fIexpression\fP\|)
The result is the square root of the expression.
The result is truncated in the least significant decimal place.
The scale of the result is
the scale of the expression or the
length\|(\|\fIexpression\fP\|)
The result is the total number of significant decimal digits in the expression.
The scale of the result is zero.
scale\|(\|\fIexpression\fP\|)
The result is the scale of the expression.
The scale of the result is zero.
Constants are primitive expressions.
An expression surrounded by parentheses is
The parentheses are used to alter the
The result is the negative of the expression.
++\|\fInamed-expression\fP
The result is the value of the named expression after
\-\-\|\fInamed-expression\fP
The result is the value of the named expression after
\fInamed-expression\fP\|++
The result is the value of the named expression before
\fInamed-expression\fP\|\-\-
The result is the value of the named expression before
The exponentiation operator binds right to left.
\fIexpression\fP ^ \fIexpression\fP
expression raised to the power of the
The second expression must be an integer.
is the scale of the left expression
and \fIb\fP is the absolute value
then the scale of the result is:
min\|(\|\fIa\(mub\fP,\|max\|(\|\fBscale\fP,\|\fIa\fP\|)\|)
The operators *, /, % bind left to right.
\fIexpression\fP * \fIexpression\fP
The result is the product
If \fIa\fP and \fIb\fP are the
scales of the two expressions,
then the scale of the result is:
min\|(\|\fIa+b\fP,\|max\|(\|\fBscale\fP,\|\fIa\fP,\|\fIb\fP\|)\|)
\fIexpression\fP / \fIexpression\fP
The result is the quotient of the two expressions.
The scale of the result is the value of \fBscale\fR.
\fIexpression\fP % \fIexpression\fP
The % operator produces the remainder of the division
\fIa\fP%\fIb\fP is \fIa\fP\-\fIa\fP/\fIb\fP*\fIb\fP.
The scale of the result is the sum of the scale of
the divisor and the value of
The additive operators bind left to right.
\fIexpression\fP + \fIexpression\fP
The result is the sum of the two expressions.
The scale of the result is
the maximun of the scales of the expressions.
\fIexpression\fP \- \fIexpression\fP
The result is the difference of the two expressions.
The scale of the result is the
maximum of the scales of the expressions.
The assignment operators bind right to left.
\fInamed-expression\fP = \fIexpression\fP
This expression results in assigning the value of the expression
to the named expression on the left.
\fInamed-expression\fP =+ \fIexpression\fP
\fInamed-expression\fP =\- \fIexpression\fP
\fInamed-expression\fP =* \fIexpression\fP
\fInamed-expression\fP =/ \fIexpression\fP
\fInamed-expression\fP =% \fIexpression\fP
\fInamed-expression\fP =^ \fIexpression\fP
The result of the above expressions is equivalent
to ``named expression = named expression OP expression'',
where OP is the operator after the = sign.
Unlike all other operators, the relational operators
are only valid as the object of an \fBif\fP, \fBwhile\fP,
or inside a \fBfor\fP statement.
\fIexpression\fP < \fIexpression\fP
\fIexpression\fP > \fIexpression\fP
\fIexpression\fP <= \fIexpression\fP
\fIexpression\fP >= \fIexpression\fP
\fIexpression\fP == \fIexpression\fP
\fIexpression\fP != \fIexpression\fP
There are only two storage classes in BC, global and automatic
Only identifiers that are to be local to a function need be
declared with the \fBauto\fP command.
The arguments to a function
are local to the function.
All other identifiers are assumed to be global
and available to all functions.
All identifiers, global and local, have initial values
Identifiers declared as \fBauto\fP are allocated on entry to the function
and released on returning from the function.
They therefore do not retain values between function calls.
\fBauto\fP arrays are specified by the array name followed by empty square brackets.
Automatic variables in BC do not work in exactly the same way
as in either C or PL/I. On entry to a function, the old values of
the names that appear as parameters and as automatic
variables are pushed onto a stack.
Until return is made from the function, reference to these
names refers only to the new values.
Statements must be separated by semicolon or newline.
Except where altered by control statements, execution
When a statement is an expression, unless
the main operator is an assignment, the value
of the expression is printed, followed by a newline character.
Statements may be grouped together and used when one statement is expected
by surrounding them with { }.
This statement prints the string inside the quotes.
\fBif\|(\|\fIrelation\fB\|)\|\fIstatement\fR
The substatement is executed if the relation is true.
\fBwhile\|(\|\fIrelation\fB\|)\|\fIstatement\fR
The statement is executed while the relation
The test occurs before each execution of the statement.
\fBfor\|(\|\fIexpression\fB; \fIrelation\fB; \fIexpression\fB\|)\|\fIstatement\fR
The for statement is the same as
\fBwhile\|(\fPrelation\|\fB) {\fP
All three expressions must be present.
\fBbreak\fP causes termination of a \fBfor\fP or \fBwhile\fP statement.
\fBauto \fIidentifier\fR\|[\|\fB,\fIidentifier\fR\|]
The auto statement causes the values of the identifiers to be pushed down.
The identifiers can be ordinary identifiers or array identifiers.
Array identifiers are specified by following the array name by empty square
The auto statement must be the first statement
in a function definition.
\fBdefine(\|\fR[\fIparameter\|\fR[\fB\|,\|\fIparameter\|.\|.\|.\|\fR]\|]\|\fB)\|{\fI
The define statement defines a function.
be ordinary identifiers or array names.
Array names must be followed by empty square brackets.
\fBreturn(\fI\|expression\|\fB)\fR
The return statement causes termination of a function,
popping of its auto variables, and
specifies the result of the function.
The first form is equivalent to \fBreturn(0)\fR.
The result of the function is the result of the expression
The quit statement stops execution of a BC program and returns
control to UNIX when it is first encountered.
Because it is not treated as an executable statement,
in a function definition or in an