DNM Script

Contents

Overview

DNM Script is a simple procedural scripting language in an early development phase, originally designed as the scripting solution for Ac Browser Plus.

It is planned that the DNM manual will eventually be available online only and one should check this location for an updated help.

Below, we have an example of a simple DNM script which shows the text "Hello World"  :

MessageBox("Hello World!");

Important note about wrong evaluation order of expressions

The problem

DNM is an abbreviation for "(I) Don't Know Math". Well, DNM actually can calculate things, it only has problems with evaluation order of expressions. It usually calculates from left to right, or vice-versa, depending upon mood. And sometimes from middle, to the left, and then to the right. You never know.

For example, most people (and compilers) know, that 2+2*3 is 8, because first we multiply 2 and 3 and then add 2.

This is not true for DNM Script - in this case, it will be 12. It will first (probably) add 2 and 2 and then finally will multiply the result by 3.
[edit]
The solution

Use parentheses. In our example that would be 2+(2*3), and now even DNM Script will say it's 8

This problem occurs when using any expression with mixed operators. For example, after executing the following code:

if(4>3+5) MessageBox("yes, 4 is greater that 8");

DNM Script will lie, that "yes, 4 is greater that 8", because it will first evaluate "4>3" which gives TRUE, and then '5' will be added to 'TRUE' which in turn gives TRUE+5 (=6). The solution: again, using parentheses, in this example that would be:

if(4>(3+5)) MessageBox("yes, 4 is greater that 8");

Basic syntax

Below, we have an example of a simple DNM script which shows the text "Hello World"  :

MessageBox("Hello World!");

Each code line in DNM must end with a semicolon. The semicolon is a separator and is used to distinguish one set of instructions from another.

Comments in DNM

In DNM , we use // to make a single-line comment or /* and */ to make a large comment block.

//This is a comment

/*
This is
a comment
block
*/
 

Variables

A variable is a means of storing a value, such as text string "Hello World!" or the integer value 7. A variable can then be reused throughout your code, instead of having to type out the actual value over and over again. All variables in DNM start with a $ sign symbol. Variables may contain strings, numbers, or arrays. When declaring a variable you must precede it with 'var' statement. When using a variable you must omit this keyword. Eg:

var $empty;
var $number=44;

//declaring variable: var $variable_name = Value; eg:
var $hello = "Hello World!";
var $a_number = 4;
var $another__number = 6;
var $empty;//non assigned variable

//using variables:
MessageBox($a_number + $another__number );
$empty=22;
var $CopyOfANumber=$a_number;

Variable types

DNM Script automatically converts types variables depending on context. Example:

var $empty;//this var will be empty
var $number=34;//this one will be INTEGER (64 bit)
var $str="Hello world!";//this will be string

//conversions:

$empty=44;//now, the previously 'empty' variable becomes a number
$str="dog";//now, the previously 'int' variable becomes a string

 

Operators

This section lists the different operators used in DNM.

Arithmetic Operators

Operator Description Example Result
+ Addition x=2
x+2
4
- Subtraction x=2
5-x
3
* Multiplication x=4
x*5
20
/ Division 15/5
5/2
3
2.5
% [not implemented] Modulus (division remainder) [not implemented] 5%2
10%8
10%2
1
2
0

Assignment Operators

Operator Example Is The Same As
= x=y x=y
+= x+=y x=x+y
-= x-=y x=x-y
*= x*=y x=x*y
/= x/=y x=x/y
%= [not implemented] x%=y [not implemented] x=x%y [not implemented]

Comparison Operators

Operator Description Example
== is equal to 2==5 returns false
!= is not equal 2!=5 returns true
> is greater than 2>5 returns false
< is less than 2<5 returns true
>= is greater than or equal to 5>=2 returns false
<= is less than or equal to 2<=5 returns true

Logical Operators

Operator Description Example
&& (alias: AND) and x=6
y=3

(x < 10 && y > 1) returns true

|| (alias: OR) or x=6
y=3

(x==5 || y==5) returns false

! (alias: NOT) not x=6
y=3

!(x==y) returns true

the if statement

An if statement has the form:
 



if (condition)
{
    // code to execute if condition is true
}
else
{
    // code to execute if condition is false
}
 


In an if statement, condition is a value or an expression that is used to determine which code block is executed, and the curly braces act as "begin" and "end" markers.

Here is a full program as an example:

// define two integers
int x = 3;
int y = 4;

//print out a message telling which is bigger
if (x > y)
{
    MessageBox("x is bigger than y")
}
else
{
    MessageBox("x is smaller than y");
}



In this case condition is equal to "(x > y)" which is equal to "(3 > 4)" which is a false statement. So the code within the else clause will be executed. The output of this program will be:

x is smaller than y

If instead the value for x was 6 and the value for y was 2, then condition would be "(6 > 2)" which is a true statement and the output of the program would be:

x is bigger than y

Built-in Functions

int GetLastError()

Returns last error. Only for functions which clearly describe that they set the last error.The Return Value section of the documentation for each function that sets the last-error code notes the conditions under which the function sets the last-error code.

var GetLastAdditionalResult()

Return last 'additional result', some functions set it up.

int MessageBox(string Message, [string Caption],[int Type=MB_OK])

Example:

MessageBox("Hello world!");
if (MessageBox("Are you sure ?","Some caption",MB_YESNO)==IDYES){
MessageBox("yes");
};

Identical to: MSDN: MessageBox, except that it doesn't take 'HWND' as the first parameter.

string InputBox (strQuestion)

Displays a window with an edit box and 'OK', 'Cancel' buttons. Users can enter data into the edit box which will be returned by this function.

Additionally, GetLastAdditionalResult()  will return button code pressed by User (IDOK or IDCANCEL)

Example:

var $s=InputBox("Enter your name");
if(GetLastAdditionalResult()==IDCANCEL)
MessageBox("You pressed cancel...");
else MessageBox("Hello "+$s+"!");
 

Other functions:

The list of raw function declarations is available here.


 

 

To be continued

The DNM Script manual is in progress. For an updated document you may want to check kwiki (wiki at konradp.com)