92 lines
2.5 KiB
HTML
92 lines
2.5 KiB
HTML
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
|
|
|
|
<html>
|
|
<head>
|
|
<title>Expressions</title>
|
|
<link href="style.css" rel="stylesheet" type="text/css">
|
|
</head>
|
|
<body background="images/back.gif">
|
|
<!--START-->
|
|
|
|
<h3>Expressions</h3>
|
|
|
|
Expressions can be real numbers (e.g. 3.4), hexadecimal numbers, starting
|
|
with a $ sign (e.g. $00FFAA), strings between single or
|
|
double quotes (e.g. 'hello' or “hello”) or more complicated
|
|
expressions. (Note that strings can run over multiple lines!)
|
|
For expressions, the following binary operators exist (in
|
|
order of priority):
|
|
|
|
<ul>
|
|
<li>&& || ^^: combine Boolean values (&& = and, || = or,
|
|
^^ = xor)</li>
|
|
<li>< <= == != > >=: comparisons, result in true (1) or
|
|
false (0)</li>
|
|
<li>| & ^: bitwise operators (| = bitwise or, & = bitwise and, ^
|
|
= bitwise xor)</li>
|
|
<li><< >>: bitwise operators (<< = shift left, >
|
|
> = shift right)</li>
|
|
<li>+ -: addition, subtraction</li>
|
|
<li>* / div mod: multiplication, division, integer division, and modulo
|
|
</li>
|
|
</ul>
|
|
|
|
<p>
|
|
Note that
|
|
value of <tt>x div y</tt> is the value of <tt>x/y</tt> rounded in the direction of zero to the nearest integer.
|
|
The <tt>mod</tt> operator returns the remainder obtained by dividing its operands.
|
|
In other words, <tt>x mod y = x - (x div y) * y</tt>.
|
|
|
|
|
|
Also, the following unary operators exist:
|
|
|
|
<ul>
|
|
<li>!: not, turns true into false and false into true</li>
|
|
<li>-: negates the next value</li>
|
|
<li>~: negates the next value bitwise</li>
|
|
</ul>
|
|
|
|
As values you can use numbers, variables, or functions that return a
|
|
value. Sub-expressions can be placed between brackets. All operators work
|
|
for real values. Comparisons also work for strings and + concatenates
|
|
strings. (Please note that, contrary to certain languages, both arguments
|
|
to a Boolean operation are always computed, even when the first argument
|
|
already determines the outcome.)
|
|
|
|
<p>
|
|
<b>Example</b>
|
|
|
|
<p>
|
|
Here is an example with some assignments.
|
|
|
|
<p>
|
|
<blockquote>
|
|
<pre>
|
|
{
|
|
x = 23;
|
|
color = $FFAA00;
|
|
str = 'hello world';
|
|
y += 5;
|
|
x *= y;
|
|
x = y << 2;
|
|
x = 23*((2+4) / sin(y));
|
|
str = 'hello' + " world";
|
|
b = (x < 5) && !(x==2 || x==4);
|
|
}
|
|
</pre>
|
|
</blockquote>
|
|
|
|
<!--END-->
|
|
</body>
|
|
</html>
|
|
|
|
<!-- KEYWORDS
|
|
hexadecimal numbers
|
|
expressions
|
|
operators
|
|
binary operators
|
|
unary operators
|
|
bitwise operators
|
|
boolean operators
|
|
logical operators
|
|
--> |