lojix/logic/src/main/com/thesett/aima/logic/fol/isoprologparser/DynamicOperatorParser.java
public void setOperator(int name, String textName, int priority, OpSymbol.Associativity associativity)
    {
        // Check that the name of the operator is valid.

        // Check that the priority of the operator is valid.
        if ((priority < 0) || (priority > 1200))
        {
            throw new IllegalArgumentException("Operator priority must be between 0 and 1200 inclusive.");
        }

        OpSymbol opSymbol = new OpSymbol(name, textName, associativity, priority);

        // Consult the defined operators to see if there are any already defined that match the name of the
        // new definition, otherwise a map of operators by fixity needs to be created.
        EnumMap<OpSymbol.Fixity, OpSymbol> operatorMap = operators.get(textName);

        // Check if the priority is non-zero in which case the operator is being added or redefined.
        if (priority > 0)
        {
            if (operatorMap == null)
            {
                operatorMap = new EnumMap<OpSymbol.Fixity, OpSymbol>(OpSymbol.Fixity.class);
                operators.put(textName, operatorMap);
            }

            // Check if the operators fixity to see if further rules regarding simultaneous definition of post and
            // infix operators need to be applied.
            if (opSymbol.isPostfix())
            {
                // Postfix, so check if an infix definition already exists, which is not allowed.
                if (operatorMap.containsKey(OpSymbol.Fixity.In))
                {
                    throw new IllegalArgumentException(
                        "Cannot define a postfix operator when an infix one with the same name already exists.");
                }
            }
            else if (opSymbol.isInfix())
            {
                // Infix, so check if a postfix definition already exists, which is not allowed.
                if (operatorMap.containsKey(OpSymbol.Fixity.Post))
                {
                    throw new IllegalArgumentException(
                        "Cannot define an infix operator when an postfix one with the same name already exists.");
                }
            }

            // Add the operator to the table replacing any previous definition of the same fixity.
            operatorMap.put(opSymbol.getFixity(), opSymbol);
        }
        else
        {
            // The priority is zero, in which case the operator is to be removed.
            if ((operatorMap != null) && opSymbol.isPrefix())
            {
                // Remove it from the prefix table, if it exists there.
                operatorMap.remove(OpSymbol.Fixity.Pre);
            }
            else if ((operatorMap != null) && (opSymbol.isPostfix() || opSymbol.isInfix()))
            {
                // Remove it from the postfix/infix table, if it exists there.
                operatorMap.remove(OpSymbol.Fixity.Post);
                operatorMap.remove(OpSymbol.Fixity.In);
            }
        }
    }
public void setOperator(int name, String textName, int priority, OpSymbol.Associativity associativity)
    {
        // Check that the name of the operator is valid.

        // Check that the priority of the operator is valid.
        if ((priority < 0) || (priority > 1200))
        {
            throw new IllegalArgumentException("Operator priority must be between 0 and 1200 inclusive.");
        }

        OpSymbol opSymbol = new OpSymbol(name, textName, associativity, priority);

        // Consult the defined operators to see if there are any already defined that match the name of the
        // new definition, otherwise a map of operators by fixity needs to be created.
        EnumMap<OpSymbol.Fixity, OpSymbol> operatorMap = operators.get(textName);

        // Check if the priority is non-zero in which case the operator is being added or redefined.
        if (priority > 0)
        {
            if (operatorMap == null)
            {
                operatorMap = new EnumMap<OpSymbol.Fixity, OpSymbol>(OpSymbol.Fixity.class);
                operators.put(textName, operatorMap);
            }

            // Check if the operators fixity to see if further rules regarding simultaneous definition of post and
            // infix operators need to be applied.
            if (opSymbol.isPostfix())
            {
                // Postfix, so check if an infix definition already exists, which is not allowed.
                if (operatorMap.containsKey(OpSymbol.Fixity.In))
                {
                    throw new IllegalArgumentException(
                        "Cannot define a postfix operator when an infix one with the same name already exists.");
                }
            }
            else if (opSymbol.isInfix())
            {
                // Infix, so check if a postfix definition already exists, which is not allowed.
                if (operatorMap.containsKey(OpSymbol.Fixity.Post))
                {
                    throw new IllegalArgumentException(
                        "Cannot define an infix operator when an postfix one with the same name already exists.");
                }
            }

            // Add the operator to the table replacing any previous definition of the same fixity.
            operatorMap.put(opSymbol.getFixity(), opSymbol);
        }
        else
        {
            // The priority is zero, in which case the operator is to be removed.
            if ((operatorMap != null) && opSymbol.isPrefix())
            {
                // Remove it from the prefix table, if it exists there.
                operatorMap.remove(OpSymbol.Fixity.Pre);
            }
            else if ((operatorMap != null) && (opSymbol.isPostfix() || opSymbol.isInfix()))
            {
                // Remove it from the postfix/infix table, if it exists there.
                operatorMap.remove(OpSymbol.Fixity.Post);
                operatorMap.remove(OpSymbol.Fixity.In);
            }
        }
    }
Sets the priority and associativity of a named operator in this table. This method may be used to remove
operators by some implementations, through a special setting of the priority value. A priority value of zero will
remove any existing operator matching the fixity of the one specified (that is pre, or post/infix). To be
accepted, the operator must have a priority between 0 and 1200 inclusive, and can only be a postfix operator when
an infix is not already defined with the same name, and similarly for infix operators when a postfix operator is
already defined.

@param name          The interned name of the operator to set in the table.
@param textName      The text name of the operator to set in the table.
@param priority      The priority of the operator. Zero removes the operator.
@param associativity The associativity of the operator.