Search in sources :

Example 51 with PExpression

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

the class RulesMachineChecker method inAAssignSubstitution.

@Override
public void inAAssignSubstitution(AAssignSubstitution node) {
    ArrayList<PExpression> righthand = new ArrayList<>(node.getRhsExpressions());
    for (PExpression pExpression : righthand) {
        pExpression.apply(this);
    }
    List<PExpression> copy = new ArrayList<>(node.getLhsExpression());
    checkThatIdentifiersAreLocalVariables(copy);
}
Also used : ArrayList(java.util.ArrayList) PExpression(de.be4.classicalb.core.parser.node.PExpression)

Example 52 with PExpression

use of de.be4.classicalb.core.parser.node.PExpression 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)

Example 53 with PExpression

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

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

use of de.be4.classicalb.core.parser.node.PExpression 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)

Aggregations

PExpression (de.be4.classicalb.core.parser.node.PExpression)50 AIdentifierExpression (de.be4.classicalb.core.parser.node.AIdentifierExpression)28 ArrayList (java.util.ArrayList)27 CheckException (de.be4.classicalb.core.parser.exceptions.CheckException)21 TIdentifierLiteral (de.be4.classicalb.core.parser.node.TIdentifierLiteral)12 Test (org.junit.Test)6 Node (de.be4.classicalb.core.parser.node.Node)5 LinkedList (java.util.LinkedList)5 AExpressionParseUnit (de.be4.classicalb.core.parser.node.AExpressionParseUnit)4 AFunctionExpression (de.be4.classicalb.core.parser.node.AFunctionExpression)4 AIntegerExpression (de.be4.classicalb.core.parser.node.AIntegerExpression)4 PSubstitution (de.be4.classicalb.core.parser.node.PSubstitution)4 VisitorException (de.be4.classicalb.core.parser.exceptions.VisitorException)3 ADefinitionExpression (de.be4.classicalb.core.parser.node.ADefinitionExpression)3 AStringExpression (de.be4.classicalb.core.parser.node.AStringExpression)3 Start (de.be4.classicalb.core.parser.node.Start)3 BParser (de.be4.classicalb.core.parser.BParser)2 AExpressionDefinitionDefinition (de.be4.classicalb.core.parser.node.AExpressionDefinitionDefinition)2 AMachineReference (de.be4.classicalb.core.parser.node.AMachineReference)2 AOpSubstitution (de.be4.classicalb.core.parser.node.AOpSubstitution)2