[SLP-Homepage]    [Source Modules]    [Manual]    [Run]    [Examples]
 

Enumeration Type for Operator Associativity

The parser for formulas (Module parse) is fairly general. It allows that for each logical operator, the priority and the associativity can be defined.

The priority means binding strength or precedence. For instance, AND (&) usually binds stronger than OR (|), so "a & b | c" means "(a & b) | c" and "a | b & c" means "a | (b & c)".

The associativity refers to sequences of the same operator, e.g. "a & b & c". There are three possibilities:

This module defines a type assoc_t with the three values ASSOC_LEFT, ASSOC_RIGHT, and ASSOC_NONE.

Not that monadic (prefix) operators can never be left associative, only right associative (in which case e.g. "~ ~ p" (not not p) is legal, or not associative (in which case it is not legal).

In Prolog, the operator type "yfx" is left associative, the operator type "xfy" is right associative, and "xfx" is not associative. There are special types for unary operators ("fx" and "fy" for prefix operators).

The meaning of the different associativities is implemented in the parser:

Note that you should never define two different operators with the same priority and a different associativity. It is not really defined what this means.


Implementation:


Stefan Brass (sbrass@sis.pitt.edu), March 27, 2001.    [HTML 3.2 Checked]