Expressions
Expressions in AXE are programs that can operate on an AXE document or perform
independant calculations.
There are two places you can use expressions:
The only difference between these two contexts is that in the calculator,
expressions have no access to any particular document. When used from the
library, they can use functions (described below) to read and write the
currenct document. Expressions have a simple, vaguely C-like syntax.
AXE comes with some sample expressions already in the expression library. These
are a good place to start.
Literals:
Literal numbers and strings are specified as in C. To specify the number 17,
you could enter 17 or 0x11 or 0b10001 or
0c21 or 17.0. Points to note:
Internally, all numbers are converted to double-precision floating point
numbers, except for bitwise operations.
You can put a minus sign before any number.
'0c' is the prefix for octal.
Variables:
Variables need not be declared. They come into existance whenever they are
assigned to. Thus a=100*3; creates a variable 'a' and assigns the
value 300 to it.
Operators:
A C-like range of operators is supported. The ++ and -- operators are not
supported. Operator precedence is a little annoying; The use of parentheses is
strongly advised.
Operators such as & and ^ that perform binary operations first convert the
operands to integral types, then perform the binary operation, then convert
them back to doubles.
The full range of operators is as follows:
+ - * / % ~ & | ^ << >> && || ! == != < > <= >= = +=
-= *= /= |= &= ^=
Arrays:
Variables become arrays if they are treated as arrays. Thus a[10] = 109;
creates an array 'a' and assigns the value 109 to slot '10' in it. Array
indexes may be expressions; thus b=10; a[b*2]=1; assigns the value
1 to slot '20' in array 'a'.
Functions:
Functions are called as in C, with comma-separated arguments enclosed in
parentheses. You may not define your own functions; you can only use the
built-in ones. Future versions of AXE will probably use a different, much more
powerful scripting language.
Statements:
Statements end with a ; as in C. If you forget the ;, the Calculator will try
and add one for you.
Loops:
Loops look like C loops. To set 'i' to every value from 0 to 99 inclusive, do
this:
for(i=0;i<100;i+=1)
{
array[i]=i;
}
Note that as there is no ++ operator, we had to write i+=1.
Conditionals:
The only conditional is 'if'. It is used as in C:
if (i > (b+100))
{
msgbox("i is a lot bigger than b");
}
else
{
msgbox("i isn't really all that big");
}
The built-in functions are divided into general maths functions, and functions
that are specific to AXE and operate on the document itself. Mathematical
functions are:
sqrt(n) Square root of n
sin/cos/tan/asin/acos/atan(n) Sine, cosine etc of n
byteswap2(n) Convert n to a WORD, call htons() on it, and return the
resulting value.
byteswap4(n) Convert n to a DWORD, call htonl() on it, and return the
resulting value.
max(n,m) Returns the greater of n and m
min(n,m) Returns the lesser of n and m
pwr(n,m) Returns n to the power of m. m must be an integer >= 2
AXE-specific functions are:
msgbox("s") Puts up a message box with message s
end/exit(n) Stop evaluating, and make n the final result of the
evaluation
togmark(n) Toggles the 'mark' flag for byte 'n'
setmark(n,m) Turns the 'mark' flag for byte 'n' on if m is non zero;
otherwise turns it off
setmark(n) Returns 1 if 'mark' flag for byte 'n' is on; otherwise
returns 0
togdiff(n) Toggles the 'diff' flag for byte 'n'
setdiff(n,m) Turns the 'diff' flag for byte 'n' on if m is non zero;
otherwise turns it off
setdiff(n) Returns 1 if 'diff' flag for byte 'n' is on; otherwise
returns 0
bookmark("s", n) Makes a bookmark called s at offset n
getsize/docsize() Returns the number of bytes in the document
getselstart() Returns the offset of the first selected byte
getselend() Returns the offset of the last selected byte
disableundo() Disables undo, which makes these scripts run much faster
enableundo() Re-enables undo -- don't forget to do this before the
script exits, unless you hate having an undo buffer
get1u(n) Gets a 1-byte unsigned value at offset n
get2u(n) Gets a 2-byte unsigned value at offset n
get4u(n) Gets a 4-byte unsigned value at offset n
get1s(n) Gets a 1-byte signed value at offset n
get2s(n) Gets a 2-byte signed value at offset n
get4s(n) Gets a 4-byte signed value at offset n
getflt(n) Gets a single-precision floating point value at offset n
getdbl(n) Gets a double-precision floating point value at offset n
set1u(n,m) Sets the 1-byte unsigned value at offset n to m
set2u(n,m) Sets the 2-byte unsigned value at offset n to m
set4u(n,m) Sets the 4-byte unsigned value at offset n to m
set1s(n,m) Sets the 1-byte signed value at offset n to m
set2s(n,m) Sets the 2-byte signed value at offset n to m
set4s(n,m) Sets the 4-byte signed value at offset n to m
setflt(n) Sets the single-precision floating point value at offset n to
m
setdbl(n,m) Sets the double-precision floating point value at offset n
to m