# Compiler Directives
Directives are special instructions to the compiler that start with `{$`. They are used for conditional compilation, including external files, and controlling compiler behavior or state.
## Conditional Compilation
Conditional compilation allows you to include or exclude blocks of code based on defined symbols or constant expressions.
### Symbol Directives
| Directive | Description |
| :--- | :--- |
| `{$DEFINE symbol}` | Defines a conditional symbol. |
| `{$UNDEF symbol}` | Undefines a previously defined symbol. |
| `{$IFDEF symbol}` | Compiles the following code if the symbol is defined. |
| `{$IFNDEF symbol}` | Compiles the following code if the symbol is NOT defined. |
| `{$ELSE}` | Provides an alternative branch for `IFDEF`, `IFNDEF`, or `IF`. |
| `{$ENDIF}` | Marks the end of a conditional block. |
```pascal
{$DEFINE DEBUG}
// Symbol DEBUG is now defined
```
```pascal
{$IFDEF DEBUG}
PrintLn('Debug mode');
{$ENDIF}
// OUTPUT
// NONE
```
```pascal
{$IFNDEF RELEASE}
PrintLn('Not in Release mode');
{$ENDIF}
// OUTPUT
// Not in Release mode
```
### Constant Expressions
DWScript also supports `{$IF}` for evaluating constant expressions at compile time.
```pascal
const VERSION = 2;
{$IF VERSION > 1}
PrintLn('Modern Version');
{$ENDIF}
// OUTPUT
// Modern Version
```
## Including Files
You can include the contents of another file directly into your script.
| Directive | Description |
| :--- | :--- |
| `{$I filename}` | Includes the specified file. |
| `{$INCLUDE filename}` | Alias for `{$I}`. |
```pascal
// NO_COMPILE
{$I configuration.inc}
```
## State Management (PUSH/POP)
The `{$PUSH}` and `{$POP}` directives (compatible with Free Pascal) allow you to save and restore the state of compiler directives.
| Directive | Description |
| :--- | :--- |
| `{$PUSH}` | Saves the current state of all pushable compiler directives onto a stack. |
| `{$POP}` | Restores the most recently pushed state from the stack. |
```pascal
{$PUSH}
{$HINTS OFF}
// Hints are temporarily disabled
{$POP}
// Hints are restored to their previous state
```
## HTML Filter Directives
When using the [HTML Filter](/lang/basics/html_filter), special directives control the filtering process.
| Directive | Description |
| :--- | :--- |
| `{$FILTER "name"}` | Switches to a different filter or includes a file through a filter. |
| `{$F "name"}` | Alias for `{$FILTER}`. |
```pascal
// NO_COMPILE
<div>
{$FILTER "sidebar.html"}
</div>
```
## Other Directives
| Directive | Description |
| :--- | :--- |
| `{$HINT "msg"}` | Emits a compiler hint with the specified message. |
| `{$WARNING "msg"}` | Emits a compiler warning. |
| `{$ERROR "msg"}` | Triggers a compiler error and stops compilation. |
```pascal
{$WARNING 'This is a test warning'}
```
Compiler Directives
Directives are special instructions to the compiler that start with {$. They are used for conditional compilation, including external files, and controlling compiler behavior or state.
Conditional Compilation
Conditional compilation allows you to include or exclude blocks of code based on defined symbols or constant expressions.
Symbol Directives
Directive
Description
{$DEFINE symbol}
Defines a conditional symbol.
{$UNDEF symbol}
Undefines a previously defined symbol.
{$IFDEF symbol}
Compiles the following code if the symbol is defined.
{$IFNDEF symbol}
Compiles the following code if the symbol is NOT defined.
{$ELSE}
Provides an alternative branch for IFDEF, IFNDEF, or IF.
{$ENDIF}
Marks the end of a conditional block.
{$DEFINE DEBUG}// Symbol DEBUG is now defined
{$IFDEF DEBUG}
PrintLn('Debug mode');{$ENDIF}
{$IFNDEF RELEASE}
PrintLn('Not in Release mode');{$ENDIF}
Result
Not in Release mode
Constant Expressions
DWScript also supports {$IF} for evaluating constant expressions at compile time.
const VERSION =2;{$IF VERSION > 1}
PrintLn('Modern Version');{$ENDIF}
Result
Modern Version
Including Files
You can include the contents of another file directly into your script.
Directive
Description
{$I filename}
Includes the specified file.
{$INCLUDE filename}
Alias for {$I}.
{$I configuration.inc}
State Management (PUSH/POP)
The {$PUSH} and {$POP} directives (compatible with Free Pascal) allow you to save and restore the state of compiler directives.
Directive
Description
{$PUSH}
Saves the current state of all pushable compiler directives onto a stack.
{$POP}
Restores the most recently pushed state from the stack.
{$PUSH}{$HINTS OFF}// Hints are temporarily disabled{$POP}// Hints are restored to their previous state
HTML Filter Directives
When using the HTML Filter, special directives control the filtering process.
Directive
Description
{$FILTER "name"}
Switches to a different filter or includes a file through a filter.