NEIL, a simple programming language for Nuboj®
A real Nuboj system with obfsucated data

NEIL, a simple programming language for Nuboj®

During last weeks, I designed NEIL, a simple programming language to be integrated in Nuboj, the IOT Business Platform of Tempestive.

In the past we integrated several existing languages (C#, Java, JavaScript, and Python) in the platform but managing the safety of the execution context was difficult. Moreover, these languages are known by programmers or scientists but difficult to manage by power users. Their syntaxes are complex and all of them have quirks that are not well known.

The main goals of NEIL language are:

  • Simple syntax.
  • Give some sort of extensibility to the users but limit the execution context to ensure safety of platform. Safety means that the user cannot make damages to the platform. 

There are several usage scenarios. For example, sometimes you need to show a value that is calculated as a composition of other values. In the figure you can see some widgets that show real time values that comes from a device (data are obfuscated for privacy reasons). Widgets are placed and defined by the end user.

Widgtes showing "real time" values from the device

The widget called "ERROR SWITCH" shows the value of an error variable. The error variable is calculated using a simple, yet powerful formula expression defined in NEIL. NEIL is fast! There is no difference with the native code of Nuboj.

NEIL is a quite simple language targeted to end users. It was designed to add small snippets of code into Nuboj. The language is like a structured BASIC (Pascal-like) language. The keywords are case-insensitive.

Variables are divided in two flavors: local or external.  

Local variables are limited to the snippet scope. Local variables have dynamic types. The runtime tries to automatically convert types.

External variables are used to communicate with the host system (Nuboj). External variables have static type. This is an area where a safe mechanism in place. External variables have a static defined type because the type is decided externally. Changing the type should be dangerous and by this is forbidden. NEIL tries to convert automatically the value assigned to the type of the external variables using a coercion mechanism. 

There is some conversion statement to convert explicitly the type of an expression. This is an explicit casting mechanism.

NEIL tries to limit the loop to avoid infinite loop trap. The only loop statement available is the FOR TO STEP statement. The max number of iterations is l000. This is enforced in the inner loops, too. In other words, if you use a loop with an inner loop the sum of the two iterations can’t be more than 1000. This is more than enough for the purpose of the language.

A sample of NEIL source code:

[VAL1] = 333            
[VAL2] = 222.2
[VAL3] = true
[VAL6] = "ciao \"CIAO\" ciao"
[HH] = boolean("true")
 
# local variable
hellos = ""
 
# assignment to not existent variable
[STATUS] = "OK"
[STATUS2] = "OK"
 
# for loop
FOR I=0 TO ([NUM_VAR] + 18) 
	# create a local variable containing a name to use indirect addressing 
	varName = "VAR_" + STR(I)
	# indirect variable used
	hellos = hellos + " " + {varName}
	# if
	IF {varName} == "error" THEN
		[STATUS] = "ERROR"
		BREAK
	END
	{varName} = {varName} + " world"
END

Some other interesting features are:

  • From the language grammar point of view, NEIL has only a well-known bunch of predefined functions. 
  • The execution of some statements is authorized only for specific users (defined using the role management feature of Nuboj).
  • External variable can be addressed directly (using the syntax [VARNAME]) or indirectly (using the syntax {expr} where expr must return the name of an external variable).
  • Types managed by NEIL are string, long (64 bit) integer numbers, int (32 bit) integer numbers, double precision floating numbers, datetime, timestamp (UNIX epoch time expressed in ms), Guid.
  • Datetime and timestamp use UTC time zone.

NEIL was developed using ANTLR4 and C# on .NET Framework and .NET Core. It is compiled and it is fast as C#.

Non avevo dubbi che avresti "escogitato" qualche altra diavoleria!

Like
Reply

Excellent Max, well done as usual 👍

Like
Reply

To view or add a comment, sign in

More articles by Massimo Santin

Others also viewed

Explore content categories