FScript

by murlen
[Previous] [Contents] [Next]

Language

Overview

The FScript language is very simple it supports four data types int (Integer), string (String), double (Double) and a special type object (see later for documentation on the 'object' type.. The language is case sensitive, and both variables and functions need to be declared before use.

Comments

In normal scripting language fashion comments are indicated by a '#' - this may either start a line, in which case the entire line is regarded as a comment, or be placed anywhere in the line - in which case any characters after the '#' are ignored.

Variable Declaration

Variables must be declared before use, the syntax is :

int|string|double <varname>[=<expression>][,<varname>*]

For example

	int counter,b,n
	string name,address
	double value

It is also possible to assign a value to a variable during declaration (like java) for example:

	int counter=0,b,c
	string link,path="/home/"+username+"/mydir",tmpstring

Variable names must start with A-Z or a-z, but numbers, "." and "_" can also used in variable names e.g

	int valid9_variable.name1

Strings

Strings are enclosed in double quotes, and may contain the special tokens \n, \r, \t, \\ and \"to include a new line, carriage return, tab, backslash and double quote character respectively.

Line continuation can be indicated by ... e.g.

	a=thisLongNamedVariable+thatLongNamedVariable/...
	anotherLongNamedVariable

Conditional Execution

The sole construct for conditional execution is the 'if' statement.

There are two forms of 'if' statements, multi line and single line. Multi-line If statements may optionally contain 'elsif' and 'else'clauses. The 'then' keyword is optional for the multi-line form of 'if' The syntax is :

	if <expression> [then]
<statements>
	[else
<statements>
	]
	[elsif <expression>
<statements>]
	endif

For example

	if a>300 
		a=a-145
		b=b+3
	elsif a > 500
		a=a-245
		b=b+4
	else
		a=a+10
	endif

The single line form of 'if' is used if only one statement needs to be executed by the 'if'. There is no provision for 'else' or 'elsif' and the 'then' keyword is not optional.

For example:

	if a>300 then a=0

Note that both elsif and elseif are valid for use in if statements.

Loops

The only loop construct supported by FScript is while. The syntax is :

	while <expression>
<statements>
	endwhile

For example

	while count<500
		count=count+1
		value=value+calcvalue(count)
	endwhile

Functions

FScript supports the declaration of functions that may return a parameter, and accept a pre-defined set of parameters. Functions may be recursive. It is not legal to nest functions in code (i.e. declare functions within functions). Local variables may be declared within the function scope. Within a function global scope variables are available, and in the event of a naming conflict between the global and local scope, the local scope wins. The 'return' keyword can be used to return a value to the calling code.

The syntax of a function declaration is:

	func <function name>([[<param type><param name>][,]]*)
<statements>
	endfunc

For example

	func test(int a,string b,double c)
		int count
		while count<10
			count=count+1
		endwhile
		return count
	endfunc

Arrays

FScript does not directly support arrays, however it does support array like access to variables that are defined in extensions/subclasses of FScript The syntax is the same as that found in Java (and C). e.g.

<varname>[<subscript>] 

However in FScript the subscript can be any supported variable type (string,int or even double - although I doubt that has many uses).

For Example:

	thisvar[n]=thatvar[2]
	MyFunction(thisvar[n+1]) 

In the above example the variables thisvar and thatvar are supplied by the application embedding FScript

Operators

The usual selection of math and logic operators are supported:

+ - * / % == != >= <= <>&& || ! ( ) 

As of FScript 0.8 operator priority is recognized so constructs like 3+4*7 will work as expected.

Not all operators are valid for all types

The mathematical operators (+ - * / %) are valid for all numeric types. The operator + is also valid for string operands (which concatenates the strings).

The equality & inequality operators ( == !=) are valid for all types. These operators yield an integer 1 or 0 as a result. All logical operators use the 'C' convention of false being zero and true being any non-zero value.

The comparison operators ( ><>= <=) can be used to compare any type, again as long as both operands are the same type. The result is (again) a 1 or 0 integer.

The boolean logic operators ( && || ) work only with integer operands.

Notes

Carriage returns are significant in FScript, so :

	if a>=100 a=100 endif

will not work.

Also FScript is somewhat sensitive about the interpretation of numbers, for example '15' will always be interpreted as an integer, and will cause an error if it is assigned to a double variable, use '15.0' to force the value to be interpreted as a double.


[Previous] [Contents] [Next]

created with DocLite