[ Prev | Index | Next ]
Japanese English

Features of the Vnano as a Language

In this page, we explain main features/syntaxes of the Vnano as a script language.


Design Concept of the Language

The language specification of the Vnano ( = VCSSL nano ) is a small subset of the VCSSL which is a programming language having simple C-like syntax, so Vnano also has simple C-like syntax.

Vnano is specialized for embedded use in applications, so compared with other programming languages, many features not necessary for the embedded use are omitted for making the implementation of the script engine compact. It is the concept for giving priority to customizability, maintainability, security, portability and so on than the functionality.

Data Types

Vnano supports only int (=long), float (=double), bool, and string for data-types.

Nems of Data Types Descriptions
int (or long) The 64-bit signed integer type
float (or double) The 64-bit floating point number type
bool The boolean type
string The character string type

Other primitive data types, pointer, struct and class are not supported. On the other hand, array types of the data types in the above table are supported, and you can use it with C-like syntax.

However, please note that arrays in the Vnano (and VCSSL) behaves as value types, not reference types or pointers. The assignment operation (=) of an array behaves as the copy of all values of elements, not the copy of the reference to (address on) the memory. It is the same for character strings. In the Vnano, the "string" type which is the data type to store character strings behaves as the value type, not reference type.

In short, Vnano has no reference types, so all data types in the Vnano are value types. Therefore, the script engine of the Vnano has no garbage-collection (GC) modules.

By the way, if sizes of arrays at the left-hand and the right-hand of the assignment operation (=) are different, the size of the left-hand array will be adjusted to the same size with the right-hand array, by re-allocating memory of the left-hand array automatically.

Variable Declaration Statements

You can describe the variable declaration statements with C-like syntax.

Declaration of scalar variables

The following is an example code of declaration statements of scalar variables (non-array variables) :

The result on the command-line mode is:

1
2.3
true
Hello, World !

However, you can NOT declare multiple variable in 1 statement in the Vnano:

Declaration of Arrays

You can declare and use arrays as follows:

The result on the command-line mode is:

123

However, you can NOT use array initializers in the Vnano:

Control Statements

In control statements of C-like languages, Vnano supports if / else / for / while / continue / break statements.

if and else statements

The folloing is an example code of if and else statements:

The result is:

x is 1.

By the way, in the Vnano, after of if / else / for / while statements must be a block statement {...}. Therefore, you can NOT write single statement which is not enclosed by braces { } after the if statement as follows:

However, for else statement at just before of if statement (so-called "else if"), braces { } can be omitted.

for statement

The folloing is an example code of for statement:

Please note that braces { } can not be omitted. The result is:

i=1
i=2
i=3
i=4
i=5

while 文

The folloing is an example code of while statement:

Please note that braces { } can not be omitted. The result is:

a=500
a=377
a=254
a=131
a=8

break statement

The folloing is an example code of break statement:

The result is:

i=1
i=2
i=3

continue statement

The folloing is an example code of continue statement:

The result is:

i=1
i=2
i=4
i=5
i=7
i=8
i=10

Expressions

Elements of expressions

The expression is the set of tokens consists of operators, operands, and parentheses ( ), where operands are literals or identifiers (variable names and function names). For example:

In the above expression, + and * are operators, x and 2 and 3 are operands, ( ) are parentheses. In the Vnano, as the same with the C programming language, the symbol of the assignment "=" is an operator, so the following is also expression:

An expression alone can be a statement as "expression statement". In addition, an expression can be described as a part of other statements, e.g., a condition expression of an if statement.

Operators

The following is the list of operators supported in the Vnano:

Operator Precedence Syntax Associativity Data Types of Operands Data Type of Result
Function Call
( ... , ... , ... )
1000 multiary
(multiary)
left any any
Array Indices
[ ... ][ ... ][ ... ]
1000 multiary left int any
++ 1000 postfix left int int
-- 1000 postfix left int int
+ 2000 prefix right int int
- 2000 prefix right int int
! 2000 prefix right bool bool
* 3000 binary left int, float int, float (See the above table)
/ 3000 binary left int, float int, float
% 3000 binary left int, float int, float
+ 3100 binary left int, float, string int, float, string
- 3100 binarytd> left int, float int, float
< 4000 binary left int, float bool
<= 4000 binary left int, float bool
> 4000 binary left int, float bool
>= 4000 binary left int, float bool
== 4100 binary left any bool
!= 4100 binary left any bool
&& 5000 binary left bool bool
|| 5100 binary left bool bool
= 6000 binary right any any
*= 6000 binary right int, float int, float
/= 6000 binary right int, float int, float
%= 6000 binary right int, float int, float
+= 6000 binary right int, float, string int, float, string
-= 6000 binary right int, float int, float

The value type (the data-type of the operated value) of binary arithmetic operators (*, /, %, +, -) and compound arithmetic assignment operators (*=, /=, %=, +=, -=) are decided by the following table:

- Data Types of the Results of Arithmetic & Compound Arithmetic-Assignment Operations -
Type of Operand A Type of Operand B Type of Operated Value
int int int
int float float
int string string ( available only for +, += )
float int float
float float float
float string string ( available only for +, += )
string int string ( available only for +, += )
string float string ( available only for +, += )
string string string ( available only for +, += )

Where you can choose the right or the left operand as the operand A (or operand B) freely in the above table.

Function (Internal Function)

You can declare and call functions in the Vnano script code with C-like syntax. However, this script engine does not support recursive calls of functions, because allocations of local variables are implemented in very simple way.

In the Vnano, build-in functions provided by the outside of the script are referred as "external functions", so functions declared in the script as we explain in this section are also referred as "internal functions" in that context.

Scalar input/output functions

The following is an example code of the function of which arguments and the return value is scalar (non-array) values:

The result on the command-line mode is:

3

Array input/output functions

If you want to return an array, or get arrays as arguments, the following code is an example:

The result is:

z[0]=3
z[1]=5
z[2]=7

Please note that, as we mentioned in the section of Data Types, arrays in the Vnano (and VCSSL) behaves as value types, not reference types or pointers.

Assignment operations of arguments and the return value behaves as the copy of all values of elements, not the copy of the reference to (address on) the memory. In addition, the size of the array will be adjusted automatically when an array having different size will copied to it.

Therefore, we omitted to specify size of array declarations in several places in the above code, e.g.: "int a[]", "int b[]", and "int z[] = fun(x, y, 3)".


Japanese English
Index
Announcement (Twitter)