Search in sources :

Example 1 with AIntegerExpression

use of de.be4.classicalb.core.parser.node.AIntegerExpression in project probparsers by bendisposto.

the class RulesMachineChecker method checkFailedRuleErrorTypeOperator.

private void checkFailedRuleErrorTypeOperator(AOperatorPredicate node, final List<PExpression> arguments) {
    if (arguments.size() != 2) {
        this.errorList.add(new CheckException("The FAILED_RULE_ERROR_TYPE predicate operator expects exactly two arguments.", node));
        return;
    }
    PExpression pExpression = node.getIdentifiers().get(0);
    if (!(pExpression instanceof AIdentifierExpression)) {
        this.errorList.add(new CheckException("The first argument of FAILED_RULE_ERROR_TYPE must be an identifier.", node));
        return;
    }
    PExpression secondArg = node.getIdentifiers().get(1);
    if (!(secondArg instanceof AIntegerExpression)) {
        this.errorList.add(new CheckException("The second argument of FAILED_RULE_ERROR_TYPE must be an integer literal.", node));
        return;
    }
    this.referencedRuleOperations.add((AIdentifierExpression) arguments.get(0));
    return;
}
Also used : AIntegerExpression(de.be4.classicalb.core.parser.node.AIntegerExpression) CheckException(de.be4.classicalb.core.parser.exceptions.CheckException) AIdentifierExpression(de.be4.classicalb.core.parser.node.AIdentifierExpression) PExpression(de.be4.classicalb.core.parser.node.PExpression)

Example 2 with AIntegerExpression

use of de.be4.classicalb.core.parser.node.AIntegerExpression in project probparsers by bendisposto.

the class SourcePositionsTest method testAddExpression.

@Test
public void testAddExpression() throws Exception {
    final String testMachine = "#EXPRESSION xx + 5";
    final Start result = getAst(testMachine);
    final AExpressionParseUnit exprParseUnit = (AExpressionParseUnit) result.getPParseUnit();
    assertEquals(1, exprParseUnit.getStartPos().getLine());
    assertEquals(1, exprParseUnit.getStartPos().getPos());
    assertEquals(1, exprParseUnit.getEndPos().getLine());
    assertEquals(19, exprParseUnit.getEndPos().getPos());
    final AAddExpression addExpression = (AAddExpression) exprParseUnit.getExpression();
    assertEquals(1, addExpression.getStartPos().getLine());
    assertEquals(13, addExpression.getStartPos().getPos());
    assertEquals(1, addExpression.getEndPos().getLine());
    assertEquals(19, addExpression.getEndPos().getPos());
    final AIdentifierExpression varExpression = (AIdentifierExpression) addExpression.getLeft();
    assertEquals(1, varExpression.getStartPos().getLine());
    assertEquals(13, varExpression.getStartPos().getPos());
    assertEquals(1, varExpression.getEndPos().getLine());
    assertEquals(15, varExpression.getEndPos().getPos());
    final AIntegerExpression intExpression = (AIntegerExpression) addExpression.getRight();
    assertEquals(1, intExpression.getStartPos().getLine());
    assertEquals(18, intExpression.getStartPos().getPos());
    assertEquals(1, intExpression.getEndPos().getLine());
    assertEquals(19, intExpression.getEndPos().getPos());
}
Also used : AExpressionParseUnit(de.be4.classicalb.core.parser.node.AExpressionParseUnit) AIntegerExpression(de.be4.classicalb.core.parser.node.AIntegerExpression) AAddExpression(de.be4.classicalb.core.parser.node.AAddExpression) Start(de.be4.classicalb.core.parser.node.Start) AIdentifierExpression(de.be4.classicalb.core.parser.node.AIdentifierExpression) Test(org.junit.Test)

Example 3 with AIntegerExpression

use of de.be4.classicalb.core.parser.node.AIntegerExpression in project probparsers by bendisposto.

the class ASTPrologTest method testPartition.

