Search in sources :

Example 41 with Node

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

the class RulesMachineChecker method caseAComputationOperation.

@Override
public void caseAComputationOperation(AComputationOperation node) {
    currentOperation = new ComputationOperation(node.getName(), this.fileName, this.machineName, machineReferences);
    computationMap.put(node, (ComputationOperation) currentOperation);
    visitOperationAttributes(node.getAttributes());
    node.getBody().apply(this);
    currentOperation = null;
}
Also used : AComputationOperation(de.be4.classicalb.core.parser.node.AComputationOperation)

Example 42 with Node

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

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

the class RulesMachineChecker method caseAVarSubstitution.

@Override
public void caseAVarSubstitution(AVarSubstitution node) {
    final HashSet<String> variables = new HashSet<>();
    LinkedList<PExpression> identifiers = node.getIdentifiers();
    for (PExpression e : identifiers) {
        if (e instanceof AIdentifierExpression) {
            AIdentifierExpression id = (AIdentifierExpression) e;
            String name = id.getIdentifier().get(0).getText();
            variables.add(name);
        } else {
            errorList.add(new CheckException("There must be a list of identifiers in VAR substitution.", node));
        }
    }
    this.identifierScope.createNewScope(new LinkedList<PExpression>(node.getIdentifiers()), true);
    node.getSubstitution().apply(this);
    this.identifierScope.removeScope();
}
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) HashSet(java.util.HashSet)

Example 44 with Node

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

the class RulesMachineChecker method checkStringFormatOperator.

private void checkStringFormatOperator(AOperatorExpression node, final LinkedList<PExpression> parameters) {
    PExpression firstParam = parameters.get(0);
    Integer count = countPlaceHoldersInExpression(firstParam);
    if (count != null && count != parameters.size() - 1) {
        this.errorList.add(new CheckException("The number of arguments (" + (parameters.size() - 1) + ") does not match the number of placeholders (" + count + ") in the string.", node));
    }
    LinkedList<PExpression> identifiers = node.getIdentifiers();
    for (PExpression pExpression : identifiers) {
        pExpression.apply(this);
    }
    return;
}
Also used : CheckException(de.be4.classicalb.core.parser.exceptions.CheckException) PExpression(de.be4.classicalb.core.parser.node.PExpression)

Example 45 with Node

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

the class RulesMachineChecker method caseAForallSubMessageSubstitution.

@Override
public void caseAForallSubMessageSubstitution(AForallSubMessageSubstitution node) {
    if (!isInRule()) {
        errorList.add(new CheckException("RULE_FORALL used outside of a RULE operation", node));
        return;
    }
    this.identifierScope.createNewScope(new LinkedList<PExpression>(node.getIdentifiers()));
    node.getWhere().apply(this);
    node.getExpect().apply(this);
    node.getMessage().apply(this);
    this.identifierScope.removeScope();
    checkErrorType(node.getErrorType());
}
Also used : CheckException(de.be4.classicalb.core.parser.exceptions.CheckException) PExpression(de.be4.classicalb.core.parser.node.PExpression)

Aggregations

CheckException (de.be4.classicalb.core.parser.exceptions.CheckException)42 PExpression (de.be4.classicalb.core.parser.node.PExpression)30 ArrayList (java.util.ArrayList)30 Node (de.be4.classicalb.core.parser.node.Node)20 AIdentifierExpression (de.be4.classicalb.core.parser.node.AIdentifierExpression)16 TIdentifierLiteral (de.be4.classicalb.core.parser.node.TIdentifierLiteral)12 TPragmaIdOrString (de.be4.classicalb.core.parser.node.TPragmaIdOrString)11 VisitorException (de.be4.classicalb.core.parser.exceptions.VisitorException)8 HashSet (java.util.HashSet)8 Token (de.be4.ltl.core.parser.node.Token)7 Type (de.be4.classicalb.core.parser.IDefinitions.Type)6 IOException (java.io.IOException)6 ASTProlog (de.be4.classicalb.core.parser.analysis.prolog.ASTProlog)5 PositionedNode (de.hhu.stups.sablecc.patch.PositionedNode)5 LinkedList (java.util.LinkedList)5 BCompoundException (de.be4.classicalb.core.parser.exceptions.BCompoundException)4 LinkedHashMap (java.util.LinkedHashMap)4 Test (org.junit.Test)4 ClassicalPositionPrinter (de.be4.classicalb.core.parser.analysis.prolog.ClassicalPositionPrinter)3 NodeIdAssignment (de.be4.classicalb.core.parser.analysis.prolog.NodeIdAssignment)3