public final class Operands extends Object
Prolog allows functors (names of predicates) to be defined as "operators". The use of operators allows syntax to be easier to read.
Infix operators are placed between their two arguments. Prefix operators are placed before their single argument. Postfix operators are placed after their single argument.
A common use of operators is in the definition of arithmetic operations. By declaring is
and -
as
infix operators we can write valid prolog syntax like X is 1 + 2.
instead of is(X, +(1, 2)).
Each KnowledgeBase
has a single unique Operands
instance.
KnowledgeBase.getOperands()
Constructor and Description |
---|
Operands() |
Modifier and Type | Method and Description |
---|---|
void |
addOperand(String operandName,
String associativityName,
int precedence)
Adds a new operator.
|
boolean |
fx(String op)
Returns
true if op represents a prefix operator with associativity of fx , else
false . |
boolean |
fy(String op)
Returns
true if op represents a prefix operator with associativity of fy , else
false . |
int |
getInfixPriority(String op)
Returns the priority (precedence/level) of the infix operator represented by
op . |
int |
getPostfixPriority(String op)
Returns the priority (precedence/level) of the postfix operator represented by
op . |
int |
getPrefixPriority(String op)
Returns the priority (precedence/level) of the prefix operator represented by
op . |
boolean |
infix(String op)
Returns
true if op represents an infix operator, else false . |
boolean |
isDefined(String commandName)
Returns
true if commandName represents any known operator, else false . |
boolean |
postfix(String op)
Returns
true if op represents a postfix operator, else false . |
boolean |
prefix(String op)
Returns
true if op represents a prefix operator, else false . |
boolean |
xf(String op)
Returns
true if op represents a postfix operator with associativity of xf , else
false . |
boolean |
xfx(String op)
Returns
true if op represents an infix operator with associativity of xfx , else
false . |
boolean |
xfy(String op)
Returns
true if op represents an infix operator with associativity of xfy , else
false . |
boolean |
yf(String op)
Returns
true if op represents a postfix operator with associativity of yf , else
false . |
boolean |
yfx(String op)
Returns
true if op represents an infix operator with associativity of yfx , else
false . |
public void addOperand(String operandName, String associativityName, int precedence)
operandName
- the name of the new operatorassociativityName
- the operators associativity (must be one of: xfx, xfy, yfx, fx, fy, xf or yf)precedence
- used to specify the ordering of terms where it is not made explicit by the use of bracketspublic int getInfixPriority(String op)
op
.public int getPrefixPriority(String op)
op
.public int getPostfixPriority(String op)
op
.public boolean infix(String op)
true
if op
represents an infix operator, else false
.public boolean yfx(String op)
true
if op
represents an infix operator with associativity of yfx
, else
false
.public boolean xfy(String op)
true
if op
represents an infix operator with associativity of xfy
, else
false
.public boolean xfx(String op)
true
if op
represents an infix operator with associativity of xfx
, else
false
.public boolean prefix(String op)
true
if op
represents a prefix operator, else false
.public boolean fx(String op)
true
if op
represents a prefix operator with associativity of fx
, else
false
.public boolean fy(String op)
true
if op
represents a prefix operator with associativity of fy
, else
false
.public boolean postfix(String op)
true
if op
represents a postfix operator, else false
.public boolean xf(String op)
true
if op
represents a postfix operator with associativity of xf
, else
false
.public boolean yf(String op)
true
if op
represents a postfix operator with associativity of yf
, else
false
.public boolean isDefined(String commandName)
true
if commandName
represents any known operator, else false
.Copyright © 2024. All rights reserved.