The FramScript syntax and semantics is based on C, with the following basic differences:
Before execution by FVM (Framsticks Virtual Machine), FramScript source code is first translated to FVM assembler source code, and then transformed to FVM machine code.
(brackets [] denote optional parts)
if (expression) statement; [else statement;]
for (expression;expression;expression) statement
while (expression) statement;
switch(expression) { case constant: statements... default: statements... }
{ statement; [statement;] }
return [expression];
break [level];
continue [level];
label_name:
goto labelname[:];
var name[=expression];
function name([parameter_names]) {statements}
asm { source code for FVM }
Remarks:
Variables must be declared before they are used. Unlike in C, the declaration does not specify the variable type.
Variables are untyped, but the values are typed. The value can be of one of 5 types: integer, floating point, string, object reference or the special empty value (null).
Some operators can act differently depending on the value type.
Example:
var int=123, float=1.23, string="123"; int+=0.0001; // result = 123 float+=0.0001; // result = 1.2301 string+=0.0001; // result = "1230.0001"
Most of the C language expressions are also valid in FramScript. This includes arithmetic and logical operators, parentheses, function calls, and assignments. Moreover, the following FramScript specific opearator are available:
Examples:
var two=Math.sqrt(4); // static object name (Math) var v=Vector.new(); // static object name (Vector) v.add(123); v.add(456); return v.get(1); // variable containing object reference (v) var v=[123,456]; return v[1]; // vector [] notation
Functions are defined as follows:
All parameters are passed by value (copied). However, an argument (or a return value) can contain object reference, in which case it is the reference that is actually copied.
A function can return a value to the caller using the "return expression;" statement. If a bare "return;" is used, the return value is undefined.
Example:
function factorial(n)
{
if (n<3) return n;
return factorial(n-1)*n;
}
See FramScript reference to learn about internal Framsticks classes, methods, and variables. You can also use the class browser (available both in GUI and command-line interfaces).