lojix/logic/src/main/com/thesett/aima/logic/fol/isoprologparser/DynamicOperatorParser.java
public Term parseOperators(Term[] terms) throws SourceCodeException
    {
        // Initialize the parsers state.
        stack.offer(0);
        state = 0;
        position = 0;
        nextTerm = null;

        // Consume the terms from left to right.
        for (position = 0; position <= terms.length;)
        {
            Symbol nextSymbol;

            // Decide what the next symbol to parse is; candidate op, term or final.
            if (position < terms.length)
            {
                nextTerm = terms[position];

                if (nextTerm instanceof CandidateOpSymbol)
                {
                    nextSymbol = Symbol.Op;
                }
                else
                {
                    nextSymbol = Symbol.Term;
                }
            }
            else
            {
                nextSymbol = Symbol.Final;
            }

            // Look in the action table to find the action associated with the current symbol and state.
            Action action = actionTable[state][nextSymbol.ordinal()];

            // Apply the action.
            action.apply();
        }

        return (Functor) outputStack.poll();
    }
public Term parseOperators(Term[] terms) throws SourceCodeException
    {
        // Initialize the parsers state.
        stack.offer(0);
        state = 0;
        position = 0;
        nextTerm = null;

        // Consume the terms from left to right.
        for (position = 0; position <= terms.length;)
        {
            Symbol nextSymbol;

            // Decide what the next symbol to parse is; candidate op, term or final.
            if (position < terms.length)
            {
                nextTerm = terms[position];

                if (nextTerm instanceof CandidateOpSymbol)
                {
                    nextSymbol = Symbol.Op;
                }
                else
                {
                    nextSymbol = Symbol.Term;
                }
            }
            else
            {
                nextSymbol = Symbol.Final;
            }

            // Look in the action table to find the action associated with the current symbol and state.
            Action action = actionTable[state][nextSymbol.ordinal()];

            // Apply the action.
            action.apply();
        }

        return (Functor) outputStack.poll();
    }
Parses a flat list of terms, which are literals, variables, functors, or operators into a tree in such a way that
the operators associativity and precendence is obeyed.

@param  terms A flat list of terms possibly containing operators, to be parsed.

@return The functor at the root of the sequence of terms parsed into an abstract syntax tree.

@throws SourceCodeException If the list of terms does not form a valid syntactical construction under the current
set of defined operators.