[ Prev | Index | Next ]
Japanese English

Vnano as a Language

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


What is Vnano?

The Vnano (VCSSL nano) is a programming language having simple C-like syntax. Language specifications of the 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.

How to Run Example Scripts

To run example scripts on this page, copy code of a script and paste it on any text-editor, and save as a file of which file name ends with the extension ".vnano". There are multiple methods to run it, so select from the followings:

Use VCSSL Runtime

Most easy way is: Download and launch the VCSSL Runtime, and then choose the script file saved the above to run it. Syntax/features of the Vnano is a subset of the VCSSL, so you can run Vnano scripts by the VCSSL Runtime. All features of Vnano Standard Plug-ins are available by default. In addition, you can also run scripts by using "vcssl" command on your command-line terminal.

Use RINPn

If you are an user of a programmable calculator software RINPn, you can run Vnano scripts on it easily. Put a Vnano script into the folder of RINPn, and input its file name to RINPn to run it. For a script locating in other folder, you can run it by inputting its file path. On RINPn, all features of Vnano Standard Plug-ins are available by default.

Use Vnano Engine

The last method is: run a script by using command-line mode of the Vnano Engine, which is the script engine of the Vnano. On this method, you can use various options helping development, so it is recommended for developers of apps using Vnano. However, Vnano Standard Plug-ins providing fundmental features (containing "print" function) are not bundled by default, so it requires to introduce it by yourself. How to do it is explained by the document of command-line mode.

That's all about how to run example scripts. Let's move onto the main subject: language features and syntax of the Vnano.

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. Because of that, 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 {...}. So 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" statement

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

An expression is a series of tokens to describe operations, consists of operators, operands, and parentheses ( ). An expression can be a statement as an "expression statement" by itself. In addition, expressions can be parts of other kinds of statements, e.g.: a condition expression of "if" statement.

As syntactic elements of expressions, "operators" are symbols of operations, e.g.: "+", "-", and so on. Values to be operated are called as "operands", e.g.: 1 and 2.3 for "1 + 2.3". More specifically, as syntactic elements, values directly described such as "1", "2.3" and so on are called as "literals". Besides literals, identifiers of variables (e.g.: "x"), and results of other operations can be operands.

For example:

In the above expression, "+" and "*" are operators, "x" and "2" and "3" are operands, "(" and ")" are parentheses.

However, the result of the addition "(x + 2)" is also an operand for the "*" operator, so the word "operands" is ambiguous. For disambiguation, sometimes minimum units of operands such as "x" and "2" and "3" are syntactically called as "leaf operands".

By the way, in the Vnano, as the same with the C programming language, the symbol of the assignment "=" is an operator, so the following is also an expression:

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
Cast
(...)
2000 prefix right any any
* 3000 binary left int, float int, float (See the next 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.

Note that, the Vnano does not support recursive calls of functions, because allocations of local variables are implemented in very simple way in the script engine of the Vnano.

Also, in the Vnano, functions declared in scripts are called as "internal functions", in contrast to that, functions provided by plug-ins connectet to the script engine are called as "external functions".

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)".

Formal parameters and actual arguments

The parameter-variable declared in a function declaration like as "a" in the following example is called as "formal parameter". In contrast, the value/variable passed to a function like as "x" in the following example is called as "actual argument".

Call by value

By default, change of values of formal parameters in functions don't affect to values of actual arguments of caller-side, For example:

The result is:

x = 0
y[0] = 0
y[1] = 0
y[2] = 0

As demonstrated by the above result, actual arguments of caller-side "a" and "b" have not changed although formal parameters "x" and "y" changed in the function "fun".

This is because, by default, actual arguments will be simply copied once to formal parameters when the function is called. This behaviour is called as "call-by-value".

Call by reference

If you want to affect changed values of formal parameters in functions to values of actual arguments of caller-side, describe the symbol "&" before the name of formal parameters in declarations of them. For example:

The result is:

x = 2
y[0] = 10
y[1] = 11
y[2] = 12

The memory-reference to data of a formal parameter declared with "&" will be shared with reference to data of an actual argument.

Hence, as demonstrated by the above result, after values of formal parameters "x" and "y" in the function "fun" changed, actual arguments "a" and "b" of caller-side also changed to same values with "x" and "y". This behaviour is called as "call-by-reference".


Japanese English
Index
News

The Internal Architecture of Exevalator
2022/05/04 - Explaining the internal architecture of Exevalator, which is an open-source expression calculator library we released last month.

Released "Exevalator": A Multilingual & Copyright-Free Expression Evaluator Library
2022/04/16 - We have released a new library "Exevalator" which enables you to calculate values of numerical expressions stored in string variables, on Java/C#/C++/Rust programs.

Announcement (Twitter)