-
Notifications
You must be signed in to change notification settings - Fork 98
NCalc scripting Language basics
A value is a terminal token representing a concrete element. This can be:
- an integer
- a floating point number
- a date time
- a boolean
- a string
- a function
- a parameter
They are represented using numbers.
123456
They are evaluated as Int32.
Use the dot to define the decimal part.
123.456
0.123
They are evaluated as Decimal. Scientific notation
You can use the e to define power of ten (10^).
- 1.22e1
- 1e2
- 1e+2
- 1e-2
- .1e-2
- 1e10
They are evaluated as Double
Must be enclosed between sharps.
#2008/01/31# // for en-US culture
The are evaluated as DateTime.
Booleans can be either true or false.
true
Any character between single quotes "'" are evaluated as String.
'hello'
You can escape special characters using \, ', \n, \r, \t.
A function is made of a name followed by braces, containing optionally any value as arguments.
Abs(1)
doSomehting(1, 'dummy')
Please read the functions page for details.
A parameter as a name, and can be optionnaly contained inside brakets.
2 + x
2 + [x]
Expressions can be combined using operators. Each operator as a precedence priority. Here is the list of those expression's priority.
- primary
- unary
- power
- multiplicative
- additive
- relational
- logical
- Logical
These operators can do some logical comparison between other expressions:
- or, ||
- and, &&
true or false and true
The and operator has more prioroty thand the or, thus in the example above, false and true is evaluated first. Relational
- =, ==, !=, <>
- <, <=, >, >=
1 < 2
- +, -
1 + 2 - 3
- *, /, %
1 * 2 % 3
- & (bitwise and),
- | (bitwise or)
- ^(bitwise xor)
- << (left shift)
- >>(right shift)
2 >> 3
- !
- not
- -
- ~ (bitwise not)
not true
- (, )
- values
2 * ( 3 + 2 )