Prev Up Next
Go backward to C.5.2.2 Display Annotations
Go up to C.5.2 Annotations
Go forward to C.5.2.4 Semantic Annotations

C.5.2.3 Parsing Annotations

These annotations, applicable to an entire library, are to allow users to specify the precedence of operation symbols, and the significance of layout in the so-called "offside" rule. Their primary purpose is to allow the omission of grouping parentheses and/or list separators in the input; but formatters may also exploit them to avoid superfluous parentheses in the display.

A set of parsing annotations has been proposed in Note L-11 [RM99] (see also Note T-6 [Mos98a]). The following have been approved:

These annotations, applicable to an entire library, are to allow users to specify the precedence of operation symbols, and the significance of layout in the so-called "offside" rule. Their primary purpose is to allow the omission of grouping parentheses and/or list separators in the input; but formatters may also exploit them to avoid superfluous parentheses in the display.

A prededence annotation is written:

%prec {id1, ..., idn} < {idn+1, ..., idn+k}
Here each idi is an (unqualified) mixfix operation symbol of the form
`__ ... __ ... __'. The relation specifies that for 1 < i < n the symbol idi has lower priority (i.e., binds weaker) than the symbol idj, where n+1 < j < n+k. In case that there is just one operation symbol, the grouping braces may be omitted.

It is also possible to specify that two mixfix operation symbols id1 and id2 (which need not to be of form `__ ... __ ... __') are not allowed to be combined without explicit grouping parentheses This is done using an annotation:

%prec {id1, ..., idn} <> {idn+1, ..., idn+k}
In case that there is just one operation symbol, the grouping braces may be omitted.

The precedence annotations determine a pre-order, which is obtained in the following way:

  1. Expand all precedence relations into binary relations, i.e.:
  2. Take the union of all declared expanded precedence relations with the predefined precedences listed in Section C.3.1.
  3. Take the reflexive transitive closure of this union.

If two symbols occurring in a term of atomic formula are equivalent (i.e. related in both directions) or incomparable (i.e. related in no direction) in the precedence relation, their grouping has to be explicitly specified by using parentheses.

There are two associativity annotations, `%left assoc' and `%right assoc'. They may be used immediately after an operation or predicate declaration. For example, declaring __+__ to be left associative means that t1 + t2 + t3 is parsed as (t1 + t2) + t3, while declaring it to be right associative leads to t1 + (t2 + t3). If there is no associativity annotation for a mixfix symbol, it is not allowed to repeat that symbol without explicit grouping using parentheses.

For precedence and associativity annotations, we adopt non-linear visibility, that is, they are visible in the whole enclosing basic specification (cf. Section C.3.1).

Precedence annotations interact with structured specifications in the same way as the subsorting relation. That is, for renamings and restrictions, the precedence relation is lifted along the renaming or restriction. For unions and extensions, the precedence relations are united. Note that in the case that there are conflicting precedence annotations this may lead to equivalent symbols in the union. In this case these symbols cannot be combined without explicit grouping. Associativity annotations are translated along renamings and restrictions and united along unions and extensions in the same way as the operations they refer to.


CoFI Document: CASL/Summary -- Version: 1.0 -- 22 July 1999.
Comments to cofi-language@brics.dk

Prev Up Next