Commodore 128 Programmer's Reference Manual page 33

Hide thumbs Also See for 128:
Table of Contents

Advertisement

n
BASIC BUILDING BLOCKS AND BASIC 7.0 ENCYCLOPEDIA
23
parentheses (
), creating a "subexpression." The parts of an expression enclosed in pa-
^
rentheses will be reduced to a single value before evaluating parts outside the parentheses.
i i
When you use parentheses in expressions, pair them so that you always have an
\ \
equal number of left and right parentheses. If you don't, the BASIC error message
7SYNTAX ERROR will occur.
p
Expressions that have operands inside parentheses may themselves be enclosed in
\
parentheses, forming complex expressions of multiple levels. This is called nesting.
Parentheses can be nested in expressions to a maximum depth of ten levels—ten
r^
matching sets of parentheses. The innermost expression has its operations performed
j |
first. Some examples of expressions are:
A + B
n
Ct(D + E)/2
j j
((X-Ct (D + E)/2)*10)+l
' [
GG$>HH$
JJ$ + "MORE"
fj
K%=1ANDMOX
i I
K% = 2OR(A = B ANDM<X)
NOT(D = E)
j
The BASIC Interpreter performs operations on expressions by performing arithme
tic operations first, then relational operations, and logical operations last. Both arithme
tic and logical operators have an order of precedence (or hierarchy of operations) within
-?
themselves. Relational operators do not have an order of precedence and will be
performed as the expression is evaluated from left to right.
If all remaining operators in an expression have the same level of precedence, then
^
operations are performed from left to right. When performing operations on expressions
j
within parentheses, the normal order of precedence is maintained. The hierarchy of
arithmetic and logical operations is shown in Table 2-2 from first to last in order of
precedence. Note that scientific notation is resolved first.
OPERATOR
t
-
*/
+
> = <
NOT
AND
OR
DESCRIPTION
Exponentiation
Negation (Unary Minus)
Multiplication
Division
Addition
Subtraction
Relational Operations
Logical NOT
(Integer Two's Complement)
Logical AND
Logical OR
EXAMPLE
BASEfEXP
-A
AB*CD
EF/GH
CNT + 2
JK-PQ
A<= B
NOT K%
JK AND 128
PQ OR 15
Table 2-2 Hierarchy of Operations Performed on Expressions

Hide quick links:

Advertisement

Table of Contents
loading

Table of Contents