A brief Language Specification of ReoScript.

Language Elements

- Expression
- Statement
- Expression Statement
- Block


An expression contains mathematical operations, variable assignment, function call and some primary expressions. Expression is not a completed statement, it cannot be performed by interpreter directly.

Some expressions can be used like completed statements in JavaScript, for example, an variable assignment expression can be executed as a completed statement directly; In ReoScript, variable assignment should end with a semicolon to become an assign expression statement.

    1 + 2 + 3               // mathematical expression
    a = 10                  // assignment expression
    func()                  // function call expression
    [1, 2, 3]               // array literal expression
    {key: 'value'}          // object literal expression

Expression can be nested within '(' and ')':
    func() * (1 + 2)

Primary Expression

Primary expression is a variable, digits const, object literal, array literal and etc. Primary expression can only be contained in other expressions.
    a                       // variable
    true                    // bool const
    13.5                    // number const
    0xA2F0                  // hex const
    0b1101                  // binary const
    [1,2,3]                 // array literal
    {key:'value'}           // object literal


Statement is a staff that describes a completed command to be executed. Statement usually used to control the program flow, the following statements are available in ReoScript:
  • var local variable declaration
  • assignment
  • if else
  • for, while
  • switch
  • break, continue, return
  • try catch finally

    if (1 + 1 == 2) a = 3;

See Statements.

Expression Statement

Expression Statement is an assignment statement, function call expression or unary expression. Unlike expression, an expression statement can finish an completed operation without other descriptions. Expression Statement should end with a semicolon:
    a = 10;                  // assignment expression statement
    func(1, 2);              // function call expression statement
    return false;            // terminal and return expression statement

Assignment Expression

Syntax of Assignment Expression:
    identifier = ( assignment-expression | expression )

For example:
    a = 10;                  // OK
    a = b = 10;              // OK (right to left)
    10 = 10;                 // error: const value cannot be assigned

Function Call

Syntax of Function Call:
    expression '(' [expression [, expression]*] ')'

For example:
    function func1() { }
    func1();                 // OK

    var func2 = function() { };
    func2();                 // OK

    var arr = [ function() { } ];
    arr[0]();                // OK

    function func3() {
        return function() { }; 
    func3()();               // OK

Unary Expression

Unary Expression is one of following expressions:
    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                       // bitwise not operation
    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);

Note: It is same as ECMAScript/JavaScript, a block is not an variable scope. Only functions have call-scope that decides some variable scopes, see more about Functions.
    if (true) {
        var a = 10;

    console.log(a);          // access variable outside a block

The result is:

See Variables and Functions.

Data Types

The 3 types of data could be managed and processed in ReoScript.

- Primitive type (null, number, boolean, string, object, function)
- ReoScript Object (implemented by .NET type ObjectValue)
- Any .NET Objects (available with DirectAccess)

Primitive type

  1. Object Value

ReoScript uses standard ECMAScript/JavaScript data types and wrapper objects.

The following types are primitive types:

- object
- number (contains char, byte, int, long, float, double)
- string
- boolean
- function

NOTE: typeof keyword can only return the type of an object that is primitive type above.

The following data types are wrapper objects, they have the mapped constructors in .NET side:

- Object
- String
- Function
- Boolean
- Number
- Array
- Date
- Error

See more about wrapper object.


Unary Operators

    -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                      // creating instance operator
    delete                   // delete property from object
    typeof                   // retrieving data type operator

Calculating Operators

    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

Bitwise operators

    ~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

Relation operators

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)

Condition control operator

    boolean-expression ? expression : expression

Index access operator

    expression '[' expression ']' 

Property access operator

    expression '.' identifier


All Keywords

    break                       case                        catch                       continue
    default                     delete                      else                        finally
    for                         function                    if                          in
    instanceof                  import                      new                         null
    return                      switch                      this                        throw
    try                         typeof                      undefined                   var

'undefined' is absolutely same as 'null' keyword in ReoScript.

Keywords not be supported by ReoScript

    debugger                    do                         with

Keywords only be supported by ReoScript


See import keyword.

Reserved Keywords

    public                     protected                   internal                     private

Built-in Objects


Math object contains:
    Math.PI     = 3.141592653589793
    Math.E      = 2.71828182845904
    Math.LN     = 0.6931471805599453
    Math.LN10   = 2.302585092994046
    Math.min = function(a, b) { return a > b ? b : a; };
    Math.max = function(a, b) { return a > b ? a : b; };

    Math.pow(number, pow)

console object


debug object

debug object is available when ScriptDebugger is created for ScriptRunningMachine.
    debug.assert(but, expect)

JSON object

    JSON.parse(string[, handler])
    JSON.stringify(object[, handler])


Built-in Functions

Built-in Standard I/O functions:
    __stdin__                  __stdinln__                 __stdout__                 __stdoutln__

Wrapper object and type converting functions:
    Object                     Function                    String                     Number
    Array                      Date                        Boolean                    Error
    parseInt                   isNaN

Evaluation functions:

Async-calling functions:
    setTimeout                 clearTimeout               setInterval                 clearInterval              

See Enhanced Async-calling.

User interacting functions:
    alert                      confirm                    

Tip: Some built-in objects and functions could be disabled by setting CoreFeatures.

See Also

Last edited Dec 17, 2014 at 12:37 AM by unvell, version 7