| Home CBM ASCII-X BASIC Disk Commands Enter RUN mode Program Format Secret Variables Variable Format Expressions Keywords Syntax Tokens C128 D64plus Disk Escape Codes Hardware PCxface PETSCII Pet2asc Futurama IBM PC-AT Contact Games Glossary Hall of fame Hall of shame Miscellaneous Privacy policy Programming Twisty puzzles |
BASIC expressions are so fundamental that their operation is rarely documented;
or at least, not fully documented. BASIC expressions are a core element of the BASIC language:
they are used in almost every BASIC command/function/statement!
There are 4 fundamental types of BASIC expressions ("primitives"):
Most importantly, a BASIC expression may be composed of multiple primitives ("compound expression").
For example, the (compound) expression Y-2*X consists of 5 primitives:
These can be considered as constants. Examples:
These are some value created/saved by a program (typically) or the user in direct mode (rarely). Examples:
This a formula which is auto-calculated by BASIC. Example:
Fundamental mathematical expression. NOTE: this is (by far) the most common type of expression. Examples:
In the examples above, you could substitute PRINT with variable = EXAMPLE
to store a value (expression result) instead of printing it.
Note that case 4 "Operator" invokes OPERATOR PRECEDENCE. In very general terms,
a BASIC expression is evaluated left-to-right, but if an operator is encountered with higher priority
than the current sub-expression, the later (high-priority) operator will "take precedence"
which means the following sub-expression will be evaluated before the prior sub-expressions.
If you are familiar with Algebra's precedence (order-of-operations)
this should seem natural. But anyway I list them all below
(by the priority used in BASIC expression evaluation)
in case you aren't intimate with Algebra or maybe you've been using another computer language
(with different precedence).
Note in some cases listed above, where there are two or more operators on a single line (like addition and subtraction) , BASIC will evaluate those (same-priority) operators in left-to-right ("first come, first serve") order. Again, if you are familiar with Algebra or programming with other languages, this may seem rather obvious. But below are some examples which I hope will de-mystify any confusion:
© H2Obsession, 2014, 2015, 2019 |