swirl
Guide to OmniMark 8   OmniMark home
docs home 
IndexConceptsTasksSyntaxLibrariesLegacy LibrariesErrors
 
Prerequisite Concepts      

Precedence and order of operations

In a complex expression, operations are performed according to their order of precedence. For instance, consider the mathematical expression in the following program:

  process
     output "d" % 3 * 4 + 5 * 6

This program will output "42". The mathematical operations are performed in this order:

Had the operations been performed in written order, left to right, the result would have been 102. You can force this order of evaluation using parentheses:

  process
     output "d" % ((3 * 4) + 5) * 6

Any operation contained in parentheses is performed first. In the case of nested parentheses, the most deeply nested operations are performed first.

Operations of the same precedence level are performed in order from left to right. Thus the following program outputs "3":

  process
     output "d" % 12 - 3 - 6

Once again, you can use parentheses to change the order of operations:

  process
     output "d" % 12 - (3 - 6)

The code above outputs "15".

The following table gives the precedence for OmniMark operators. Items at the top of the list have low precedence. That is, they are performed last. Items at the bottom of the list have high precedence and are performed first.

Note that if you overload an OmniMark operator, that operator retains its precedence order. However, if you write a function with the name of an OmniMark operator that is not overloadable, your function will override the OmniMark operator (even if your function is written as overloaded) and your function will fall into the "everything else" precedence category, despite the precedence of the name in this table.

Prerequisite Concepts
   Arithmetic and comparison operators
 
   
 

Top [ INDEX ] [ CONCEPTS ] [ TASKS ] [ SYNTAX ] [ LIBRARIES ] [ LEGACY LIBRARIES ] [ ERRORS ]

OmniMark 8.2.0 Documentation Generated: March 13, 2008 at 3:25:49 pm
If you have any comments about this section of the documentation, please use this form.

Copyright © Stilo International plc, 1988-2008.