Class Operands


  • public final class Operands
    extends java.lang.Object
    Collection 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 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.

    See Also:
    KnowledgeBase.getOperands()
    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      private static class  Operands.Associativity
      Associativity is used to specify rules over operators in the same expression that have the same priority.
      private static class  Operands.Location  
      private static class  Operands.Operand  
    • Constructor Summary

      Constructors 
      Constructor Description
      Operands()  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void addOperand​(java.lang.String operandName, java.lang.String associativityName, int precedence)
      Adds a new operator.
      boolean fx​(java.lang.String op)
      Returns true if op represents a prefix operator with associativity of fx, else false.
      boolean fy​(java.lang.String op)
      Returns true if op represents a prefix operator with associativity of fy, else false.
      private Operands.Associativity getAssociativity​(java.lang.String associativityName)  
      int getInfixPriority​(java.lang.String op)
      Returns the priority (precedence/level) of the infix operator represented by op.
      private java.util.Map<java.lang.String,​Operands.Operand> getOperandsMap​(Operands.Associativity a)  
      int getPostfixPriority​(java.lang.String op)
      Returns the priority (precedence/level) of the postfix operator represented by op.
      int getPrefixPriority​(java.lang.String op)
      Returns the priority (precedence/level) of the prefix operator represented by op.
      boolean infix​(java.lang.String op)
      Returns true if op represents an infix operator, else false.
      boolean isDefined​(java.lang.String commandName)
      Returns true if commandName represents any known operator, else false.
      boolean postfix​(java.lang.String op)
      Returns true if op represents a postfix operator, else false.
      boolean prefix​(java.lang.String op)
      Returns true if op represents a prefix operator, else false.
      boolean xf​(java.lang.String op)
      Returns true if op represents a postfix operator with associativity of xf, else false.
      boolean xfx​(java.lang.String op)
      Returns true if op represents an infix operator with associativity of xfx, else false.
      boolean xfy​(java.lang.String op)
      Returns true if op represents an infix operator with associativity of xfy, else false.
      boolean yf​(java.lang.String op)
      Returns true if op represents a postfix operator with associativity of yf, else false.
      boolean yfx​(java.lang.String op)
      Returns true if op represents an infix operator with associativity of yfx, else false.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • 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
    • Constructor Detail

      • Operands

        public Operands()
    • 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 operator
        associativityName - 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
      • getInfixPriority

        public int getInfixPriority​(java.lang.String op)
        Returns the priority (precedence/level) of the infix operator represented by op.
      • getPrefixPriority

        public int getPrefixPriority​(java.lang.String op)
        Returns the priority (precedence/level) of the prefix operator represented by op.
      • getPostfixPriority

        public int getPostfixPriority​(java.lang.String op)
        Returns the priority (precedence/level) of the postfix operator represented by op.
      • infix

        public boolean infix​(java.lang.String op)
        Returns true if op represents an infix operator, else false.
      • yfx

        public boolean yfx​(java.lang.String op)
        Returns true if op represents an infix operator with associativity of yfx, else false.
      • xfy

        public boolean xfy​(java.lang.String op)
        Returns true if op represents an infix operator with associativity of xfy, else false.
      • xfx

        public boolean xfx​(java.lang.String op)
        Returns true if op represents an infix operator with associativity of xfx, else false.
      • prefix

        public boolean prefix​(java.lang.String op)
        Returns true if op represents a prefix operator, else false.
      • fx

        public boolean fx​(java.lang.String op)
        Returns true if op represents a prefix operator with associativity of fx, else false.
      • fy

        public boolean fy​(java.lang.String op)
        Returns true if op represents a prefix operator with associativity of fy, else false.
      • postfix

        public boolean postfix​(java.lang.String op)
        Returns true if op represents a postfix operator, else false.
      • xf

        public boolean xf​(java.lang.String op)
        Returns true if op represents a postfix operator with associativity of xf, else false.
      • yf

        public boolean yf​(java.lang.String op)
        Returns true if op represents a postfix operator with associativity of yf, else false.
      • isDefined

        public boolean isDefined​(java.lang.String commandName)
        Returns true if commandName represents any known operator, else false.