Using Expressions

An expression is like an algebraic expression in normal life. An expression can generally be used when any numeric or other type of value is expected. Provided the data type yielded by the expression matches the type expected there should be no problem.

For example the Circle shape expects a numeric value for the first ( radius ) parameter. So you can use a literal number, like 20, or you could use some complex expression that yields a number, e.g. "Sin(3 * x) + 45".

Components of Expressions

An expression consists of terms and operators. Each term in the expression can itself be an expression or an atomic term ( one that cannot be broken down further ).

Atomic Terms

An atomic term consists of either a literal value or a datum ( named variable or constant ). A literal value can be a compound value ( structure or array ), in which case each element of the compound can itself be an expression. so everything eventually reduces to atomic terms and operators.

Operators

There is a large set of operators. Most take numeric values as operands, but all data types have some operators.

Each operator has a fixed precedence and order in which they associate. These can be overridden using parentheses. The system is like the old "BODMAS" from school days.

The following is a summary of all the operators :-

Operator | Data Types | Precedence | Associativity | Operation |
---|---|---|---|---|

. | Structure | 1000 | Left | Field Access |

( | Function | 1000 | Left | Function Call |

{ | Structure | 1000 | Left | Structure Modify |

[ | Array/Text | 1000 | Left | Indexing |

+ | Numeric | 700 | Right | Unary Plus |

- | Numeric | 700 | Right | Unary Minus |

^ | Numeric | 640 | Right | Power |

* | Numeric | 620 | Left | Multiplication |

/ | Numeric | 620 | Left | Division |

// | Numeric | 620 | Left | Integer Division |

Mod | Numeric | 620 | Left | Modulo |

+ | Numeric/Text | 600 | Left | Addition/Concatenation |

- | Numeric | 600 | Left | Subtraction |

>= <= > < | Numeric/Enum | 520 | Left | Comparison |

== <> | All | 500 | Left | Equality |

Not | Logical | 440 | Right | Logical Negation |

And | Logical | 430 | Left | And |

Or | Logical | 420 | Left | Inclusive Or |

XOr | Logical | 420 | Left | Exclusive Or |

The absolute value of the precedence is not important, just the relative values. If the precedence values are the same then the associativity rule applies.

There are some symbols that have more the one meaning, e.g. '+' and '(', the interpretation of these depend on where they appear in the expression. A term is always followed by a binary operator ( or some terminator ) so any ambiguous symbol will always be interpreted as such in those situations.

If you have done any programming most of these operators should be familiar to you. The only one invented for this language is the "structure modify" operator ( although someone else has probably come up with the same idea already ). All the operators will be covered in detail at some point in the documentation.