Search in sources :

Example 26 with PrologTerm

use of de.prob.prolog.term.PrologTerm in project probparsers by bendisposto.

the class StructuredPrologOutput method closeTerm.

public IPrologTermOutput closeTerm() {
    PrologTerm[] elements = getArguments();
    final String functor = currentFunctor;
    popFromStack();
    addArgument(new CompoundPrologTerm(functor, elements));
    return this;
}
Also used : CompoundPrologTerm(de.prob.prolog.term.CompoundPrologTerm) CompoundPrologTerm(de.prob.prolog.term.CompoundPrologTerm) PrologTerm(de.prob.prolog.term.PrologTerm) ListPrologTerm(de.prob.prolog.term.ListPrologTerm) VariablePrologTerm(de.prob.prolog.term.VariablePrologTerm) IntegerPrologTerm(de.prob.prolog.term.IntegerPrologTerm)

Example 27 with PrologTerm

use of de.prob.prolog.term.PrologTerm in project probparsers by bendisposto.

the class CliBParser method parseTemporalFormula.

private static void parseTemporalFormula(BufferedReader in, final TemporalLogicParser<?> parser) throws IOException {
    String theFormula;
    PrologTermStringOutput strOutput = new PrologTermStringOutput();
    theFormula = in.readLine();
    try {
        final PrologTerm term = parser.generatePrologTerm(theFormula, null);
        strOutput.openTerm("ltl").printTerm(term).closeTerm();
    } catch (LtlParseException e) {
        strOutput.openTerm("syntax_error").printAtom(e.getLocalizedMessage()).closeTerm();
    }
    strOutput.fullstop();
    // A Friendly Reminder: strOutput includes a newline!
    print(strOutput.toString());
}
Also used : PrologTermStringOutput(de.prob.prolog.output.PrologTermStringOutput) PrologTerm(de.prob.prolog.term.PrologTerm) LtlParseException(de.be4.ltl.core.parser.LtlParseException)

Example 28 with PrologTerm

use of de.prob.prolog.term.PrologTerm 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)

Example 29 with PrologTerm

use of de.prob.prolog.term.PrologTerm in project probparsers by bendisposto.

the class FastReadTransformer method write.

public String write() {
    Collection<PrologTerm> sentences = spo.getSentences();
    if (sentences.isEmpty())
        throw new IllegalArgumentException(EMPTY_MSG);
    if (sentences.size() > 1)
        throw new IllegalArgumentException(MULTI_MSG);
    PrologTerm term = sentences.iterator().next();
    fastwrite(term);
    return sb.toString();
}
Also used : CompoundPrologTerm(de.prob.prolog.term.CompoundPrologTerm) PrologTerm(de.prob.prolog.term.PrologTerm) ListPrologTerm(de.prob.prolog.term.ListPrologTerm) VariablePrologTerm(de.prob.prolog.term.VariablePrologTerm) IntegerPrologTerm(de.prob.prolog.term.IntegerPrologTerm)

Example 30 with PrologTerm

use of de.prob.prolog.term.PrologTerm in project probparsers by bendisposto.

the class FastReadTransformer method write.

private void write(PrologTerm cp) {
    if (cp.isAtom()) {
        sb.append("A");
        sb.append(cp.getFunctor());
        sb.append(ZERO);
    } else {
        sb.append("S");
        sb.append(cp.getFunctor());
        sb.append(ZERO);
        sb.append((char) cp.getArity());
        for (int i = 1; i <= cp.getArity(); i++) {
            PrologTerm argument = cp.getArgument(i);
            fastwrite(argument);
        }
    }
}
Also used : CompoundPrologTerm(de.prob.prolog.term.CompoundPrologTerm) PrologTerm(de.prob.prolog.term.PrologTerm) ListPrologTerm(de.prob.prolog.term.ListPrologTerm) VariablePrologTerm(de.prob.prolog.term.VariablePrologTerm) IntegerPrologTerm(de.prob.prolog.term.IntegerPrologTerm)

Aggregations

PrologTerm (de.prob.prolog.term.PrologTerm)103 ListPrologTerm (de.prob.prolog.term.ListPrologTerm)86 CompoundPrologTerm (de.prob.prolog.term.CompoundPrologTerm)85 Test (org.junit.Test)64 IntegerPrologTerm (de.prob.prolog.term.IntegerPrologTerm)11 StructuredPrologOutput (de.prob.prolog.output.StructuredPrologOutput)10 VariablePrologTerm (de.prob.prolog.term.VariablePrologTerm)8 Transition (de.prob.statespace.Transition)5 IEvalElement (de.prob.animator.domainobjects.IEvalElement)4 ArrayList (java.util.ArrayList)4 CheckBooleanPropertyCommand (de.prob.animator.command.CheckBooleanPropertyCommand)3 AbstractEvalResult (de.prob.animator.domainobjects.AbstractEvalResult)3 EvalResult (de.prob.animator.domainobjects.EvalResult)3 ISimplifiedROMap (de.prob.parser.ISimplifiedROMap)3 IPrologTermOutput (de.prob.prolog.output.IPrologTermOutput)3 RecursiveMachineLoader (de.be4.classicalb.core.parser.analysis.prolog.RecursiveMachineLoader)2 LtlParseException (de.be4.ltl.core.parser.LtlParseException)2 ClassicalB (de.prob.animator.domainobjects.ClassicalB)2 ComputationNotCompletedResult (de.prob.animator.domainobjects.ComputationNotCompletedResult)2 StateError (de.prob.animator.domainobjects.StateError)2