Package org.projog.core.parser
Class Operands
- java.lang.Object
-
- org.projog.core.parser.Operands
-
public final class Operands extends java.lang.ObjectCollection of operands.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
isand-as infix operators we can write valid prolog syntax likeX is 1 + 2.instead ofis(X, +(1, 2)).Each
KnowledgeBasehas a single uniqueOperandsinstance.- See Also:
KnowledgeBase.getOperands()
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static classOperands.AssociativityAssociativity is used to specify rules over operators in the same expression that have the same priority.private static classOperands.Locationprivate static classOperands.Operand
-
Field Summary
Fields Modifier and Type Field Description private java.util.Map<java.lang.String,Operands.Operand>infixOperandsprivate java.lang.ObjectLOCKprivate java.util.Map<java.lang.String,Operands.Operand>postfixOperandsprivate java.util.Map<java.lang.String,Operands.Operand>prefixOperands
-
Constructor Summary
Constructors Constructor Description Operands()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddOperand(java.lang.String operandName, java.lang.String associativityName, int precedence)Adds a new operator.booleanfx(java.lang.String op)Returnstrueifoprepresents a prefix operator with associativity offx, elsefalse.booleanfy(java.lang.String op)Returnstrueifoprepresents a prefix operator with associativity offy, elsefalse.private Operands.AssociativitygetAssociativity(java.lang.String associativityName)intgetInfixPriority(java.lang.String op)Returns the priority (precedence/level) of the infix operator represented byop.private java.util.Map<java.lang.String,Operands.Operand>getOperandsMap(Operands.Associativity a)intgetPostfixPriority(java.lang.String op)Returns the priority (precedence/level) of the postfix operator represented byop.intgetPrefixPriority(java.lang.String op)Returns the priority (precedence/level) of the prefix operator represented byop.booleaninfix(java.lang.String op)Returnstrueifoprepresents an infix operator, elsefalse.booleanisDefined(java.lang.String commandName)ReturnstrueifcommandNamerepresents any known operator, elsefalse.booleanpostfix(java.lang.String op)Returnstrueifoprepresents a postfix operator, elsefalse.booleanprefix(java.lang.String op)Returnstrueifoprepresents a prefix operator, elsefalse.booleanxf(java.lang.String op)Returnstrueifoprepresents a postfix operator with associativity ofxf, elsefalse.booleanxfx(java.lang.String op)Returnstrueifoprepresents an infix operator with associativity ofxfx, elsefalse.booleanxfy(java.lang.String op)Returnstrueifoprepresents an infix operator with associativity ofxfy, elsefalse.booleanyf(java.lang.String op)Returnstrueifoprepresents a postfix operator with associativity ofyf, elsefalse.booleanyfx(java.lang.String op)Returnstrueifoprepresents an infix operator with associativity ofyfx, elsefalse.
-
-
-
Field Detail
-
LOCK
private final java.lang.Object LOCK
-
infixOperands
private final java.util.Map<java.lang.String,Operands.Operand> infixOperands
-
prefixOperands
private final java.util.Map<java.lang.String,Operands.Operand> prefixOperands
-
postfixOperands
private final java.util.Map<java.lang.String,Operands.Operand> postfixOperands
-
-
Method Detail
-
addOperand
public void addOperand(java.lang.String operandName, java.lang.String associativityName, int precedence)Adds a new operator.- Parameters:
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 brackets
-
getAssociativity
private Operands.Associativity getAssociativity(java.lang.String associativityName)
-
getOperandsMap
private java.util.Map<java.lang.String,Operands.Operand> getOperandsMap(Operands.Associativity a)
-
getInfixPriority
public int getInfixPriority(java.lang.String op)
Returns the priority (precedence/level) of the infix operator represented byop.
-
getPrefixPriority
public int getPrefixPriority(java.lang.String op)
Returns the priority (precedence/level) of the prefix operator represented byop.
-
getPostfixPriority
public int getPostfixPriority(java.lang.String op)
Returns the priority (precedence/level) of the postfix operator represented byop.
-
infix
public boolean infix(java.lang.String op)
Returnstrueifoprepresents an infix operator, elsefalse.
-
yfx
public boolean yfx(java.lang.String op)
Returnstrueifoprepresents an infix operator with associativity ofyfx, elsefalse.
-
xfy
public boolean xfy(java.lang.String op)
Returnstrueifoprepresents an infix operator with associativity ofxfy, elsefalse.
-
xfx
public boolean xfx(java.lang.String op)
Returnstrueifoprepresents an infix operator with associativity ofxfx, elsefalse.
-
prefix
public boolean prefix(java.lang.String op)
Returnstrueifoprepresents a prefix operator, elsefalse.
-
fx
public boolean fx(java.lang.String op)
Returnstrueifoprepresents a prefix operator with associativity offx, elsefalse.
-
fy
public boolean fy(java.lang.String op)
Returnstrueifoprepresents a prefix operator with associativity offy, elsefalse.
-
postfix
public boolean postfix(java.lang.String op)
Returnstrueifoprepresents a postfix operator, elsefalse.
-
xf
public boolean xf(java.lang.String op)
Returnstrueifoprepresents a postfix operator with associativity ofxf, elsefalse.
-
yf
public boolean yf(java.lang.String op)
Returnstrueifoprepresents a postfix operator with associativity ofyf, elsefalse.
-
isDefined
public boolean isDefined(java.lang.String commandName)
ReturnstrueifcommandNamerepresents any known operator, elsefalse.
-
-