Class Operands

java.lang.Object
org.projog.core.parser.Operands

public final class Operands extends 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:
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    static final class 
     
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    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
    Returns the priority (precedence/level) of the infix operator represented by op.
     
    int
    Returns the priority (precedence/level) of the postfix operator represented by op.
     
    int
    Returns the priority (precedence/level) of the prefix operator represented by op.
    boolean
    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
    Returns true if op represents a postfix operator, else false.
    boolean
    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.

    Methods inherited from class Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • Operands

      public Operands()
  • Method Details

    • addOperand

      public void addOperand(String operandName, 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
    • getInfixOperand

      public Operands.Operand getInfixOperand(String op)
    • getPrefixOperand

      public Operands.Operand getPrefixOperand(String op)
    • getPostfixOperand

      public Operands.Operand getPostfixOperand(String op)
    • getInfixPriority

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

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

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

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

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

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

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

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

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

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

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

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

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

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