Current details of the language - not for beginners - for experts:
A Program
Example:
function void main() // 'click 'pretty' to format
{
int x=0;
x=big(6, 88);
print("biggest is: ");
print (x);
}
function int big(int a, int b)
{
if(a<b)
{
return a;
}
else
{
return b;
}
}
A program is a series of functions. One must be called main.
This particular incarnation enforces a 'straightjacket' of no globals.
Parameters and return is like Java. We use pass-by-value, using types: int, double, string.
A function with no return takes the form:
function void fred(int a)
{
declarations
code
}
Use of return is checked at compile time.
Here is 'hello world':
function void main()
{
alert("hello");
}
// for comments ( slash-star comments not allowed)
Declarations
you MUST initialise vars. You can declare int and string:
int x=3, sum=23;
int y=9;
double d=2.0; // must use a . in double constants
string name="mike";
Statements
if, while, assignment, i/o.
assignment
I / O
display on a pop-up: alert
Display on 'console screen' - print
Display on 'console screen' then move to next line - printLine
The parameter of the above is a single numeric expression, or a single string (can't join strings)
get an int, double or a string from a popup box: getInt, getString, getDouble. (you need to supply a prompt,
and you can type quit to halt the program.)
int n=0;
string s="";
n=getInt("type your age");
s=getString("type your name");
alert(s);
Control Strucs
if/ else, while - like Java BUT
You must not use a ; at end, as in: while(a>0);
(this is flagged as an error)
You MUST use {...} round statements.
'for' - not available yet.
You must use a boolean expr in if, while
Stuck in a loop? - Every few hundred instructions, a pop-up is displayed
warning that the program might be stuck in a loop, asking if you want to quit or not.
Assignment
n=23+x*(3-7)/9;
Normal use of ( .. ) is allowed.
type-checking across = is done.: double = int; is ok. But not int=double;
You can use ++ and --, but only in the form:
n++;
c--;
not within an expression (as in x=3*n++;)
Operators
Subject to change. Currently + - * / % , the java comparison ops: != >= etc,
and the logical ops && !! !
/ gives a float result on the rhs, which = converts to int. : will be fixed soon.
Misc
getRandomInt() - returns a random int in range 0 to 9 inclusive
|