Search in sources :

Example 41 with FormulaNode

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

the class SetOperationsTest method generalizedUnionTest.

@Test
public void generalizedUnionTest() throws ParserException {
    String formula = "x = union({{4,5}, {1,2}})";
    FormulaNode formulaNode = Parser.getFormulaAsSemanticAst(formula);
    assertEquals(PREDICATE_FORMULA, formulaNode.getFormulaType());
    DeclarationNode declarationNode = formulaNode.getImplicitDeclarations().get(0);
    assertEquals("x", declarationNode.getName());
    assertEquals(POW_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 42 with FormulaNode

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

the class SetOperationsTest method emptySetTest.

@Test
public void emptySetTest() throws ParserException {
    String formula = "x = {} & x <: NAT";
    FormulaNode formulaNode = Parser.getFormulaAsSemanticAst(formula);
    assertEquals(PREDICATE_FORMULA, formulaNode.getFormulaType());
    DeclarationNode declarationNode = formulaNode.getImplicitDeclarations().get(0);
    assertEquals("x", declarationNode.getName());
    assertEquals(POW_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 43 with FormulaNode

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

the class SetOperationsTest method properSubsetTest.

@Test
public void properSubsetTest() throws ParserException {
    String formula = "x <<: 4 .. 10";
    FormulaNode formulaNode = Parser.getFormulaAsSemanticAst(formula);
    assertEquals(PREDICATE_FORMULA, formulaNode.getFormulaType());
    DeclarationNode declarationNode = formulaNode.getImplicitDeclarations().get(0);
    assertEquals("x", declarationNode.getName());
    assertEquals(POW_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 44 with FormulaNode

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

the class Parser method getFormulaAsSemanticAst.

public static FormulaNode getFormulaAsSemanticAst(String inputString) throws ParserException {
    Parser parser = new Parser();
    try {
        FormulaContext formulaContext;
        formulaContext = parser.parseFormula(inputString);
        List<String> warnings = CSTAnalyser.analyseConcreteSyntaxTree(formulaContext);
        FormulaNode formulaNode = parser.getFormulaAst(formulaContext);
        formulaNode.setWarnings(warnings);
        TypeChecker.typecheckFormulaNode(formulaNode);
        return formulaNode;
    } catch (ParseErrorException | TypeErrorException | ScopeException e) {
        throw new ParserException(e);
    }
}
Also used : FormulaNode(de.bmoth.parser.ast.nodes.FormulaNode) TypeErrorException(de.bmoth.parser.ast.TypeErrorException) FormulaContext(de.bmoth.antlr.BMoThParser.FormulaContext) BMoThParser(de.bmoth.antlr.BMoThParser)

Example 45 with FormulaNode

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

the class FunctionsTest method lambdaTest.

@Test
@Ignore
public void lambdaTest() throws ParserException {
    String formula = "x = %z.(z : 1..10|z*z)";
    FormulaNode formulaNode = Parser.getFormulaAsSemanticAst(formula);
    assertEquals(PREDICATE_FORMULA, formulaNode.getFormulaType());
    DeclarationNode declarationNode = formulaNode.getImplicitDeclarations().get(0);
    assertEquals("x", declarationNode.getName());
    assertEquals(POW_INTEGER_INTEGER, declarationNode.getType().toString());
}
Also used : FormulaNode(de.bmoth.parser.ast.nodes.FormulaNode) DeclarationNode(de.bmoth.parser.ast.nodes.DeclarationNode) Ignore(org.junit.Ignore) 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