use of de.bmoth.parser.ast.nodes.FormulaNode in project bmoth by hhu-stups.
the class ASTTransformationTest method testMemberOfIntervalInsideComprehensionToLeqGeq.
@Test
public void testMemberOfIntervalInsideComprehensionToLeqGeq() {
String formula = "sc = {a | a : 1..7}";
FormulaNode formulaNode = parseFormula(formula);
formulaNode = AstTransformationsForZ3.transformFormulaNode(formulaNode);
assertEquals("EQUAL(sc,SET_COMPREHENSION(a,AND(GREATER_EQUAL(a,1),LESS_EQUAL(a,7))))", formulaNode.getFormula().toString());
}
use of de.bmoth.parser.ast.nodes.FormulaNode 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.ast.nodes.FormulaNode in project bmoth by hhu-stups.
the class NumbersTest method productTest.
@Test
public void productTest() throws ParserException {
String formula = "x = 2 * 3";
FormulaNode formulaNode = Parser.getFormulaAsSemanticAst(formula);
assertEquals(PREDICATE_FORMULA, formulaNode.getFormulaType());
DeclarationNode declarationNode = formulaNode.getImplicitDeclarations().get(0);
assertEquals("x", declarationNode.getName());
assertEquals(INTEGER, declarationNode.getType().toString());
}
use of de.bmoth.parser.ast.nodes.FormulaNode in project bmoth by hhu-stups.
the class NumbersTest method greaterEqualTest.
@Test
public void greaterEqualTest() throws ParserException {
String formula = "x >= 2";
FormulaNode formulaNode = Parser.getFormulaAsSemanticAst(formula);
assertEquals(PREDICATE_FORMULA, formulaNode.getFormulaType());
DeclarationNode declarationNode = formulaNode.getImplicitDeclarations().get(0);
assertEquals("x", declarationNode.getName());
assertEquals(INTEGER, declarationNode.getType().toString());
}
use of de.bmoth.parser.ast.nodes.FormulaNode in project bmoth by hhu-stups.
the class NumbersTest method minimumTest.
@Test
public void minimumTest() throws ParserException {
String formula = "x = min({1,2})";
FormulaNode formulaNode = Parser.getFormulaAsSemanticAst(formula);
assertEquals(PREDICATE_FORMULA, formulaNode.getFormulaType());
DeclarationNode declarationNode = formulaNode.getImplicitDeclarations().get(0);
assertEquals("x", declarationNode.getName());
assertEquals(INTEGER, declarationNode.getType().toString());
}
Aggregations