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;
}
}
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);
}
}
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());
}
}
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;
}
Aggregations