Search in sources :

Example 1 with ComputationOperation

use of de.be4.classicalb.core.parser.rules.ComputationOperation in project probparsers by bendisposto.

the class AbstractOperation method getImplicitDependenciesToComputations.

public List<TIdentifierLiteral> getImplicitDependenciesToComputations() {
    List<TIdentifierLiteral> result = new ArrayList<>();
    for (ComputationOperation comp : implicitDependenciesToComputations) {
        TIdentifierLiteral nameLiteral = comp.getNameLiteral();
        result.add(nameLiteral);
    }
    return result;
}
Also used : ArrayList(java.util.ArrayList) TIdentifierLiteral(de.be4.classicalb.core.parser.node.TIdentifierLiteral)

Example 2 with ComputationOperation

use of de.be4.classicalb.core.parser.rules.ComputationOperation in project probparsers by bendisposto.

the class RulesMachineChecker method outADefineSubstitution.

@Override
public void outADefineSubstitution(ADefineSubstitution node) {
    // section
    if (currentOperation != null && currentOperation instanceof ComputationOperation) {
        ComputationOperation computationOperation = (ComputationOperation) currentOperation;
        try {
            computationOperation.addDefineVariable(node.getName());
            this.knownIdentifier.addKnownIdentifier(node.getName());
        } catch (CheckException e) {
            this.errorList.add(e);
        }
    }
}
Also used : CheckException(de.be4.classicalb.core.parser.exceptions.CheckException) AComputationOperation(de.be4.classicalb.core.parser.node.AComputationOperation)

Example 3 with ComputationOperation

use of de.be4.classicalb.core.parser.rules.ComputationOperation 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 4 with ComputationOperation

use of de.be4.classicalb.core.parser.rules.ComputationOperation in project probparsers by bendisposto.

the class RulesProject method checkDependsOnComputations.

private void checkDependsOnComputations(AbstractOperation operation) {
    boolean errorOccured = false;
    for (AIdentifierExpression aIdentifierExpression : operation.getDependsOnComputationList()) {
        final String name = aIdentifierExpression.getIdentifier().get(0).getText();
        if (allOperations.containsKey(name)) {
            AbstractOperation abstractOperation = allOperations.get(name);
            if (!(abstractOperation instanceof ComputationOperation)) {
                this.bExceptionList.add(new BException(operation.getFileName(), new CheckException("Identifier '" + name + "' is not a COMPUTATION.", aIdentifierExpression)));
                errorOccured = true;
            }
        } else {
            errorOccured = true;
            this.bExceptionList.add(new BException(operation.getFileName(), new CheckException("Unknown operation: '" + name + "'.", aIdentifierExpression)));
        }
    }
    if (!errorOccured) {
        checkVisibilityOfAIdentifierList(operation, operation.getDependsOnComputationList());
    }
}
Also used : CheckException(de.be4.classicalb.core.parser.exceptions.CheckException) AIdentifierExpression(de.be4.classicalb.core.parser.node.AIdentifierExpression) BException(de.be4.classicalb.core.parser.exceptions.BException)

Example 5 with ComputationOperation

use of de.be4.classicalb.core.parser.rules.ComputationOperation in project prob2 by bendisposto.

the class RulesChecker method evalOperations.

public Map<AbstractOperation, OperationStatus> evalOperations(State state, Collection<AbstractOperation> operations) {
    ArrayList<IEvalElement> formulas = new ArrayList<>();
    for (AbstractOperation abstractOperation : operations) {
        if (abstractOperation instanceof ComputationOperation || abstractOperation instanceof RuleOperation) {
            formulas.add(rulesModel.getEvalElement(abstractOperation));
        }
    }
    state.getStateSpace().subscribe(this, formulas);
    Map<IEvalElement, AbstractEvalResult> values = state.getValues();
    final Map<AbstractOperation, OperationStatus> states = new HashMap<>();
    for (AbstractOperation op : operations) {
        if (op instanceof RuleOperation) {
            states.put(op, RuleStatus.valueOf(values.get(rulesModel.getEvalElement(op))));
        } else if (op instanceof ComputationOperation) {
            states.put(op, ComputationStatus.valueOf(values.get(rulesModel.getEvalElement(op))));
        }
    }
    return states;
}
Also used : RuleOperation(de.be4.classicalb.core.parser.rules.RuleOperation) AbstractOperation(de.be4.classicalb.core.parser.rules.AbstractOperation) HashMap(java.util.HashMap) AbstractEvalResult(de.prob.animator.domainobjects.AbstractEvalResult) IEvalElement(de.prob.animator.domainobjects.IEvalElement) ArrayList(java.util.ArrayList) ComputationOperation(de.be4.classicalb.core.parser.rules.ComputationOperation)

Aggregations

CheckException (de.be4.classicalb.core.parser.exceptions.CheckException)3 ArrayList (java.util.ArrayList)3 BException (de.be4.classicalb.core.parser.exceptions.BException)2 AComputationOperation (de.be4.classicalb.core.parser.node.AComputationOperation)2 AIdentifierExpression (de.be4.classicalb.core.parser.node.AIdentifierExpression)2 HashMap (java.util.HashMap)2 TIdentifierLiteral (de.be4.classicalb.core.parser.node.TIdentifierLiteral)1 AbstractOperation (de.be4.classicalb.core.parser.rules.AbstractOperation)1 ComputationOperation (de.be4.classicalb.core.parser.rules.ComputationOperation)1 RuleOperation (de.be4.classicalb.core.parser.rules.RuleOperation)1 AbstractEvalResult (de.prob.animator.domainobjects.AbstractEvalResult)1 IEvalElement (de.prob.animator.domainobjects.IEvalElement)1 HashSet (java.util.HashSet)1 LinkedHashMap (java.util.LinkedHashMap)1