Progress
Language Tutorial
for Character


Understanding Precedence in Expressions

When you have a complex expression of many operators and functions, it’s important to know the order in which Progress evaluates parts of the expression. For example, the following nonsensical jumble of language elements is a legal expression:

var1 <= var2 + var3 / (ASC("z") - ASC("a") 

Assume that the variables have the following values:

ASSIGN var1 = 20 
       var2 = 10 
       var3 = 250. 

Progress follows these steps to evaluate the expression:

  1. Progress evaluates functions first. So, Progress executes the ASC functions, which return the ASCII integer code for a supplied character as shown in the following code:
  2. var1 <= var2 + var3 / (122 - 97). 
    

  3. Progress evaluates any part of the expression contained inside parentheses:
  4. var1 <= var2 + var3 / 25. 
    

    If Progress encounters nested parentheses, Progress evaluates the elements in the innermost set first and then works out from there.

  5. Progress has predefined levels of operator importance based on the laws of mathematics and logic. These levels of precedence define which operators Progress executes first. Table 5–8, which follows this description, shows the levels of precedence. Operators with a higher number are executed first. In this example, the division operator has the highest level of precedence:
  6. var1 <= var2 + 10 
    

    Among operators of equal precedence, Progress evaluates them from left to right.

  7. The addition operator has the next highest level of precedence:
  8. var1 <= 20 
    

  9. Finally, the less than or equal to operator remains. Since this is a logical operator, the final result of the expression will be TRUE or FALSE. In this case the final value is TRUE.

Table 5–8 depicts the levels of operator precedence which Progress follows from highest (7) to lowest (1):

Table 5–8: Operator Precedence 
Level
Operator
Symbol
7
Unary Negative
Unary Positive
-
+
6
Modulo
Division
Multiplication
MODULO
/
*
5
Date Subtraction
Subtraction
Date Addition
Concatenation
Addition
-
-
+
+
+
4
MATCHES
Less Than
Less Than or Equal To
Greater Than
Greater Than or Equal To
Equal To
Not Equal To
BEGINS
MATCHES
LT or <
LE or <=
GT or >
GE or >=
=
<>
BEGINS
3
Not
NOT
2
And
AND
1
Or
OR


Copyright © 2004 Progress Software Corporation
www.progress.com
Voice: (781) 280-4000
Fax: (781) 280-4095