Search in sources :

Example 41 with AIdentifierExpression

use of de.be4.classicalb.core.parser.node.AIdentifierExpression 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 42 with AIdentifierExpression

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

the class RulesMachineChecker method checkThatIdentifiersAreLocalVariables.

private void checkThatIdentifiersAreLocalVariables(List<PExpression> copy) {
    for (PExpression e : copy) {
        if (e instanceof AIdentifierExpression) {
            AIdentifierExpression id = (AIdentifierExpression) e;
            String name = id.getIdentifier().get(0).getText();
            if (!this.identifierScope.isAssignableVariable(name)) {
                errorList.add(new CheckException("Identifier '" + name + "' is not a local variable (VAR). Hence, it can not be assigned here.", id));
            }
        } else {
            errorList.add(new CheckException("There must be an identifier on the left side of the assign substitution. A function assignment 'f(1) := 1' is also not permitted.", e));
        }
    }
}
Also used : 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 43 with AIdentifierExpression

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

the class RulesMachineChecker method checkSucceededRuleErrorTypeOperator.

private void checkSucceededRuleErrorTypeOperator(AOperatorPredicate node, final List<PExpression> arguments) {
    if (arguments.size() != 2) {
        this.errorList.add(new CheckException("The SUCCEEDED_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 SUCCEEDED_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 SUCCEEDED_RULE_ERROR_TYPE must be an integer value.", 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 44 with AIdentifierExpression

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

the class RulesMachineChecker method checkGetRuleCounterExamplesOperator.

private void checkGetRuleCounterExamplesOperator(AOperatorExpression node, final LinkedList<PExpression> parameters) {
    // the grammar ensures at least one argument
    if (parameters.size() > 2) {
        this.errorList.add(new CheckException("Invalid number of arguments. Expected one or two arguments.", node));
    }
    PExpression pExpression = node.getIdentifiers().get(0);
    if (!(pExpression instanceof AIdentifierExpression)) {
        this.errorList.add(new CheckException("The first argument of GET_RULE_COUNTEREXAMPLES must be an identifier.", node));
        return;
    }
    this.referencedRuleOperations.add((AIdentifierExpression) pExpression);
    return;
}
Also used : 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 45 with AIdentifierExpression

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

the class MachineContext method caseAConstantsMachineClause.

@Override
public void caseAConstantsMachineClause(AConstantsMachineClause node) {
    hasConstants = true;
    List<PExpression> copy = new ArrayList<PExpression>(node.getIdentifiers());
    for (PExpression e : copy) {
        AIdentifierExpression c = (AIdentifierExpression) e;
        String name = Utils.getTIdentifierListAsString(c.getIdentifier());
        exist(c.getIdentifier());
        constants.put(name, c);
    }
}
Also used : AIdentifierExpression(de.be4.classicalb.core.parser.node.AIdentifierExpression) ArrayList(java.util.ArrayList) PExpression(de.be4.classicalb.core.parser.node.PExpression)

Aggregations

AIdentifierExpression (de.be4.classicalb.core.parser.node.AIdentifierExpression)43 PExpression (de.be4.classicalb.core.parser.node.PExpression)27 ArrayList (java.util.ArrayList)25 CheckException (de.be4.classicalb.core.parser.exceptions.CheckException)22 TIdentifierLiteral (de.be4.classicalb.core.parser.node.TIdentifierLiteral)14 Node (de.be4.classicalb.core.parser.node.Node)5 Test (org.junit.Test)5 BException (de.be4.classicalb.core.parser.exceptions.BException)4 VisitorException (de.be4.classicalb.core.parser.exceptions.VisitorException)4 HashSet (java.util.HashSet)4 LinkedList (java.util.LinkedList)4 AExpressionDefinitionDefinition (de.be4.classicalb.core.parser.node.AExpressionDefinitionDefinition)3 AFunctionExpression (de.be4.classicalb.core.parser.node.AFunctionExpression)3 AIntegerExpression (de.be4.classicalb.core.parser.node.AIntegerExpression)3 AStringExpression (de.be4.classicalb.core.parser.node.AStringExpression)3 BParser (de.be4.classicalb.core.parser.BParser)2 IDefinitions (de.be4.classicalb.core.parser.IDefinitions)2 Type (de.be4.classicalb.core.parser.IDefinitions.Type)2 AEqualPredicate (de.be4.classicalb.core.parser.node.AEqualPredicate)2 AExpressionParseUnit (de.be4.classicalb.core.parser.node.AExpressionParseUnit)2