Search in sources :

Example 1 with AAtomTerm

use of de.prob.core.sablecc.node.AAtomTerm in project probparsers by bendisposto.

the class PrologTermGenerator method toPrologTerm.

private static PrologTerm toPrologTerm(final PTerm node) {
    PrologTerm term;
    if (node instanceof ANumberTerm) {
        String text = ((ANumberTerm) node).getNumber().getText();
        term = new IntegerPrologTerm(new BigInteger(text));
    } else if (node instanceof AAtomTerm) {
        String text = ((AAtomTerm) node).getName().getText();
        if ("[]".equals(text)) {
            term = new ListPrologTerm(EMPTY_PROLOG_LIST);
        } else {
            text = removeQuotes(text);
            term = new CompoundPrologTerm(text);
        }
    } else if (node instanceof ATerm) {
        ATerm aterm = (ATerm) node;
        int listSize = getListSize(node);
        if (listSize >= 0) {
            PrologTerm[] list = new PrologTerm[listSize];
            fillListWithElements(list, aterm);
            term = new ListPrologTerm(list);
        } else {
            String functor = removeQuotes(aterm.getFunctor().getText());
            PrologTerm[] params = evalParameters((AParams) aterm.getParams());
            term = new CompoundPrologTerm(functor, params);
        }
    } else if (node instanceof AVariableTerm) {
        String text = removeQuotes(((AVariableTerm) node).getVariable().getText());
        term = new VariablePrologTerm(text);
    } else
        throw new IllegalStateException("Unexpected subclass of PTerm: " + node.getClass().getCanonicalName());
    return term;
}
Also used : VariablePrologTerm(de.prob.prolog.term.VariablePrologTerm) CompoundPrologTerm(de.prob.prolog.term.CompoundPrologTerm) ListPrologTerm(de.prob.prolog.term.ListPrologTerm) PrologTerm(de.prob.prolog.term.PrologTerm) VariablePrologTerm(de.prob.prolog.term.VariablePrologTerm) IntegerPrologTerm(de.prob.prolog.term.IntegerPrologTerm) AAtomTerm(de.prob.core.sablecc.node.AAtomTerm) ListPrologTerm(de.prob.prolog.term.ListPrologTerm) ANumberTerm(de.prob.core.sablecc.node.ANumberTerm) ATerm(de.prob.core.sablecc.node.ATerm) BigInteger(java.math.BigInteger) CompoundPrologTerm(de.prob.prolog.term.CompoundPrologTerm) IntegerPrologTerm(de.prob.prolog.term.IntegerPrologTerm) AVariableTerm(de.prob.core.sablecc.node.AVariableTerm)

Aggregations

AAtomTerm (de.prob.core.sablecc.node.AAtomTerm)1 ANumberTerm (de.prob.core.sablecc.node.ANumberTerm)1 ATerm (de.prob.core.sablecc.node.ATerm)1 AVariableTerm (de.prob.core.sablecc.node.AVariableTerm)1 CompoundPrologTerm (de.prob.prolog.term.CompoundPrologTerm)1 IntegerPrologTerm (de.prob.prolog.term.IntegerPrologTerm)1 ListPrologTerm (de.prob.prolog.term.ListPrologTerm)1 PrologTerm (de.prob.prolog.term.PrologTerm)1 VariablePrologTerm (de.prob.prolog.term.VariablePrologTerm)1 BigInteger (java.math.BigInteger)1