use of de.be4.ltl.core.parser.LtlParseException 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
}
}
}
use of de.be4.ltl.core.parser.LtlParseException in project probparsers by bendisposto.
the class TemporalLogicParser method generatePrologTerm.
public PrologTerm generatePrologTerm(final String formula, final String stateID) throws LtlParseException {
T ast;
try {
ast = parseFormula(formula);
} catch (IOException e) {
String msg = "StringReader should not cause IOExceptions";
throw new IllegalStateException(msg);
}
StructuredPrologOutput pto = new StructuredPrologOutput();
try {
applyPrologGenerator(pto, stateID, specParser, ast);
} catch (LtlAdapterException e) {
throw e.getOriginalException();
}
pto.fullstop();
return pto.getSentences().iterator().next();
}
use of de.be4.ltl.core.parser.LtlParseException in project probparsers by bendisposto.
the class LTLFormulaVisitor method parseBPredicate.
private de.be4.classicalb.core.parser.node.Start parseBPredicate(String text) {
String bPredicate = "#PREDICATE " + text;
BParser parser = new BParser("Testing");
de.be4.classicalb.core.parser.node.Start start = null;
try {
start = parser.parse(bPredicate, false);
} catch (BCompoundException e) {
throw new LTLParseException(e.getMessage());
}
return start;
}
use of de.be4.ltl.core.parser.LtlParseException 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());
}
use of de.be4.ltl.core.parser.LtlParseException in project probparsers by bendisposto.
the class CtlParser method parseFormula.
protected Start parseFormula(final String formula) throws LtlParseException, IOException {
StringReader reader = new StringReader(formula);
PushbackReader r = new PushbackReader(reader);
Lexer l = new CtlLexer(r);
Parser p = new Parser(l);
Start ast = null;
try {
ast = p.parse();
} catch (ParserException e) {
final UniversalToken token = UniversalToken.createToken(e.getToken());
throw new LtlParseException(token, e.getLocalizedMessage());
} catch (LexerException e) {
throw new LtlParseException(null, e.getLocalizedMessage());
}
return ast;
}
Aggregations