Search in sources :

Example 1 with PrologTerm

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

the class LtlConsoleParser method main.

public static void main(final String[] args) {
    ConsoleOptions options = new ConsoleOptions();
    options.addOption(CLI_LANG, "set language for atomic propositions, etc. (e.g. none, B)", 1);
    options.addOption(CLI_OUT, "set output file, use stdout if omitted", 1);
    options.addOption(CLI_LTL, "use LTL (default)");
    options.addOption(CLI_CTL, "use CTL instead of LTL");
    options.setIntro("usage: LtlConsoleParser [options] <LTL file>\n\n" + "If the file is omitted, stdin is used\n" + "Available options are:");
    options.addOption(CLI_HELP, "print this message");
    options.parseOptions(args);
    if (options.isOptionSet(CLI_HELP)) {
        options.printUsage(System.out);
        return;
    }
    String[] params = options.getRemainingOptions();
    if (params.length > 1) {
        options.printUsage(System.out);
        System.exit(-1);
        return;
    }
    if (options.isOptionSet(CLI_LTL) && options.isOptionSet(CLI_CTL)) {
        System.err.println("Incopatible options -ltl and -ctl given.");
        System.exit(-1);
        return;
    }
    final Mode mode = options.isOptionSet(CLI_CTL) ? Mode.CTL : Mode.LTL;
    // please note: createOutputStream might call System.exit()
    final OutputStream out = createOutputStream(options);
    final String lang = options.isOptionSet(CLI_LANG) ? options.getOptions(CLI_LANG)[0] : null;
    final ProBParserBase extParser = getExtensionParser(lang);
    final IPrologTermOutput pto = new PrologTermOutput(out, false);
    final String input = createInputStream(params, pto);
    if (input != null) {
        final String[] formulas = input.split("###");
        final TemporalLogicParser<?> parser = createParser(extParser, mode);
        pto.openList();
        for (final String formula : formulas) {
            try {
                final PrologTerm term = parser.generatePrologTerm(formula, null);
                pto.openTerm("ltl").printTerm(term).closeTerm();
            } catch (LtlParseException e) {
                pto.openTerm("syntax_error").printAtom(e.getLocalizedMessage()).closeTerm();
            }
        }
        pto.closeList();
    }
    pto.fullstop();
    pto.flush();
    if (options.isOptionSet(CLI_OUT)) {
        try {
            out.close();
        } catch (IOException e) {
        // ignore
        }
    }
}
Also used : PrologTermOutput(de.prob.prolog.output.PrologTermOutput) IPrologTermOutput(de.prob.prolog.output.IPrologTermOutput) OutputStream(java.io.OutputStream) FileOutputStream(java.io.FileOutputStream) IOException(java.io.IOException) ProBParserBase(de.prob.parserbase.ProBParserBase) PrologTerm(de.prob.prolog.term.PrologTerm) IPrologTermOutput(de.prob.prolog.output.IPrologTermOutput) LtlParseException(de.be4.ltl.core.parser.LtlParseException)

Example 2 with PrologTerm

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

the class AbstractTest method check.

protected void check(final String input, final PrologTerm expectedTerm) throws LtlParseException {
    final PrologTerm term = parse(input);
    Assert.assertEquals(expectedTerm, term);
}
Also used : PrologTerm(de.prob.prolog.term.PrologTerm)

Example 3 with PrologTerm

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

the class PrologGeneratorTest method testGlobally.

@Test
public void testGlobally() throws Exception {
    final PrologTerm expected = new CompoundPrologTerm("globally", TERM_TRUE);
    check("G true ", expected);
}
Also used : CompoundPrologTerm(de.prob.prolog.term.CompoundPrologTerm) CompoundPrologTerm(de.prob.prolog.term.CompoundPrologTerm) ListPrologTerm(de.prob.prolog.term.ListPrologTerm) PrologTerm(de.prob.prolog.term.PrologTerm) Test(org.junit.Test)

Example 4 with PrologTerm

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

the class PrologGeneratorTest method testSince.

@Test
public void testSince() throws Exception {
    final PrologTerm expected = new CompoundPrologTerm("since", TERM_FALSE, TERM_TRUE);
    check("false S true ", expected);
}
Also used : CompoundPrologTerm(de.prob.prolog.term.CompoundPrologTerm) CompoundPrologTerm(de.prob.prolog.term.CompoundPrologTerm) ListPrologTerm(de.prob.prolog.term.ListPrologTerm) PrologTerm(de.prob.prolog.term.PrologTerm) Test(org.junit.Test)

Example 5 with PrologTerm

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

the class PrologGeneratorTest method testYesterday.

@Test
public void testYesterday() throws Exception {
    final PrologTerm expected = new CompoundPrologTerm("yesterday", TERM_TRUE);
    check("Y true ", expected);
}
Also used : CompoundPrologTerm(de.prob.prolog.term.CompoundPrologTerm) CompoundPrologTerm(de.prob.prolog.term.CompoundPrologTerm) ListPrologTerm(de.prob.prolog.term.ListPrologTerm) PrologTerm(de.prob.prolog.term.PrologTerm) Test(org.junit.Test)

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