Search in sources :

Example 16 with MachineNode

use of de.bmoth.parser.ast.nodes.MachineNode in project bmoth by hhu-stups.

the class CliTask method executeBenchmarks.

public void executeBenchmarks() {
    if (times != 0) {
        // first parsing and checking process takes longer and is ignored
        MachineNode machineNode = parseMachine(readMachineContent());
        String result = doModelCheck(getModelChecker(machineNode)).toString();
        for (int i = 1; i <= times; i++) {
            logger.info("Executing benchmark " + i + " of " + times);
            machineNode = parseMachine(readMachineContent());
            parsingTimes += nanoDiffTime;
            result = doModelCheck(getModelChecker(machineNode)).toString();
            checkingTimes += nanoDiffTime;
        }
        StringJoiner resultString = new StringJoiner("\n", "", "");
        resultString.add("Machine: " + machineFile.getName() + ", algorithm: " + algorithm + ", times: " + times);
        resultString.add("Result: " + result);
        resultString.add("Average parsing time: " + (parsingTimes / times) + " ns");
        resultString.add("Average checking time: " + (checkingTimes / times) + " ns");
        logger.info(resultString.toString());
        if (resultFileName != null) {
            try {
                PrintWriter writer = new PrintWriter(resultFileName, "UTF-8");
                writer.println(resultString.toString());
                writer.close();
            } catch (Exception e) {
                logger.warning(e.toString());
            }
        }
    }
}
Also used : StringJoiner(java.util.StringJoiner) IOException(java.io.IOException) ParserException(de.bmoth.parser.ParserException) MachineNode(de.bmoth.parser.ast.nodes.MachineNode) PrintWriter(java.io.PrintWriter)

Example 17 with MachineNode

use of de.bmoth.parser.ast.nodes.MachineNode in project bmoth by hhu-stups.

the class CliTask method execute.

public void execute() {
    if (isBenchmark) {
        executeBenchmarks();
    } else {
        MachineNode machineNode = parseMachine(readMachineContent());
        ModelCheckingResult result = doModelCheck(getModelChecker(machineNode));
        logger.info("Result: " + result.toString());
    }
}
Also used : MachineNode(de.bmoth.parser.ast.nodes.MachineNode) ModelCheckingResult(de.bmoth.modelchecker.ModelCheckingResult)

Example 18 with MachineNode

use of de.bmoth.parser.ast.nodes.MachineNode in project bmoth by hhu-stups.

the class CliTask method parseMachine.

private MachineNode parseMachine(String machineContent) {
    MachineNode machineNode = null;
    try {
        long start = isBenchmark ? System.nanoTime() : 0;
        machineNode = Parser.getMachineAsSemanticAst(machineContent);
        nanoDiffTime = isBenchmark ? System.nanoTime() - start : 0;
    } catch (ParserException e) {
        logger.severe(e.toString());
        System.exit(1);
    }
    if (machineNode == null) {
        logger.severe("Invalid machine");
        System.exit(1);
    }
    return machineNode;
}
Also used : ParserException(de.bmoth.parser.ParserException) MachineNode(de.bmoth.parser.ast.nodes.MachineNode)

Example 19 with MachineNode

use of de.bmoth.parser.ast.nodes.MachineNode in project bmoth by hhu-stups.

the class Parser method getMachineAst.

private MachineNode getMachineAst(StartContext start) throws ScopeException, ParseErrorException {
    MachineAnalyser machineAnalyser = new MachineAnalyser(start);
    SemanticAstCreator astCreator = new SemanticAstCreator(machineAnalyser);
    return (MachineNode) astCreator.getAstNode();
}
Also used : SemanticAstCreator(de.bmoth.parser.ast.SemanticAstCreator) MachineNode(de.bmoth.parser.ast.nodes.MachineNode)

Example 20 with MachineNode

use of de.bmoth.parser.ast.nodes.MachineNode in project bmoth by hhu-stups.

the class Parser method getMachineAsSemanticAst.

public static MachineNode getMachineAsSemanticAst(String inputString) throws ParserException {
    Parser parser = new Parser();
    try {
        StartContext start = parser.parseMachine(inputString);
        List<String> warnings = CSTAnalyser.analyseConcreteSyntaxTree(start);
        MachineNode machineNode = parser.getMachineAst(start);
        machineNode.setWarnings(warnings);
        TypeChecker.typecheckMachineNode(machineNode);
        return machineNode;
    } catch (ParseErrorException | TypeErrorException | ScopeException e) {
        throw new ParserException(e);
    }
}
Also used : StartContext(de.bmoth.antlr.BMoThParser.StartContext) LtlStartContext(de.bmoth.antlr.BMoThParser.LtlStartContext) TypeErrorException(de.bmoth.parser.ast.TypeErrorException) BMoThParser(de.bmoth.antlr.BMoThParser) MachineNode(de.bmoth.parser.ast.nodes.MachineNode)

Aggregations

MachineNode (de.bmoth.parser.ast.nodes.MachineNode)30 Test (org.junit.Test)25 ModelCheckingResult (de.bmoth.modelchecker.ModelCheckingResult)22 ParserException (de.bmoth.parser.ParserException)2 DeclarationNode (de.bmoth.parser.ast.nodes.DeclarationNode)2 Expr (com.microsoft.z3.Expr)1 BMoThParser (de.bmoth.antlr.BMoThParser)1 LtlStartContext (de.bmoth.antlr.BMoThParser.LtlStartContext)1 StartContext (de.bmoth.antlr.BMoThParser.StartContext)1 SemanticAstCreator (de.bmoth.parser.ast.SemanticAstCreator)1 TypeErrorException (de.bmoth.parser.ast.TypeErrorException)1 AnySubstitutionNode (de.bmoth.parser.ast.nodes.AnySubstitutionNode)1 OperationNode (de.bmoth.parser.ast.nodes.OperationNode)1 LTLFormula (de.bmoth.parser.ast.nodes.ltl.LTLFormula)1 IOException (java.io.IOException)1 PrintWriter (java.io.PrintWriter)1 StringJoiner (java.util.StringJoiner)1 Ignore (org.junit.Ignore)1 Benchmark (org.openjdk.jmh.annotations.Benchmark)1