PScript Interpreter – Part 4 – Operators

As with any programming language we need to define a list of operators and how they behave. After years of C/C++ programming I simply copy the list from that language as a start. This first list show mathematical operators.

Operator Description
+ Addition: a+b
Subtraction: a-b
/ Divide. a/b
* Multiply: a*b
+a Positive signed variable/number
-a Negative signed variable/number
% Modulo: a%b
Decrement with 1: –a or a–
++ Increment with 1: ++a or a++
~ Binary invert: ~a
| Binary OR
& Binary AND
^ Binary XOR
>> Bit rotate right
<< Bit rotate left

This next list show boolean operators that only is valid for boolean expressions.

Operator Description
== Equal
!= Not equal
> Greater than
< Less Than
>= Greater than or equal
<= Less than or equal
|| Logical OR
&& Logical AND

The trick with this is that I might have 3 operators related to a variable – one pre operator like a sign or ++, — etc, a post operator like ++ or — and a main operator. This needs to be handled by my expression parser.

Leave a Reply