v10.50 v10.55 Alpha v10.54 Alpha v10.53 Alpha v10.52 Alpha v10.51 Alpha
v10.50 v10.55 Alpha v10.54 Alpha v10.53 Alpha v10.52 Alpha v10.51 Alpha

Values

There are five value types that may be manipulated by a script: integers, strings, lists, raw bytes, and null. CSL is not a strongly typed language. Value types need not be pre-declared. Literals, variables and constants can take on any of the five value types, and the types can be reassigned dynamically.

Literals

Literals are data that remain unchanged when the program is compiled. Literals are a way of expressing hard-coded data in a script.

Integers

Integer literals represent numeric values with no fractions or decimal points. Hexa- decimal, octal, decimal, and binary notation are supported:

  • Hexadecimal numbers must be preceded by 0x: 0x2A, 0x54, 0xFFFFFF01

  • Octal numbers must begin with 0: 0775, 017, 0400

  • Decimal numbers are written as usual: 24, 1256, 2

  • Binary numbers are denoted with 0b: 0b01101100, 0b01, 0b100000

Strings

String literals are used to represent text. A string consists of zero or more characters and can include numbers, letters, spaces, and punctuation. An empty string ("") contains no characters and evaluates to false in an expression, whereas a non-empty string evaluates to true. Double quotes surround a string, and some standard backslash (\) escape sequences are supported.

String

Represented text

"Quote: \"This is a string literal.\""

Quote: "This is a string literal."

"256"

256

Note that this does not represent the integer 256, but only the characters that make up the number.

"abcd!$%&*"

abcd!$%&*

"June 26, 2001"

June 26, 2001

"[ 1, 2, 3 ]"

[ 1, 2, 3 ]

Escape Sequences

These are the available escape sequences in CSL:

Character

Escape Sequence

Example

Output

backslash

\\

"This is a backslash: \\"

This is a backslash: \

double quote

\"

"\"Quotes!\""

"Quotes!"

horizontal tab

\t

"Before tab\tAfter tab"

Before tab After tab

newline

\n

"This is how\nto get a newline."

This is how

to get a newline.

single quote

\'

"\'Single quote\'"

'Single quote'

Lists

A list can hold zero or more pieces of data. A list that contains zero pieces of data is called an empty list. An empty list evaluates to false when used in an expression, whereas a non-empty list evaluates to true. List literals are expressed using the square bracket ([]) delimiters. List elements can be of any type, including lists.

[1, 2, 3, 4]

[]

["one", 2, "three", [4, [5, [6]]]]

Raw Bytes

Raw binary values are used primarily for efficient access to packet payloads. A literal notation is supported using single quotes:

'00112233445566778899AABBCCDDEEFF'

This represents an array of 16 bytes with values starting at 00 and ranging up to 0xFF. The values can only be hexadecimal digits. Each digit represents a nybble (four bits), and if there are not an even number of nybbles specified, an implicit zero is added to the first byte. For example:

'FFF'

is interpreted as

'0FFF'

Null

Null indicates an absence of valid data. The keyword null represents a literal null value and evaluates to false when used in expressions.

C++
result = null;

Variables

Variables are used to store information, or data, that can be modified. A variable can be thought of as a container that holds a value.

All variables have names. Variable names must contain only alphanumeric charac- ters and the underscore ( _ ) character, and they cannot begin with a number. Some possible variable names are

x

_NewValue

name_2

A variable is created when it is assigned a value. Variables can be of any value type, and can change type with reassignment. Values are assigned using the assignment operator ( = ). The name of the variable goes on the left side of the operator, and the value goes on the right:

x = [ 1, 2, 3 ]

New_value = x

name2 = "Smith"

If a variable is referenced before it is assigned a value, it evaluates to null. There are two types of variables: global and local.

Global Variables

Global variables are defined outside of the scope of functions. Defining global variables requires the use of the keyword set. Global variables are visible through- out a file (and all files that it includes).

C++
set Global = 10;

If an assignment in a function has a global as a left-hand value, a variable will not be created, but the global variable will be changed. For example

C++
set Global = 10; 
Function()
{
  Global = "cat"; 
  Local = 20;
}

will create a local variable called Local, which will only be visible within the function Function. Additionally, it will change the value of Global to "cat", which will be visible to all functions. This will also change its value type from an integer to a string.

Local Variables

Local variables are not declared. Instead, they are created as needed. Local variables are created either by being in a function's parameter list, or simply by being assigned a value in a function body.

C++
Function(Parameter)
{
  Local = 20;
}

This function will create a local variable Parameter and a local variable Local, which has an assigned value of 20.

Constants

A constant is similar to a variable, except that its value cannot be changed. Like variables, constant names must contain only alphanumeric characters and the un- derscore ( _ ) character, and they cannot begin with a number.

Constants are declared similarly to global variables using the keyword const:

C++
const CONSTANT = 20;

They can be assigned to any value type, but will generate an error if used in the left- hand side of an assignment statement later on. For instance,

C++
const constant_2 = 3; 
Function()
{
  constant_2 = 5;
}

will generate an error.

Declaring a constant with the same name as a global, or a global with the same name as a constant, will also generate an error. Like globals, constants can only be declared in the file scope.