@Test
public void testPartition() {
    final PExpression set = createId("set");
    final PExpression one = new AIntegerExpression(new TIntegerLiteral("1"));
    final PExpression two = new AIntegerExpression(new TIntegerLiteral("2"));
    final PExpression three = new AIntegerExpression(new TIntegerLiteral("3"));
    final APartitionPredicate pred = new APartitionPredicate(set, Arrays.asList(one, two, three));
    final String expected = "partition($,identifier($,set),[integer($,1),integer($,2),integer($,3)])";
    checkAST(0, expected, pred);
}
Also used : AIntegerExpression(de.be4.classicalb.core.parser.node.AIntegerExpression) APartitionPredicate(de.be4.classicalb.core.parser.node.APartitionPredicate) TIntegerLiteral(de.be4.classicalb.core.parser.node.TIntegerLiteral) PExpression(de.be4.classicalb.core.parser.node.PExpression) Test(org.junit.Test)

Example 4 with AIntegerExpression

use of de.be4.classicalb.core.parser.node.AIntegerExpression in project probparsers by bendisposto.

the class ExpressionTest method testProverComprehensionSets.

@Test
public void testProverComprehensionSets() throws Exception {
    final String expression = "SET(i).(i>0)";
    parser.getOptions().setRestrictProverExpressions(false);
    final String expected = "AProverComprehensionSetExpression([AIdentifierExpression([i])],AGreaterPredicate(AIdentifierExpression([i]),AIntegerExpression(0)))";
    final String prover = getExpressionAsString(expression);
    assertEquals(expected, prover);
    parser.getOptions().setRestrictProverExpressions(true);
    try {
        getExpressionAsString(expression);
        fail("exception expected");
    } catch (BCompoundException e) {
        assertTrue(e.getCause() instanceof CheckException);
    }
}
Also used : CheckException(de.be4.classicalb.core.parser.exceptions.CheckException) Ast2String(util.Ast2String) BCompoundException(de.be4.classicalb.core.parser.exceptions.BCompoundException) Test(org.junit.Test)

Example 5 with AIntegerExpression

use of de.be4.classicalb.core.parser.node.AIntegerExpression in project probparsers by bendisposto.

the class RulesMachineChecker method checkErrorTypesAttribute.

private void checkErrorTypesAttribute(POperationAttribute pOperationAttribute, LinkedList<PExpression> arguments) {
    if (currentOperation instanceof RuleOperation) {
        final RuleOperation rule = (RuleOperation) currentOperation;
        if (arguments.size() == 1 && arguments.get(0) instanceof AIntegerExpression) {
            AIntegerExpression intExpr = (AIntegerExpression) arguments.get(0);
            rule.setErrrorTypes(intExpr);
        } else {
            errorList.add(new CheckException("Expected exactly one integer after ERROR_TYPES.", pOperationAttribute));
        }
    } else {
        errorList.add(new CheckException("ERROR_TYPES is not an attribute of a FUNCTION or COMPUTATION operation.", pOperationAttribute));
    }
    return;
}
Also used : ARuleOperation(de.be4.classicalb.core.parser.node.ARuleOperation) AIntegerExpression(de.be4.classicalb.core.parser.node.AIntegerExpression) CheckException(de.be4.classicalb.core.parser.exceptions.CheckException)

Aggregations

AIntegerExpression (de.be4.classicalb.core.parser.node.AIntegerExpression)7 Test (org.junit.Test)5 CheckException (de.be4.classicalb.core.parser.exceptions.CheckException)4 AAddExpression (de.be4.classicalb.core.parser.node.AAddExpression)3 AExpressionParseUnit (de.be4.classicalb.core.parser.node.AExpressionParseUnit)3 AIdentifierExpression (de.be4.classicalb.core.parser.node.AIdentifierExpression)3 PExpression (de.be4.classicalb.core.parser.node.PExpression)3 Start (de.be4.classicalb.core.parser.node.Start)3 TIntegerLiteral (de.be4.classicalb.core.parser.node.TIntegerLiteral)2 BCompoundException (de.be4.classicalb.core.parser.exceptions.BCompoundException)1 APartitionPredicate (de.be4.classicalb.core.parser.node.APartitionPredicate)1 ARuleOperation (de.be4.classicalb.core.parser.node.ARuleOperation)1 PositionedNode (de.hhu.stups.sablecc.patch.PositionedNode)1 Ast2String (util.Ast2String)1