Operators
The Bro scripting language supports the following operators. Note that
each data type only supports a subset of these operators. For more
details, see the documentation about the data types.
Relational operators
The relational operators evaluate to type bool
.
Name 
Syntax 
Equality 
a == b 
Inequality 
a != b 
Less than 
a < b 
Less than or equal 
a <= b 
Greater than 
a > b 
Greater than or equal 
a >= b 
Logical operators
The logical operators require operands of type bool
, and
evaluate to type bool
.
Name 
Syntax 
Logical AND 
a && b 
Logical OR 
a  b 
Logical NOT 
! a 
Arithmetic operators
Name 
Syntax 
Notes 
Addition 
a + b 
For string
operands, this performs
string concatenation. 
Subtraction 
a  b 

Multiplication 
a * b 

Division 
a / b 
For int or
count operands,
the fractional part of the
result is dropped. 
Modulo 
a % b 
Operand types cannot be
“double”. 
Unary plus 
+ a 

Unary minus 
 a 

Preincrement 
++ a 
Operand type cannot be
“double”. 
Predecrement 
 a 
Operand type cannot be
“double”. 
Absolute value 
 a  
If operand is
string ,
set ,
table , or
vector , this
evaluates to number
of elements. 
Assignment operators
The assignment operators evaluate to the result of the assignment.
Name 
Syntax 
Assignment 
a = b 
Addition assignment 
a += b 
Subtraction assignment 
a = b 
Record field operators
The record field operators take a record
as the first operand,
and a field name as the second operand. For both operators, the specified
field name must be in the declaration of the record type.
Name 
Syntax 
Notes 
Field access 
a $ b 

Field value existence test 
a ?$ b 
Evaluates to type
bool .
True if the specified field
has been assigned a value, or
false if not. 
Other operators
Name 
Syntax 
Notes 
Membership test 
a in b 
Evaluates to type
bool . Do not
confuse this use of “in”
with that used in a
for
statement. 
Nonmembership test 
a !in b 
This is the logical NOT
of the “in” operator.
For example: “a !in b”
is equivalent to
“!(a in b)”. 
Table or vector element access 
a [ b ] 
This operator can also
be used with a
set , but
only with the
add or
delete
statement. 
Substring extraction 
a [ b : c ] 
See the
string type
for more details. 
Create a deep copy 
copy ( a ) 
This is relevant only
for data types that are
assigned by reference,
such as
vector ,
set ,
table ,
and record . 
Module namespace access 
a :: b 
The first operand is the
module name, and the
second operand is an
identifier that refers
to a global variable,
enumeration constant, or
userdefined type that
was exported from the
module. 
Conditional 
a ? b : c 
The first operand must
evaluate to type
bool .
If true, then the
second expression is
evaluated and is the
result of the entire
expression. Otherwise,
the third expression is
evaluated and is the
result of the entire
expression. The types of
the second and third
operands must be
compatible. 