Search in sources :

Example 1 with CtlParser

use of de.be4.ltl.core.parser.CtlParser in project probparsers by bendisposto.

the class CliBParser method runPRepl.

private static void runPRepl(final ParsingBehaviour behaviour) throws IOException, FileNotFoundException {
    PrintStream out;
    ServerSocket serverSocket = new ServerSocket(0, 50, InetAddress.getLoopbackAddress());
    // write port number as prolog term
    System.out.println(serverSocket.getLocalPort() + ".");
    socket = serverSocket.accept();
    socketOutputStream = socket.getOutputStream();
    BufferedReader in = new BufferedReader(new InputStreamReader(socket.getInputStream(), encoding));
    String line = "";
    MockedDefinitions context = new MockedDefinitions();
    boolean terminate = false;
    while (!terminate) {
        line = in.readLine();
        EPreplCommands command;
        String theFormula;
        if (line == null) {
            // the prob instance has been terminated. exit gracefully
            command = EPreplCommands.halt;
        } else {
            command = EPreplCommands.valueOf(line);
        }
        switch(command) {
            case version:
                print(CliBParser.getBuildRevision() + System.lineSeparator());
                break;
            case definition:
                String name = in.readLine();
                String type = in.readLine();
                String parameterCount = in.readLine();
                context.addMockedDefinition(name, type, parameterCount);
                break;
            case machine:
                String filename = in.readLine();
                String outFile = in.readLine();
                out = new PrintStream(outFile, encoding);
                final File bfile = new File(filename);
                int returnValue;
                ByteArrayOutputStream baos = new ByteArrayOutputStream();
                PrintStream ps = new PrintStream(baos);
                try {
                    final String fileName = bfile.getName();
                    final String extension = fileName.substring(fileName.lastIndexOf(".") + 1);
                    if (extension.equals("rmch")) {
                        returnValue = RulesProject.parseProject(bfile, behaviour, out, ps);
                    } else {
                        final BParser parser = new BParser(bfile.getAbsolutePath());
                        returnValue = parser.fullParsing(bfile, behaviour, out, ps);
                    }
                    context = new MockedDefinitions();
                } catch (Exception e) {
                    e.printStackTrace();
                    returnValue = -4;
                } finally {
                    if (true) {
                        out.close();
                    }
                }
                if (returnValue == 0) {
                    print("exit(" + returnValue + ")." + System.lineSeparator());
                } else {
                    String output = baos.toString().replace(System.lineSeparator(), " ").trim();
                    print(output + System.lineSeparator());
                }
                break;
            case formula:
                theFormula = "#FORMULA\n" + in.readLine();
                parseFormula(theFormula, context);
                break;
            case expression:
                theFormula = "#EXPRESSION\n" + in.readLine();
                parseFormula(theFormula, context);
                break;
            case predicate:
                theFormula = "#PREDICATE\n" + in.readLine();
                parseFormula(theFormula, context);
                break;
            case substitution:
                theFormula = "#SUBSTITUTION\n" + in.readLine();
                parseFormula(theFormula, context);
                break;
            case extendedformula:
                theFormula = "#FORMULA\n" + in.readLine();
                parseExtendedFormula(theFormula, context);
                break;
            case extendedexpression:
                theFormula = "#EXPRESSION\n" + in.readLine();
                parseExtendedFormula(theFormula, context);
                break;
            case extendedpredicate:
                theFormula = "#PREDICATE\n" + in.readLine();
                parseExtendedFormula(theFormula, context);
                break;
            case extendedsubstitution:
                theFormula = "#SUBSTITUTION\n" + in.readLine();
                parseExtendedFormula(theFormula, context);
                break;
            case ltl:
                String extension = in.readLine();
                final ProBParserBase extParser = LtlConsoleParser.getExtensionParser(extension);
                final TemporalLogicParser<?> parser = new LtlParser(extParser);
                parseTemporalFormula(in, parser);
                break;
            case ctl:
                String extension2 = in.readLine();
                final ProBParserBase extParser2 = LtlConsoleParser.getExtensionParser(extension2);
                final TemporalLogicParser<?> parser2 = new CtlParser(extParser2);
                parseTemporalFormula(in, parser2);
                break;
            case halt:
                socket.close();
                serverSocket.close();
                terminate = true;
                break;
            default:
                throw new UnsupportedOperationException("Unsupported Command " + line);
        }
    }
}
Also used : PrintStream(java.io.PrintStream) InputStreamReader(java.io.InputStreamReader) LtlParser(de.be4.ltl.core.parser.LtlParser) ServerSocket(java.net.ServerSocket) BParser(de.be4.classicalb.core.parser.BParser) ByteArrayOutputStream(java.io.ByteArrayOutputStream) LtlParseException(de.be4.ltl.core.parser.LtlParseException) LexerException(de.be4.classicalb.core.parser.lexer.LexerException) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) BCompoundException(de.be4.classicalb.core.parser.exceptions.BCompoundException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) MockedDefinitions(de.be4.classicalb.core.parser.MockedDefinitions) BufferedReader(java.io.BufferedReader) CtlParser(de.be4.ltl.core.parser.CtlParser) File(java.io.File) ProBParserBase(de.prob.parserbase.ProBParserBase)

Aggregations

BParser (de.be4.classicalb.core.parser.BParser)1 MockedDefinitions (de.be4.classicalb.core.parser.MockedDefinitions)1 BCompoundException (de.be4.classicalb.core.parser.exceptions.BCompoundException)1 LexerException (de.be4.classicalb.core.parser.lexer.LexerException)1 CtlParser (de.be4.ltl.core.parser.CtlParser)1 LtlParseException (de.be4.ltl.core.parser.LtlParseException)1 LtlParser (de.be4.ltl.core.parser.LtlParser)1 ProBParserBase (de.prob.parserbase.ProBParserBase)1 BufferedReader (java.io.BufferedReader)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 File (java.io.File)1 FileNotFoundException (java.io.FileNotFoundException)1 IOException (java.io.IOException)1 InputStreamReader (java.io.InputStreamReader)1 PrintStream (java.io.PrintStream)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 ServerSocket (java.net.ServerSocket)1