next up previous contents index
Next: expect: n Up: Parser Specification Previous: Syntax declaration

Precedence

Operator precedences are specified using precedence declarations. The syntax is:


Precedence_Decl ::=left: Integer Operator  ¼ Operator ; left associative operators
  |  right: Integer Operator  ¼ Operator ; right associative operators
Operator ::=Char single character operator
  |  String multi-character operator
  |  Cons constructor

The integer associated with a precedence declaration is the precedence level of an operator. The higher the level of an operator, the lower its precedence.

For example, the following set of precedences are used in the Prop language parser:

left: 23 "as";
left: 22 "::";
left: 21 "||";
left: 20 "equiv:";
left: 19 "xor:";
left: 18 "implies:";
left: 17 "&&" "and";
right: 16 "|=" "&=" "^=" "<<=" ">>=";
right: 15 '=' ":=" "+=" "-=" "*=" "/=" "%=";
left: 14 '|';
left: 13 ':';
left: 12 ';';
left: 11 '^';
left: 10 '&';
left: 9 "==" "!=";
left: 8 '<' '>' ">=" "<=";
left: 7 "<<" ">>";
left: 6 '+' '-' "with" "less";
left: 5 '*' '/' '%';
left: 4 "++" "--";
left: 3 '!' '~' "arb" "card" "dom" "ran";
left: 2 '[' ']' '{' '}' '.' "->" ;



Allen Leung
Mon Apr 7 14:33:55 EDT 1997