The Fabl Manual
Function Index
Class Index
Globals Index
Libraries
Contents

Title Page
Introduction
Sample Code
Architecture
Syntax
Strong Typing
Polymorphism
Operators
Help
Errors
Configuration
RDF
Namespaces
Owl
Datatypes
Resources
Dot ops
Coercion
Type Casting
nil

Types
string
id
int
double
boolean
Literal
Containers
Functions
void

Home
Regarding
The Path
Classes
Delegation
Functional Values
Read/Write
Load/Store
Libraries
Imports
CGI
Syntax

The syntax of Fabl is modeled on JavaScript. The only substantial syntactic difference between Fabl and JavaScript is that in Fabl, unlike JavaScript, variables are typed. This affects only "var" statements, and the header line of function definitions, in which the function is assigned a type, as are the input variables. Here are some examples:

var int a,b,string d;
a = 44;
b = 33;
var c = 1;
a+b+c;
->78;
d="hello";
d;
->hello

int function twice(int x)
{
   return 2 * x;
} 

twice(4); 
->8

Note that a type in a var statement applies to each of the variable names in a commafied sequence preceding the next occurence of a type. Thus,

var int a,b,string c;

is equivalent to

var int a;var int b;var string c;

Also note that the statement

var <variable-name v> = <expression E>;

introduces a new variable v whose type is the type of E, and whose initial value is the value of E.

In the current release, initial values can be assigned in var statements only at top-level, not within function definitions.

Rules for comments are the same in Fabl as in JavaScript: a double slash // comments out the rest of the line on which it appears, and /* starts a comment which is terminated by */.

In the initial Fabl release, several syntactic constructs from JavaScript are lacking, but will be added in future releases; for example the switch statement and the break construct.

Here are the syntactic constructs present in Fabl, given by example rather than definition. See the ECMAScript documentation for a more formal treatment.

Block statement

A sequence of statements contained in curly brackets, and delimited by semicolons; to be executed sequentially.

var a = 23;
var int b,c;

{
b = a + a;
c = b + b;
writeln(c);
}
-->92

Conditional statement

An if-then or if-then-else

var a = 24;

void function example(int n)
{
if (n > 4) writeln("yes");
if (n == 5) writeln("yes"); else writeln("no");
}

example(5);
-->yes
-->yes
example(6);
-->yes
-->no

While statement

Executes a statement repeatedly while a condition is true.


var i = 0;

while (i < 10) {writeln(i);i = i + 3;}

-->0
-->3
-->6
-->9

For statement

for (<initialization>;<condition>;<update>) <statement>;
is equivalent to
{
<initialization>
while (<condition>) {<statement>;<update>}
}

For example

var int i;

for (i = 10;i<30;i = i + 5) writeln(i);

-->10
-->15
-->20
-->25

Return statement

Returns from a function, with or without a value.

void function noop()
{
return;
}

int function two()
{
return 2;
}