Below is the table of operators used in Pedro. The table lists the declarations of the operators as used in Prolog. In Prolog, the declaration op(Prec, Assoc, Ops)
declares the list of operators Ops
to have precedence Pred
and associativity Assoc
. The smaller the precedence, the more tightly the operator binds. For the associativity argument xfy
describes a right-associative infix operator, xfx
describes a non-associative infix operator, yfx
describes a left-associative infix operator, and fy
describes an associative prefix operator.
op(1100, xfy, [ ; ]). op(1050, xfy, [ -> ]). op(1000, xfy, [ ',' ]). op(700, xfx, [ = , is, < , =< , > , >= ]). op(500, yfx, [ + , - , /\ , \/ ]). op(400, yfx, [ * , / , // , rem , mod , << , >> ]). op(200, xfx, [ ** ]). op(200, fy, [ + , - ]). op(100, xfx, [ @ ]). op(50, xfx, [ : ]).
Examples:
The string"X is A + - B + C*D"
parses to the termis(X, +(+(A, -(B)), *(C, D)))
The string"G1 -> G2 ; G3"
parses to the term;(->(G1, G2), G3)
Note that comma is used both as an argument separator and as an infix operator. Each operator used at the top-level of an argument of a list or compound term has to have precedence less than 1000. If an argument has an operator of higher precedence then the argument needs to be enclosed in brackets.
Examples:
The string"f((G1, G2))"
parses to the compound termf(','(G1, G2))
The string"[G, (G1;G2)]"
parses to the list[G, ;(G1, G2)]