Terminal symbol 'operator'

Occurrences of symbol 'operator' in grammar rules:

DefinitionKind 'operatorOperator  SPECIFIER  INT 


Description

The first argument of operator can be any syntactically well-formed AQL functor (an Operator). In particular, it need not be known as operator prior to runtime. AQL's tokenizer will recognize as a functor any token that is either an AQL identifier (ID), or a maximal sequence of non alphanumerical characters. AQL also supports the classical prefix function notation used in math and conventional programming. Thus, any AQL functor, whether declared operator or not, can always be parsed as a prefix operator preceding a parenthesized comma-separated sequence of arguments. Whether it is a declared operator determines how it may be parsed otherwise. For example:
          AQL> 1 + 2;
          3 : int
          AQL> +(1,2). 
          3 : int
  
Note that because AQL's functions are first-class citizens, defined functors are themselves expressions of higher-types and can also be parsed as UntypedExpressions (see OperatorExpression).

The second argument of operator is an INT and denotes the binding looseness (as opposed to precedence) of the given operator. AQL uses the same dynamic operator specification used by Prolog's op/3 meta-operator. Note that looseness works as the opposite of what is known as operator binding precedence used in parsing: the smaller an operator's binding looseness, the higher its precedence. In fact, if the looseness is L, then the precedence is P = 1200-L+1. Thus, both binding looseness and precedence range inclusively from 1 (min looseness, max precedence) to 1200 (max looseness, min precedence).

The third argument of operator is called the operator's specifier. It is a symbol that encodes three kinds of information concerning the operator:

  1. arity (unary or binary),
  2. fixity (prefix, infix, or postfix),
  3. associativity (left-, right-, or non-associative).

The specifier is an identifier consisting of either two or three of the letters 'f', 'x', and 'y', which are interpreted as follows. The letter 'f' stands for the operator's position in an expression, and the letters 'x' and 'y' stand for the arguments' positions. The letters 'f', 'y', and 'x', are simply mnemonics for, respectively, "functor" (i.e., indicating the position of the operator symbol with respect to its argument(s)), "yes" (i.e., the argument associates on this side of the operator), and "no" (i.e., the does not associate on this side of the operator). In other words, a 'y' occurring on the left (resp., right) of 'f', means that the operator is left-associative (resp., right-associative). An 'x' occurring on the left (resp., right) of 'f', means that the operator is not left-associative (resp., right-associative). Thus, the possible operator specifiers are:

SpecifierArity FixityAssociativity
fxunary prefix non-associative
fyunary prefix right-associative
xfunary postfixnon-associative
yfunary postfixleft-associative
xfxbinaryinfix non-associative
xfybinaryinfix right-associative
yfxbinaryinfix left-associative

Note that yfy is not allowed as an operator specifier because that would mean an ambiguous way of parsing the operator by associating either to the left or to the right.



Copyright © 2012 by Hassan Aït-Kaci; All Rights Reserved.