﻿ Data Types & Operators

# Data Types & Operators

## Data Types

The following data types are supported by TNPL.

### Integers

int - an integer such as -7, 0, 89, or the keywords true (equal to 1) or false (equal to 0) or a valid keyword from the list of Integer Keywords

int exp - an expression that evaluates to an integer such as -7, 0, 89, 5+3, 56-34, 3*2, 6*(7-3), etc.; variable names and functions returning an int can be used

Operators that can be used with integers:

!int1 : returns 1 if int1 is 0, else returns 0

int1+int2 : returns the sum of int1 and int2 (int1+int2)

int1-int2 : returns int1-int2

int1*int2 : returns int1*int2

int1/int2 : returns int1/int2; generates an error if int2 is 0

int1%int2 : modulo (remainder) returns int1%int2 (New v11.9910)

int1&int2 : returns the bitwise AND of int1 and int2

int1|int2 : returns the bitwise OR of int1 and int2

int1^int2 : returns the bitwise XOR of int1 and int2 (exclusive OR) (New v11.9910)

int1<<int2 : returns the bitwise left shift of int1 shifted left by int2 (New v11.9910)

int1>>int2 : returns the bitwise right shift of int1 shifted right by int2 (New v11.9910)

int1==int2 : returns 1 if int1 and int2 are equal, else returns 0; note the double equals signs

int1===int2 : returns 1 if int1 and int2 are both integers and are equal, else returns 0; note the triple equals signs (New v11.9911)

int1!==int2 : returns 1 if int1===int2 is false (0), else returns 0; note the double equals signs (New v11.9915)

int1&&int2 : returns 1 if int1 and int2 are both nonzero, else returns 0

int1||int2 : returns 1 if either or both int1 and int2 are nonzero, else returns 0

int1>=int2 : returns 1 if int1 is greater than or equal to int2, else returns 0

int1<=int2 : returns 1 if int1 is less than or equal to int2, else returns 0

int1>int2 : returns 1 if int1 is greater than int2, else returns 0

int1<int2 : returns 1 if int1 is less than int2, else returns 0

int1<>int2 : returns 1 if int1 does not equal int2, else returns 0 (same as !=)

int1!=int2 : returns 1 if int1 does not equal int2, else returns 0 (same as <>)

### Strings

string - a constant string in quotation marks like "hello world!" or a valid keyword from the list of String Keywords

string exp : an expression that evaluates to a string

constant strings can be enclosed in double quotes (") or single quotes ('), such as "This is a string" or 'This is also a string'

to include a double quote in a double quoted string, escape it with a backslash (\"), similarly, to include a single quote in a single quoted string, escape it with a backslash (\') (New v10.9913)

single quoted strings accept these escape characters:

\\ - backslash (0x5c) (New v14.0209)

\' - single quote (0x27)

double quoted strings accept these escape characters:

\\ - backslash (0x5c)

\' - single quote (0x27)

\" - double quote (0x22)

\a - audible bell (0x07)

\b - backspace (0x08)

\f - form feed/new page (0x0c)

\n - new line/line feed (0x0a)

\r - carriage return (0x0d)

\t - tab (0x09)

Operators that can be used with strings:

string1+string2 : concatenates the values of string1 and string2 and evaluates to a single string

string1==string2 : returns 1 if string1 and string2 are both string variables and are equal (case-insensitively), else returns 0; note the double equals signs (New v11.9911)

string1===string2 : returns 1 if string1 and string2 are both string variables and are equal (case-sensitively), else returns 0; note the triple equals signs (New v11.9911)

string1!==string2 : returns 1 if string1===string2 is false (0), else returns 0; note the double equals signs (New v11.9915)

string1<>string2 : returns 1 if string1 and string2 are both string variables and are not equal (case-insensitively), else returns 0 (same as !=) (New v11.9911)

string1!=string2 : returns 1 if string1 and string2 are both string variables and are not equal (case-insensitively), else returns 0 (same as <>) (New v11.9911)

### Floating Point Numbers

float exp - similar to an int expression but with floating point numbers instead of integers; should not be of much use for tag name programs

floating point numbers are rarely used in TNPL programs

### Arrays

TNPL supports arrays.

Example: \$myvar[0]=5;

Keys (for associative arrays) may also be used in v11.9910 and above.

Example: \$myvar['arg1']=5;

The shortcut \$myvar.arg1=5; for the above example is also allowed and may execute slightly faster.

Use an empty index to add to the end of an array. The following example turns \$array into an array (if it's not already) and adds the value to the end of the array (appends to the array).

Example: \$array[]='last item';

Arrays can also be create with array().

## Increment & Decrement Operators (++ and --)

To increment an integer variable by 1 in an expression, use \$name++, to decrement by 1, use \$name--.

To increment an integer variable by 1 using a statement, add the ending semicolon as in \$name++; and \$name--;.

NOTE: Integer variables in versions prior to CSE HTML Validator v12 generally required the '#' symbol instead of the '\$' symbol.