Search in sources :

Example 1 with ParserException

use of de.bmoth.parser.ParserException in project bmoth by hhu-stups.

the class TestTypechecker method getFormulaTypes.

public static Map<String, String> getFormulaTypes(String formula) {
    FormulaNode formulaNode;
    try {
        formulaNode = Parser.getFormulaAsSemanticAst(formula);
        HashMap<String, String> map = new HashMap<>();
        for (DeclarationNode decl : formulaNode.getImplicitDeclarations()) {
            map.put(decl.getName(), decl.getType().toString());
        }
        return map;
    } catch (ParserException e) {
        fail(e.getMessage());
        return null;
    }
}
Also used : ParserException(de.bmoth.parser.ParserException) FormulaNode(de.bmoth.parser.ast.nodes.FormulaNode) HashMap(java.util.HashMap) DeclarationNode(de.bmoth.parser.ast.nodes.DeclarationNode)

Example 2 with ParserException

use of de.bmoth.parser.ParserException in project bmoth by hhu-stups.

the class ReplViewModel method processPredicate.

void processPredicate() {
    String predicate = code.get().substring(code.get().lastIndexOf('\n') + 1);
    FormulaNode node;
    try {
        node = Parser.getFormulaAsSemanticAst(predicate);
        boolean concatFlag = false;
        if (node.getFormulaType() != PREDICATE_FORMULA) {
            predicate = "x=" + predicate;
            FormulaNode concatNode;
            concatNode = Parser.getFormulaAsSemanticAst(predicate);
            if (concatNode.getFormulaType() != PREDICATE_FORMULA) {
                throw new IllegalArgumentException("Input can not be extended to a predicate via an additional variable.");
            } else {
                concatFlag = true;
            }
        }
        BoolExpr constraint;
        constraint = FormulaToZ3Translator.translatePredicate(predicate, ctx);
        s.add(constraint);
        Status check = s.check();
        if (check == Status.SATISFIABLE) {
            Model model = s.getModel();
            String output = new PrettyPrinter(model).getOutput();
            if (model.toString().equals("")) {
                code.set(code.get() + "\n" + check + "\n");
            } else {
                if (concatFlag) {
                    String concatOutput = output.substring(3, output.length() - 1);
                    code.set(code.get() + "\n" + concatOutput + "\n");
                } else {
                    code.set(code.get() + "\n" + output + "\n");
                }
            }
        } else {
            code.set(code.get() + "\nUNSATISFIABLE\n");
        }
    } catch (ParserException e) {
        // TODO replace this
        throw new RuntimeException(e);
    }
}
Also used : ParserException(de.bmoth.parser.ParserException) FormulaNode(de.bmoth.parser.ast.nodes.FormulaNode) ViewModel(de.saxsys.mvvmfx.ViewModel)

Example 3 with ParserException

use of de.bmoth.parser.ParserException in project bmoth by hhu-stups.

the class AppView method handleInitialStateExists.

// </editor-fold>
public void handleInitialStateExists() {
    if (codeArea.getText().replaceAll("\\s+", "").length() > 0) {
        if (hasChanged || machineNode == null) {
            handleSave();
            try {
                machineNode = Parser.getMachineAsSemanticAst(codeArea.getText());
            } catch (ParserException e) {
                EventBus eventBus = EventBusProvider.getInstance().getEventBus();
                eventBus.post(new ErrorEvent("Parse error", e.toString(), e));
                return;
            }
        }
        InitialStateExistsCheckingResult result = InitialStateExistsChecker.doInitialStateExistsCheck(machineNode);
        showResultAlert(result.getResult());
    }
}
Also used : ParserException(de.bmoth.parser.ParserException) ErrorEvent(de.bmoth.eventbus.ErrorEvent) EventBus(com.google.common.eventbus.EventBus) InitialStateExistsCheckingResult(de.bmoth.checkers.initialstateexists.InitialStateExistsCheckingResult)

Example 4 with ParserException

use of de.bmoth.parser.ParserException 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)

Aggregations

ParserException (de.bmoth.parser.ParserException)4 FormulaNode (de.bmoth.parser.ast.nodes.FormulaNode)2 EventBus (com.google.common.eventbus.EventBus)1 InitialStateExistsCheckingResult (de.bmoth.checkers.initialstateexists.InitialStateExistsCheckingResult)1 ErrorEvent (de.bmoth.eventbus.ErrorEvent)1 DeclarationNode (de.bmoth.parser.ast.nodes.DeclarationNode)1 MachineNode (de.bmoth.parser.ast.nodes.MachineNode)1 ViewModel (de.saxsys.mvvmfx.ViewModel)1 HashMap (java.util.HashMap)1