Skip to main content

Operators

SLOP uses the same operators as C / C++ / Java languages out of the box. Below a list of the supported operators with examples:

NameNotationExampleResult
Add+1 + 12
Subtract-4 - 22
Divide/4 / 22
Multiply*2 * 24
Greater or Equal To>=5 >= 4true
Less than or Equal To<=5 <= 4false
Less than<3 < 4true
Greater than>3 > 4false
Modulus%8 % 32
Not Equal!=1 != 2true
Equals==2 == 2true

The default set of operators follow the standard BODMAS order of mathematical operations. This along with modification or addition of new operators is supported. Please see the Custom Operators section for more information.

NOTE: There is a limitation where operators that modify left-side values i.e. increment (++), decrement (--) are only supported for special cases in specific statements. This is because at present the Parser does not support modification of variables directly, but have to be reassigned using the 'val = expr' pattern. An issue has been logged about this and will look to included in upcoming versions. Until that time to increment a variable please use 'myVar = myVar + 1'.

Logical Operators

Logical Operators are used when wanting to perform multiple parts to a condition. Irrespective of the language used, they share the same fundamental names which are AND and OR. A language such as Java / C# uses && and || respectively, whereas a language like Pascal adopts a more literal approach by using 'and' and 'or'. The default for SLOP follows this more literal approach (and | or), though like with everything this can be customized through the creation of a class which extends both the Token<?> class and implemented the LogicOperatorHandler interface. You can then choose in the REGEX pattern the values you wish to use:

@Override
public String getPattern() {
return "^(\\|\\||&&)";
}

From there you can set your customized version of the Logic Operator Handler to the config by using the following:

SLOPConfig config = new SLOPConfig();
config.setLogicOperatorHandler(new MyCustomLogicOperators());

For more details, please look at the LogicOperator class file within the SLOP codebase. The final stage will be to configure which tag is the OR operator. You can do this by setting a property:

config.setProperty(DefaultProperty.OR_OPERATOR, "||");

From there you can start using those in expressions (AND):

> 99 > 50 && 23 - 22 == 1
Result: true

The OR operator:

> 54 - 12 == 9 || 1 < 2
Result: true

NOTE: Please note again, the default logical operators for SLOP are 'and' and 'or'.