config/Expressions

Expressions are written in post-fix form and are case-insensitive. Expressions are composed of three parts:

  1. Numbers - Constant values such as 3, -1, and 0.5
  2. Variables - Dynamic values, represented by letters, such as "n" or "d".
  3. Operators - Perform operations such as +, -, * (multiplication), / (division)

Syntax

Syntax is written in post-fix (also known as reverse Polish notation) form. This means the operator comes AFTER the operands.

There MUST be a space between each number, variable, and operator.

Mathematics is usually done with in-fix notation—the familiar x + y. In post-fix, this is written x y +. The advantage of this is that there are no grouping symbols and the order of execution is clear. (basically, it's a hell of a lot easier for me to program post-fix evaluation)

We will try converting some expressions to post-fix from infix:

1 + 1
1 1 +

(a + b) / c
(a b +) / c
(a b +) c /
a b + c /

(a - b) / c * (d - b) + 15
(a b -) / c * (d b -) + 15
((a b -) c /) * (d b -) + 15
(((a b -) c /) (d b -) *) + 15
(((a b -) c /) (d b -) *) 15 +
a b - c / d b - * 15 +

So far, we have only looked at binary operations—operations with two operands (numbers). Some operations, such as "abs", or absolute value, have only one operand.

In standard mathematical notation, we write for "the absolute value of 'a'":

a

In ChangeDamage, we use:

a abs

The same applies for:

|a + b|
|a b +|
a b + abs

There is one operation (so far) with no operands: random. This operation creates a random number between 0 and 1, such that 0 < rand < 1, or, alternately, rand ? ]0, 1[.
The syntax is as follows:

rand

For example, to obtain a random number between 0 and 10:

rand 11 * floor

Details on numbers

All numbers are stored as decimals (technical terms: double precision floating point, aka "double") Scientific notation can be used. For example, 2e1 is 20.

Details on variables

Variables are treated as numbers that can be modified during evaluation. It is important to note that variables always take precedence over operators, so if a variable is named "x", you will have to use "*" for multiplication.

Exhaustive list of operations

Zero operands:

  • Random number: random, rand, r

One operand:

  • Absolute value: abs
  • Round down/Floor: floor, fl
  • Round: round, rd
  • Round up/Ceiling: ceiling, ceil

Two operands:

  • Addition: +
  • Subtraction: -
  • Multiplication: *, x
  • Division: /
  • Bitwise left shift: <<
  • Bitwise right shift (unsigned): >>
  • Bitwise right shift (signed): >>>

Comments

Posts Quoted:
Reply
Clear All Quotes