Introduction

Welcome to DWScript. If you are familiar with Pascal or Delphi, you will feel right at home. If you are coming from JavaScript or PHP, you will appreciate the structure and clarity that Pascal brings.

Hello World

Let's start with the classic example. In DWScript, a standalone script is simply a sequence of statements.

PrintLn('Hello World');
Result
Hello World

When this script runs on the server, it outputs:

Hello World

Code Structure

Scripts can contain:

  • Statements: Instructions to be executed (like PrintLn).
  • Declarations: Variables, types, constants, procedures, and functions.

Statements are separated by semicolons ;. Blocks of code are enclosed in begin and end keywords.

var x : Integer;
x := 10;

if x > 5 then begin
  PrintLn('x is greater than 5');
end;
Result
x is greater than 5

Comments

Comments are ignored by the compiler and are used to document your code. DWScript supports standard Pascal comments as well as C-style block comments.

// Single line comment

{ 
  Multi-line block comment 
}

(* 
  Another style of multi-line comment 
*)

/* 
  C-style block comment 
*/

Identifiers

Identifiers are names you give to variables, constants, procedures, and other entities. They must start with a letter or underscore, followed by letters, numbers, or underscores.

Reserved Words & Escaping

You cannot use reserved keywords (like type, begin, if) directly as identifiers. However, you can use them by prefixing them with an ampersand &.

var &type := 'System'; // 'type' is a reserved word
PrintLn(&type);
Result
System

Compiler Directives

Directives are special instructions to the compiler that start with {$. They are used for conditional compilation, including files, and controlling compiler behavior.

{$IFDEF DEBUG}
  // This code only compiles if DEBUG is defined
  PrintLn('Debug Mode');
{$ENDIF}
On this page