Imp
Copyright (c) 1998-1999 Redshift Software Inc. All Rights Reserved

4

Expressions

 
 
Expressions in IMP are in infix order and may be arbitrarily nested with parenthesis. Simple expressions can be literals, identifiers, routines, coerce, cast, and size. Simple expressions may be combined with built-in or user defined operators to form expressions that are arbitrarily complex.

4.1
Precedence
 
 
Built in operators in IMP have the following precedence classes from highest to lowest:

accessor @ & []
multiplier * / %
negator ~
adder + -
relator < <= = >= >
User defined operators have the lowest precedence class by default, but may assign another precedence class when defined. Consider the following example:
byte: type [8]bit
{
+: operator(a: byte;b: byte) (r: byte) { ... }
*: operator(a: byte;b: byte) (r: byte) { ... }
<<: operator(a: byte;b: byte) (r: byte) precedence <- multiplier { ... }
...
}
In addition, users may define new precedence classes as follows:

new-precedence : precedence relational operator old-precedence

The only restriction on new precedence classes is that no class may be equal to or higher than the accessor class. This means that the programmer can create any number of precedence classes below accessor and above,below, between, or equal to any other existing precedence class.


 
Reference
 
1 Lexical
2 Programs
3 Declarations
4 Expressions
5 Statements
6 Preprocessor
7 EBNF