Search in sources :

Example 81 with PrologTerm

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

the class PrologTermGenerator method toPrologTerm.

public static PrologTerm toPrologTerm(final Start node) throws ResultParserException {
    PResult topnode = node.getPResult();
    PrologTerm term = null;
    if (topnode instanceof AYesResult) {
        term = toPrologTerm(((AYesResult) topnode).getTerm());
    } else if (topnode instanceof ANoResult) {
        term = null;
    } else if (topnode instanceof AInterruptedResult) {
        term = null;
    } else if (topnode instanceof AExceptionResult) {
        String message = "ProB raised an exception: " + ((AExceptionResult) topnode).getString().getText();
        throw new ResultParserException(message, null);
    } else
        throw new IllegalStateException("Unknown subclass of PResult: " + topnode.getClass().getCanonicalName());
    return term;
}
Also used : AYesResult(de.prob.core.sablecc.node.AYesResult) AInterruptedResult(de.prob.core.sablecc.node.AInterruptedResult) AExceptionResult(de.prob.core.sablecc.node.AExceptionResult) PResult(de.prob.core.sablecc.node.PResult) ANoResult(de.prob.core.sablecc.node.ANoResult) 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)

Example 82 with PrologTerm

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

the class BParser method getASTasFastProlog.

private static String getASTasFastProlog(final BParser parser, final File bfile, final Start tree, final ParsingBehaviour parsingBehaviour, IDefinitionFileProvider contentProvider) throws BCompoundException {
    final RecursiveMachineLoader rml = new RecursiveMachineLoader(bfile.getParent(), contentProvider, parsingBehaviour);
    rml.loadAllMachines(bfile, tree, parser.getDefinitions());
    StructuredPrologOutput structuredPrologOutput = new StructuredPrologOutput();
    rml.printAsProlog(structuredPrologOutput);
    Collection<PrologTerm> sentences = structuredPrologOutput.getSentences();
    StructuredPrologOutput output = new StructuredPrologOutput();
    output.openList();
    for (PrologTerm term : sentences) {
        output.printTerm(term);
    }
    output.closeList();
    output.fullstop();
    FastReadTransformer transformer = new FastReadTransformer(output);
    return transformer.write();
}
Also used : StructuredPrologOutput(de.prob.prolog.output.StructuredPrologOutput) RecursiveMachineLoader(de.be4.classicalb.core.parser.analysis.prolog.RecursiveMachineLoader) PrologTerm(de.prob.prolog.term.PrologTerm)

Example 83 with PrologTerm

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

the class BindingGenerator method createBinding.

private static Map<String, PrologTerm> createBinding(final ListPrologTerm list) {
    Map<String, PrologTerm> result;
    result = new HashMap<String, PrologTerm>();
    for (int i = 0; i < list.size(); i++) {
        PrologTerm element = list.get(i);
        if (element.isTerm()) {
            CompoundPrologTerm binding = (CompoundPrologTerm) element;
            if (binding.getArity() == 2 && "=".equals(binding.getFunctor())) {
                extractBinding(result, binding);
            } else
                throw new IllegalArgumentException("Expected binding (=/2), but was " + binding.getFunctor() + "/" + String.valueOf(binding.getArity()));
        } else
            throw new IllegalArgumentException("Expected binding but was not a term");
    }
    return Collections.unmodifiableMap(result);
}
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 84 with PrologTerm

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

the class BindingGenerator method extractBinding.

private static void extractBinding(final Map<String, PrologTerm> result, final CompoundPrologTerm binding) {
    PrologTerm varterm = binding.getArgument(1);
    if (varterm.isAtom()) {
        String name = ((CompoundPrologTerm) varterm).getFunctor();
        PrologTerm value = binding.getArgument(2);
        result.put(name, value);
    } else
        throw new IllegalArgumentException("Expected atomic variable name, but found " + varterm.toString());
}
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 85 with PrologTerm

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

the class CSPAssertionsCommand method processResult.

@Override
public void processResult(final ISimplifiedROMap<String, PrologTerm> bindings) {
    ListPrologTerm prologTermResults = BindingGenerator.getList(bindings.get(RESULT_VARIABLE));
    ListPrologTerm prologTermResultTraces = BindingGenerator.getList(bindings.get(RESULT_TRACES_VARIABLE));
    for (PrologTerm term : prologTermResults) {
        if (term != null) {
            results.add(term.getFunctor());
        }
    }
    for (PrologTerm term : prologTermResultTraces) {
        if (term instanceof ListPrologTerm) {
            resultTraces.add(BindingGenerator.getList(term));
        }
    }
}
Also used : ListPrologTerm(de.prob.prolog.term.ListPrologTerm) PrologTerm(de.prob.prolog.term.PrologTerm) ListPrologTerm(de.prob.prolog.term.ListPrologTerm)

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