Skip to content

Language Specification

Jing Lu edited this page May 24, 2013 · 52 revisions

A brief of Language Specification of ReoScript.

Language Elements

  • Expression
  • Statement
  • Expression Statement
  • Block

Expression

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

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:

e.g.

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

See Statements.

Expression Statement

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

Assignment Expression

Syntax of Assignment Expression:

identifier = assignment-expression [= assignment-expression]*

Function Call

Syntax of Function Call:

identifier ( [expression [, expression]* )

Unary 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

Block

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

Data Types

3 internal types of data are 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

Object Value

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

The following data types is primitive type:

  • object
  • number (contains single, int, long, float, double)
  • string
  • boolean

And the following data types is wrapper object, it all has mapped constructor:

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

See more about wrapper object.

Operators

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 expression     // creating instance operator
typeof expression  // 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

Keywords

See Also

  • [How to run script in .Net program](How to use ReoScript to run JavaScript)

Clone this wiki locally