Search in sources :

Example 1 with ArrayValueStack

use of com.github.fge.grappa.stack.ArrayValueStack in project narchy by automenta.

the class NarseseParser method popTerms.

FasterList<Term> popTerms(Op[] op) /* hint */
{
    FasterList tt = new FasterList(8);
    ArrayValueStack<Object> stack = (ArrayValueStack) getContext().getValueStack();
    while (!stack.isEmpty()) {
        Object p = pop();
        if (p instanceof Object[]) {
            // it's an array so unpack by pushing everything back onto the stack except the last item which will be used as normal below
            Object[] pp = (Object[]) p;
            if (pp.length > 1) {
                for (int i = pp.length - 1; i >= 1; i--) {
                    stack.push(pp[i]);
                }
            }
            p = pp[0];
        }
        if (p == functionalForm) {
            op[0] = ATOM;
            break;
        }
        // beginning of stack frame for this term
        if (p == Compound.class)
            break;
        if (p instanceof String) {
            // throw new RuntimeException("string not expected here");
            // Term t = $.the((String) p);
            tt.add(Atomic.the((String) p));
        } else if (p instanceof Term) {
            if (p == Null) {
                stack.clear();
                return new FasterList(1).addingAll(Null);
            }
            tt.add(p);
        } else if (p instanceof Op) {
            if (op != null)
                op[0] = (Op) p;
        }
    }
    tt.reverse();
    return tt;
}
Also used : Op(nars.Op) FasterList(jcog.list.FasterList) Term(nars.term.Term) ArrayValueStack(com.github.fge.grappa.stack.ArrayValueStack)

Aggregations

ArrayValueStack (com.github.fge.grappa.stack.ArrayValueStack)1 FasterList (jcog.list.FasterList)1 Op (nars.Op)1 Term (nars.term.Term)1