C-SMILE

Version:1.0

Syntax

Packages

Each source file is a compilation unit also known as package and consists of:

<package-definition>
[ <import-definition>, ... ]
[ <package-variable-definition>, ... ]
[ <package-constant-definition>, ... ]
[ <package-function-definition>, ... ]
[ <class-definition>, ... ]
<package-definition>: package <name> ;
<import-definition>: import <package-name>[ ,  ... ] ;
<package-variable-definition>: var <name> [ = <expression> ] [  ,  ... ] ;
<package-constant-definition>: const <name> =  < expression> [ , ... ]  ;
<package-function-definition>: function <name> (  [ <argument-name> [ , ... ] ]  ) { <statement>. }

Only one package definition is allowable per compilation unit (file).

Classes

<class-definition>:     class <name> [ : <base-class-name> ] { class members... }

Where class members are:

Instance variable (member field): var <name> [ , <name> ] ;
Class static variable: static var <name-with-initialization> [ , < name-with-initialization > ] ;
Class constant: const <name-with-initialization> [ , < name-with-initialization > ] ;
Enumeration: (proposal) enum <name> { <name-with-initialization> [ , < name-with-initialization > ]  }
Function (instance method): function <name> ([ <argument-name> [ , ... ] ] ) { <statement>... }
Class function: static function <name> ([ <argument-name> [ , ... ] ] ) { <statement>... }
Property-function: property <name> ( <argument-name> ) { <statement>. }
Class property-function: static property <name> ( <argument-name> ) { <statement>... }

Statements

if ( <expression> ) <statement> [ else <statement> ]
while ( <expression> ) <statement>
do <statement> while ( <expression> )
for ( [<expression>] | [var <name-with-initialization>] ; [<expression>] ; [<expression>] ) <statement>
for ( [<expression>] | [var <name-with-initialization>] in [<expression>] ) <statement> // not in this version
switch(<expression>) { case <expression>:<statement> [...] default: <statement> }
break;
continue;
return [ <expression> ] ;
[ <expression> ] ;
{ <statement>... }
var <name-with-initialization> [ , ... ] ;
synchronized (<expression> ) <statement>
try <statement> catch ( <name> ) <statement>

Expressions

<expression> , <expression>
<lvalue> = <expression>
<lvalue> += <expression>
<lvalue> -= <expression>
<lvalue> *= <expression>
<lvalue> /= <expression>
<lvalue> %= <expression>
<lvalue> &= <expression>
<lvalue> |= <expression>
<lvalue> ^= <expression>
<lvalue> <<= <expression>
<lvalue> >>= <expression>
< expression> ? <expression (if-true)> : <expression (if-false)>
<expression> || <expresssion>
<expression> && <expression>
<expression> | <expression>
<expression> ^ <expression>
<expression> & <expression>
<expression> == <expression>
<expression> != <expression>
<expression> < <expression>
<expression> <= <expression>
<expression> >= <expression>
<expression> > <expression>
<expression> << <expression>
<expression> >> <expression>
<expression> + <expression>
<expression> - <expression>
<expression> * <expression>
<expression> / <expression>
<expression> % <expression>
<expression> instanceof <class-name>
<expression> @ <expression>   
// Object-method reference creation.
// Left side has to be object.
// Right side - reference to function which belongs to object's class.
- <expression>
! <expression>
~ <expression>
typeof <expression>
++ <lvalue>
--<lvalue>
<lvalue> ++
<lvalue> --
new <class-name> ( [ <argument-list> ] )
<expression> ( [ <arguments> ] )
<expression> . <name>
<expression> '[' <expression ']'
( <expression> )
<variable-name>
<number-constant>
<string-constant>
<array-constant>
<map-constant>
null
true
false

Primitives

<package-name>is just a <name>

<class-name> is [ <package-name> :: ]<name>

<variable-name> is [ <class-name> :: ] <name>

<name> is any sequence of characters where first character must be letter or '_' (underscore) and all subsequent characters are letters, numbers or underscore excluding reserved words.

<lvalue> is one of:

<arguments-count> is special variable with the name '$$'. Being used inside function body it reports number of arguments passed to the function 'de-facto'.        

<argument-reference-by-number> is '$'<integer-expression>. Used for access to the argument of the function by its number.

Constants

<numeric-constant> is one of <decimal-number>, <hexadecimal-number> or <char-constant>, where: 

<decimal-number> is [sign] decimal digits [. decimal digits] [ {d | D | e | E} [sign] decimal digits ]
<hexadecimal-number> is  0 x | } hexadecimal digits
<char-constant> is ' character ' ( character enclosed by apostrophes ) Example: 'a'

Proposal - "colored" values: to support additional meta-tags for values - sort of measurement units e.g. 1444in or 1444:in. C-SMILE core will support only storing/retreval this meta-info. Therefore 1440in will be just integer with meta info "in". Examples:
         var width = 1444:cm;
         var color = 0xff0c0c:rgb;
         var name1 = "MightyMouse":utf8;
Meta-tag is part of value (not a part of variable);

<string-constant> is sequence of characters enclosed by double quotes. Example: "hello world"

<array-constant> is '[' [ expression [ , ... ] ] ']'

<map-constant> is '{' [ expression(key) : expression(value) [ , ... ] ] '}'

TIL Runtime

All standard features common to all supported platforms are assembled into classes and functions of built-in std package.

Standard classes are:

std::array

Dynamic array of values

std::thread

Execution thread

std::string

String is dynamic array of chars

std::mutex

Handling critical sections of code. Primarily used in synchronized statement

std::date

Represent date and time with millisecond precision between 29000-01-01 BC and 29000-01-01 AD.

std::socket

Network interaction between computers (global domain) and processes (local domain)

std::map

Hash table and sparse array

std::node

File system node (file or folder)

std::math

Mathematical functions (not implemented yet)

std::stream

Handling input/output from/to different sources: files, sockets, blobs and strings.

std::regexp

Regular expression.

std::blob

Binary buffers of any sort with memory mapped files support

std::class

Class description. Reflection. (not implemented yet)

 

Standard functions and variables:

std::in

Public variable. Input stream of application. Can be null if application doesn't support console mode interface.

std::out, std::err

Public variables. Output streams of application.

std::gc()

Function. Do garbage collect.

std::print(...)

Print arguments to std::out

std::compile(...)

Compile source file into bytecode. (not implemented yet)

std::load(...)

Load file and execute it. (not implemented yet)

std::eval(...)

Evalute function. (not implemented yet)

std::locale

Public variable. Set or retrieve current process locale.

std::os

Public variable. Read-only. OS name. (check it, may be to move them in package runtime? )

std::os_vendor

Public variable. Read-only. OS vendor name. (check it)

std::os_version

Public variable. Read-only. OS version number. (check it)

 

TBC...

Andrew Fedoniuk.

http://terra-informatica.org