Operators

DWScript supports standard Pascal operators for arithmetic, logic, and comparisons.

Assignment & Arithmetic

var a := 10;
var b := 20;

PrintLn(a + b);
PrintLn(10 div 3);
PrintLn(10 mod 3);
PrintLn(10 / 3);
Result
30
3
1
3.33333333333333

Arithmetic Operators

Operator Operation Example
+ Addition 1 + 2 (3)
- Subtraction 5 - 3 (2)
* Multiplication 2 * 4 (8)
/ Division (Float) 10 / 2 (5.0)
div Integer Division 10 div 3 (3)
mod Modulus (Remainder) 10 mod 3 (1)

Logical Operators

Used with Boolean values. Logical operators in DWScript are short-circuiting, meaning the second operand is only evaluated if the first one doesn't determine the final result.

Operator Description
not Negation (True becomes False)
and Logical AND (True if both are True)
or Logical OR (True if either is True)
xor Logical XOR (True if only one is True)
implies Material Implication (False only if True implies False)

Comparison Operators

Operator Description
= Equal to
<> Not equal to
< Less than
> Greater than
<= Less than or equal to
>= Greater than or equal to
is Type compatibility check (for classes and interfaces)
as Checked type cast
implements Checks if an object/class implements an interface
in Set membership, array inclusion, or substring check
not in Negation of in (True if NOT a member)

Collection & String Inclusion

In DWScript, the in operator is highly versatile and works with sets, arrays, and strings.

Set Inclusion & Ranges

You can check if a value belongs to a set of values or a specific range.

var c := 'k';

if c in ['a'..'z', '0'..'9', '_'] then
  PrintLn('Is Alphanumeric');

var x := 5;
if x in [1..10, 20..30] then
  PrintLn('Is in range');

var s := 'Grape';
if s in ['Apple'..'Orange'] then
  PrintLn('Between Apple and Orange');
Result
Is Alphanumeric
Is in range
Between Apple and Orange

Array Inclusion

You can check if an element exists within an array. This works for simple types, records, and objects.

var colors := ['Red', 'Green', 'Blue'];

if 'Green' in colors then
  PrintLn('Found Green');
  
if 'Yellow' not in colors then
  PrintLn('Yellow is missing');
Result
Found Green
Yellow is missing

String Inclusion

You can check if a string contains another string using the in operator or the .Contains() method. This is more readable and idiomatic than using Pos() > 0.

var msg := 'Hello World';

// Using 'in' operator
if 'World' in msg then
  PrintLn('Found using in');

// Using .Contains method
if msg.Contains('Hello') then
  PrintLn('Found using .Contains');

// Legacy style (not recommended)
if Pos('Hello', msg) > 0 then
  PrintLn('Found using Pos');
Result
Found using in
Found using .Contains
Found using Pos

Operator Precedence

Higher priority operators are evaluated first. When operators have the same priority, they are evaluated from left to right.

  1. not, Unary -
  2. *, /, div, mod, and, shl, shr, sar, %
  3. ?? (Coalesce)
  4. +, -, or, xor
  5. =, ==, <>, !=, <, >, <=, >=, in, not in, is, as, implies
  6. if then else (Ternary)

Custom Operators

You can define custom behavior for operators when working with your own types.

Specialized Operators

DWScript also supports several specialized operators for concise expression:

On this page