-
Notifications
You must be signed in to change notification settings - Fork 35
Language Specification
A brief of Language Specification of ReoScript.
- Expression
- Statement
- Expression Statement
- Block
An expression contains Mathematical operations, variable assignment, function calling and etc. Expression should not end with semicolon:
1 + 2 + 3
a = 10
func()
Expression can be nested within '(' and ')':
func() * (1 + 2)
Expression could not be executed directly, it should be contained by Statement or Expression Statement.
Statement is language control syntax, commonly it indicates that what the code should be executed in what cases. The following statements are available in ReoScript:
- if else
- for, while
- switch
- break, continue, return
- try catch finally
e.g.
if (1 + 1 == 2) a = 3;
See Statements.
Expression Statement is an assignment statement, function call expression or unary expression, etc. Usually it means that an expression it could finish an completed operation without other descriptions. Expression Statement should end with a semicolon:
a = 10; // assignment expression
func(1, 2); // function calling expression
return false; // terminal expression
Syntax of Assignment Expression:
identifier = assignment-expression [= assignment-expression]*
Syntax of Function Call:
identifier ( [expression [, expression]* )
Unary Expression is one of following expression:
i++ // post-self-increment-expression, equals i = i + 1, calc after accessing
++i // pre-self-increment-expression, equals i = i + 1, calc before accessing
-i // minus operation
~i // binary operation, bitwise not
new expression // create instance (where expression should be function)
typeof expression // retrieve type of object
Statement and Expression Statement grouped in a scope within '{' and '}' is called Block:
{
a = func() * (1 + 2);
console.log(a);
}
Note: It is same as ECMAScript/JavaScript, a block is not a variable scope. Only functions has call-scope, see more about Functions.
if (true) {
var a = 10;
}
console.log(a); // access variable outside a block
The result is:
10
The 3 kind of data type are managed and can be processed in ReoScript.
- Primitive type (null, number, boolean, string, object, function)
- ReoScript Object (implemented by .Net type ObjectValue)
- Any .Net Objects (available with DirectAccess)
ReoScript uses standard ECMAScript/JavaScript data types and wrapper objects.
The following types are primitive type:
- object
- number (contains single, int, long, float, double)
- string
- boolean
- function
NOTE: typeof keyword can only return the primitive type above.
The following data types are wrapper objects, they all has mapped constructor:
- Object
- String
- Function
- Boolean
- Number
- Array
- Date
- Error
See more about wrapper object.
-a // minus operator
++a // pre-self-increment operator (calc before accessing)
a++ // post-self-increment operator (calc after accessing)
--a // pre-self-decrement operator (calc before accessing)
a-- // post-self-decrement operator (calc after accessing)
a() // function call operator
new expression // creating instance operator
typeof expression // retrieving data type operator
a + b // add a and b, or combine object a and b
a - b // subtract b from a
a * b // multiply a by b
a / b // divide a by b
a % b // get the remainder of division of a by b
~a // bitwise NOT - Inverts the bits of its operand.
a & b // bitwise a AND b
a | b // bitwise a OR b
a ^ b // bitwise a XOR b
a << b // shift a by b bits to the left
a >> b // shift a by b bits to the right
All relation operators return a boolean result.
a > b // check whether a is greater than b
a < b // check whether a is less than b
a == b // check whether a is equal to b
a >= b // check whether a is greater than or equal to b
a <= b // check whether a is less than or equal to b
a === b // strict compare two operands (value and type)
a !== b // strict compare two operands NOT (value and type)
boolean-expression ? expression : expression
break case catch continue
default delete else finally
for function if in
instanceof import new return
switch this throw try
typeof var while
debugger do with
import
- [How to run script in .Net program](How to use ReoScript to run JavaScript)