Search in sources :

Example 6 with FormulaNode

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());
}
Also used : FormulaNode(de.bmoth.parser.ast.nodes.FormulaNode) Test(org.junit.Test)

Example 7 with FormulaNode

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);
    }
}
Also used : ParserException(de.bmoth.parser.ParserException) FormulaNode(de.bmoth.parser.ast.nodes.FormulaNode) ViewModel(de.saxsys.mvvmfx.ViewModel)

Example 8 with FormulaNode

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());
}
Also used : FormulaNode(de.bmoth.parser.ast.nodes.FormulaNode) DeclarationNode(de.bmoth.parser.ast.nodes.DeclarationNode) Test(org.junit.Test)

Example 9 with FormulaNode

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());
}
Also used : FormulaNode(de.bmoth.parser.ast.nodes.FormulaNode) DeclarationNode(de.bmoth.parser.ast.nodes.DeclarationNode) Test(org.junit.Test)

Example 10 with FormulaNode

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());
}
Also used : FormulaNode(de.bmoth.parser.ast.nodes.FormulaNode) DeclarationNode(de.bmoth.parser.ast.nodes.DeclarationNode) Test(org.junit.Test)

Aggregations

FormulaNode (de.bmoth.parser.ast.nodes.FormulaNode)106 Test (org.junit.Test)102 DeclarationNode (de.bmoth.parser.ast.nodes.DeclarationNode)91 Ignore (org.junit.Ignore)27 ParserException (de.bmoth.parser.ParserException)2 BMoThParser (de.bmoth.antlr.BMoThParser)1 FormulaContext (de.bmoth.antlr.BMoThParser.FormulaContext)1 SemanticAstCreator (de.bmoth.parser.ast.SemanticAstCreator)1 TypeErrorException (de.bmoth.parser.ast.TypeErrorException)1 ViewModel (de.saxsys.mvvmfx.ViewModel)1 HashMap (java.util.HashMap)1