Notational conventions
The operation of some operators depends on the speciï¬c kinds of operands.
Therefore, operands are notated thus:
e - any expression;
v - any expression to which a value can be assigned (âlvalueâ expressions);
a - an array;
f - a function;
s - a symbol âwhich is a variable, a constant or a function.
Expressions
An expression consists of one or more operands with an operator. The operand can be a variable, a constant or another expression. An expression followed by a semicolon is a statement.
Listing: examples of expressions
v++
f(a1, a2)
v = (ia1 * ia2) / ia3
Arithmetic
+ "e1 + e2"
Results in the addition of e1 and e2.
- "e1 - e2"
Results in the subtraction of e1 and e2.
-e
Results in the arithmetic negation of a (two's complement).
Results in the multiplication of e1 and e2.
/ "e1 / e2"
Results in the division of e1 by e2. The result is truncated to the nearest integral value that is less than or equal to the quotient. Both negative and positive values are rounded down, i.e. towards ââ.
% "e1 % e2"
Results in the remainder of the division of e1 by e2. The sign of the remainder follows the sign of e2. Integer division and remainder have the Euclidean property: D = q*d + r, where q = D/d and r = D%d.
++ "v++"
increments v by 1; the result if the expression is the value of
v before it is incremented.
++v
increments v by 1; the result if the expression is the value of
v after it is incremented.
-- v--
decrements v by 1; the result if the expression is the value of
v before it is decremented.
--v
decrements v by 1; the result if the expression is the value of
v after it is decremented.
Notes: The unary + is not deï¬ned in pawn.
The operators ++ and -- modify the operand. The operand
must be an lvalue.
⢠Bit manipulation
~ ~e
results in the one's complement of e.
e1 >> e2
results in the arithmetic shift to the right of e1 by e2 bits.
The shift operation is signed: the leftmost bit of e1 is copied
to vacant bits in the result.
Operators and expressions 107
e1 >>> e2
results in the logical shift to the right of e1 by e2 bits. The
shift operation is unsigned: the vacant bits of the result are
ï¬lled with zeros.
<< e1 << e2
results in the value of e1 shifted to the left by e2 bits; the
rightmost bits are set to zero. There is no distinction between
an arithmetic and a logical left shift
& e1 & e2
results in the bitwise logical âandâ of e1 and e2.
| e1 | e2
results in the bitwise logical âorâ of e1 and e2.
^
e1
^
e2
results in the bitwise âexclusive orâ of e1 and e2.
⢠Assignment
The result of an assignment expression is the value of the left operand after
the assignment. The left operand may not be tagged. Tag names: 67
v
e assigns the value of e to variable v.
v
a assigns array a to variable v; v must be an array with the
same size and dimensions as a; a may be a string or a literal
array.
Note: the following operators combine an assignment with an arith-
metic or a bitwise operation; the result of the expression is
the value of the left operand after the arithmetic or bitwise
operation.
+= v += e
increments v with e.
-= v -= e
decrements v with e
108 Operators and expressions
*= v *= e
multiplies v with e
/= v /= e
divides v by e.
%= v %= e
assigns the remainder of the division of v by e to v.
>>= v >>= e
shifts v arithmetically to the right by e bits.
>>>= v >>>= e
shifts v logically to the right by e bits.
<<= v <<= e
shifts v to the left by e bits.
&= v &= e
applies a bitwise âandâ to v and e and assigns the result to v.
|= v |= e
applies a bitwise âorâ to v and e and assigns the result to v.
^
= v
^
= e
applies a bitwise âexclusive orâ to v and e and assigns the
result to v.
⢠Relational
A logical âfalseâ is represented by an integer value of 0; a logical âtrueâ is
represented by any value other than 0. Value results of relational expressions
are either 0 or 1, and their tag is set to âbool:â.
e1
e2 results in a logical âtrueâ if e1 is equal to e2.
!= e1 != e2
results in a logical âtrueâ if e1 diï¬ers from e2.
Note: the following operators may be âchainedâ, as in the expression
âe1 <= e2 <= e3â, with the semantics that the result is â1â
if all individual comparisons hold and â0â otherwise.
< e1 < e2
results in a logical âtrueâ if e1 is smaller than e2.
Operators and expressions 109
<= e1 <= e2
results in a logical âtrueâ if e1 is smaller than or equal to e2.
e1 > e2
results in a logical âtrueâ if e1 is greater than e2.
>= e1 >= e2
results in a logical âtrueâ if e1 is greater than or equal to e2.
⢠Boolean
A logical âfalseâ is represented by an integer value of 0; a logical âtrueâ is
represented by any value other than 0. Value results of Boolean expressions
are either 0 or 1, and their tag is set to âboolâ.
! !e
results to a logical âtrueâ if e was logically âfalseâ.
|| e1
results to a logical âtrueâ if either e1 or e2 (or both) are
logically âtrueâ. The expression e2 is only evaluated if e1 is
logically âfalseâ.
&& e1 && e2
results to a logical âtrueâ if both e1 and e2 are logically
âtrueâ. The expression e2 is only evaluated if e1 is logically
âtrueâ.
⢠Miscellaneous
[ ] a[e]
array index: results to cell e from array a.
{ } a{e}
array index: results to character e from âpackedâ array a.
110 Operators and expressions
( ) f(e1,e2,...eN)
results to the value returned by the function f. The function
is called with the arguments e1, e2, . . .eN. The order of eval-
uation of the arguments is undeï¬ned (an implementation may
choose to evaluate function arguments in reversed order).
? : e1 ? e2 : e3
results in either e2 or e3, depending on the value of e1. The
conditional expression is a compound expression with a two
part operator, â?â and â:â. Expression e2 is evaluated if e1
is logically âtrueâ, e3 is evaluated if e1 is logically âfalseâ.
: tagname: e
tag override; the value of the expression e does not change,
but its tag changes. See page 67 for more information.
, e1, e2
results in e2, e1 is evaluated before e2. If used in function
argument lists or a conditional expression, the comma expres-
sion must be surrounded by parentheses.
defined defined s
results in the value 1 if the symbol is deï¬ned. The symbol
may be a constant (page 98), or a global or local variable.
The tag of this expression is bool:.
sizeof sizeof s
results in the size in âelementsâ of the speciï¬ed variable. For
simple variables and for arrays with a single dimension, an
element is a cell. For multi-dimensional arrays, the result is
the number of array elements in that dimension âappend []
to the array name to indicate a lower/more minor dimension.
If the size of a variable is unknown, the result is zero.
When used in a default value for a function argument, the ex-
pression is evaluation at the point of the function call, instead
of in the function deï¬nition.
state state s
See also page 116
where s is the name of a state that is optionally preï¬xed with for state speciï¬ers
the automaton name, this operator results in the value 1 if
the automatons is in the indicated state and in 0 otherwise.
The tag of this expression is bool:.
tagof tagof s
results in the a unique number that represents the tag of the
variable, the constant, the function result or the tag label.
When used in a default value for a function argument, the ex-
pression is evaluation at the point of the function call, instead
of in the function deï¬nition.
char e char
results the number of cells that are needed to hold a packed
array of e characters.
⢠Operator precedence
The table beneath groups operators with equal precedence, starting with the
operator group with the highest precedence at the top of the table.
If the expression evaluation order is not explicitly established by parentheses,
it is determined by the association rules. For example: a*b/c is equivalent
with (a*b)/c because of the left-to-right association, and a=b=c is equivalent
with a=(b=c).
() function call left-to-right
[] array index (cell)
{} array index (character)
! logical not right-to-left
~ one's complement
- two's complement (unary minus)
++ increment
-- decrement
: tag override
char convert number of packed characters to cells
defined symbol deï¬nition status
sizeof symbol size in âelementsâ
state automaton/state condition
tagof unique number for the tag
- multiplication left-to-right
/ division
% remainder
+ addition left-to-right
- subtraction
arithmetic shift right left-to-right
logical shift right
<< shift left
& bitwise and left-to-right
^
bitwise exclusive or left-to-right
| bitwise or left-to-right
< smaller than left-to-right
<= smaller than or equal to
greater than
>= greater than or equal to
== equality left-to-right
!= inequality
&& logical and left-to-right
? : conditional right-to-left
= assignment right-to-left
*= /= %= += -= >>= >>>= <<= &=
^
= |=
, comma left-to-right
Comming Soon