Search in sources :

Example 1 with PPredicate

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

the class MachineContext method caseAAssertionsMachineClause.

@Override
public void caseAAssertionsMachineClause(AAssertionsMachineClause node) {
    this.assertiondMachineClause = node;
    this.contextTable = new ArrayList<LinkedHashMap<String, Node>>();
    ArrayList<MachineContext> list = lookupReferencedMachines();
    for (int i = 0; i < list.size(); i++) {
        MachineContext s = list.get(i);
        this.contextTable.add(s.getSetParamter());
        this.contextTable.add(s.getScalarParameter());
        this.contextTable.add(s.getDeferredSets());
        this.contextTable.add(s.getEnumeratedSets());
        this.contextTable.add(s.getEnumValues());
        this.contextTable.add(s.getConstants());
        this.contextTable.add(s.getDefinitions());
        this.contextTable.add(s.getVariables());
    }
    List<PPredicate> copy = new ArrayList<PPredicate>(node.getPredicates());
    for (PPredicate e : copy) {
        e.apply(this);
    }
}
Also used : ArrayList(java.util.ArrayList) PPredicate(de.be4.classicalb.core.parser.node.PPredicate) LinkedHashMap(java.util.LinkedHashMap)

Example 2 with PPredicate

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

the class RulesMachineChecker method checkOperationPredicateAttribute.

private void checkOperationPredicateAttribute(OccurredAttributes occurredAttributes, POperationAttribute pOperationAttribute) throws AssertionError {
    APredicateAttributeOperationAttribute attr = (APredicateAttributeOperationAttribute) pOperationAttribute;
    PPredicate predicate = attr.getPredicate();
    final String attrName = attr.getName().getText();
    occurredAttributes.add(attrName, pOperationAttribute);
    switch(attrName) {
        case RulesGrammar.ACTIVATION:
            if (currentOperation instanceof FunctionOperation) {
                errorList.add(new CheckException("ACTIVATION is not a valid attribute of a FUNCTION operation.", pOperationAttribute));
            } else {
                currentOperation.setActivationPredicate(predicate);
            }
            break;
        case RulesGrammar.PRECONDITION:
            if (currentOperation instanceof FunctionOperation) {
                FunctionOperation func = (FunctionOperation) currentOperation;
                func.setPreconditionPredicate(predicate);
            } else {
                errorList.add(new CheckException("PRECONDITION clause is not allowed for a RULE or COMPUTATION operation", pOperationAttribute));
            }
            break;
        case RulesGrammar.POSTCONDITION:
            if (currentOperation instanceof RuleOperation) {
                errorList.add(new CheckException("POSTCONDITION attribute is not allowed for a RULE operation", pOperationAttribute));
            } else {
                currentOperation.setPostcondition(predicate);
            }
            break;
        default:
            throw new AssertionError("Unexpected operation attribute: " + attrName);
    }
    predicate.apply(this);
}
Also used : APredicateAttributeOperationAttribute(de.be4.classicalb.core.parser.node.APredicateAttributeOperationAttribute) ARuleOperation(de.be4.classicalb.core.parser.node.ARuleOperation) AFunctionOperation(de.be4.classicalb.core.parser.node.AFunctionOperation) CheckException(de.be4.classicalb.core.parser.exceptions.CheckException) PPredicate(de.be4.classicalb.core.parser.node.PPredicate)

Example 3 with PPredicate

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

the class BMachine method addPropertiesPredicates.

public void addPropertiesPredicates(Map<String, String> constantStringValues) {
    if (constantStringValues.size() == 0) {
        return;
    }
    APropertiesMachineClause clause = new APropertiesMachineClause();
    this.parseUnit.getMachineClauses().add(clause);
    List<PPredicate> predList = new ArrayList<>();
    for (Entry<String, String> entry : constantStringValues.entrySet()) {
        AIdentifierExpression identifier = createIdentifier(entry.getKey());
        AStringExpression value = new AStringExpression(new TStringLiteral(entry.getValue()));
        AEqualPredicate equal = new AEqualPredicate(identifier, value);
        predList.add(equal);
    }
    clause.setPredicates(createConjunction(predList));
}
Also used : AEqualPredicate(de.be4.classicalb.core.parser.node.AEqualPredicate) AIdentifierExpression(de.be4.classicalb.core.parser.node.AIdentifierExpression) ArrayList(java.util.ArrayList) AStringExpression(de.be4.classicalb.core.parser.node.AStringExpression) TStringLiteral(de.be4.classicalb.core.parser.node.TStringLiteral) PPredicate(de.be4.classicalb.core.parser.node.PPredicate) APropertiesMachineClause(de.be4.classicalb.core.parser.node.APropertiesMachineClause)

Example 4 with PPredicate

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

the class SyntaxExtensionTranslator method outAIfPredicatePredicate.

@Override
public void outAIfPredicatePredicate(AIfPredicatePredicate node) {
    // IF P THE P2 ELSE P3 END
    // will be translated into
    // (p => p2) & (not(p) => p3)
    AImplicationPredicate imp1 = new AImplicationPredicate((PPredicate) cloneNode(node.getCondition()), (PPredicate) cloneNode(node.getThen()));
    AImplicationPredicate imp2 = new AImplicationPredicate(new ANegationPredicate((PPredicate) cloneNode(node.getCondition())), (PPredicate) cloneNode(node.getElse()));
    AConjunctPredicate con = new AConjunctPredicate(imp1, imp2);
    con.setStartPos(node.getStartPos());
    con.setEndPos(node.getEndPos());
    node.replaceBy(con);
}
Also used : AConjunctPredicate(de.be4.classicalb.core.parser.node.AConjunctPredicate) AImplicationPredicate(de.be4.classicalb.core.parser.node.AImplicationPredicate) ANegationPredicate(de.be4.classicalb.core.parser.node.ANegationPredicate) PPredicate(de.be4.classicalb.core.parser.node.PPredicate)

Example 5 with PPredicate

use of de.be4.classicalb.core.parser.node.PPredicate in project prob2 by bendisposto.

the class ContextTranslator method processAxiomsAndTheorems.

private List<PContextClause> processAxiomsAndTheorems() {
    List<PContextClause> axiomsAndThms = new ArrayList<>();
    List<PPredicate> axioms = new ArrayList<>();
    List<PPredicate> thms = new ArrayList<>();
    for (EventBAxiom axiom : context.getAxioms()) {
        PPredicate ppred = (PPredicate) ((EventB) axiom.getPredicate()).getAst();
        nodeInfos.put(ppred, new Tuple2<>(context.getName(), axiom.getName()));
        if (axiom.isTheorem()) {
            thms.add(ppred);
        } else {
            axioms.add(ppred);
        }
    }
    axiomsAndThms.add(new AAxiomsContextClause(axioms));
    axiomsAndThms.add(new ATheoremsContextClause(thms));
    return axiomsAndThms;
}
Also used : EventBAxiom(de.prob.model.eventb.EventBAxiom) ArrayList(java.util.ArrayList) ATheoremsContextClause(de.be4.classicalb.core.parser.node.ATheoremsContextClause) PPredicate(de.be4.classicalb.core.parser.node.PPredicate) AAxiomsContextClause(de.be4.classicalb.core.parser.node.AAxiomsContextClause) PContextClause(de.be4.classicalb.core.parser.node.PContextClause)

Aggregations

PPredicate (de.be4.classicalb.core.parser.node.PPredicate)10 ArrayList (java.util.ArrayList)6 PSubstitution (de.be4.classicalb.core.parser.node.PSubstitution)3 AEqualPredicate (de.be4.classicalb.core.parser.node.AEqualPredicate)2 AEvent (de.be4.classicalb.core.parser.node.AEvent)2 AEventsModelClause (de.be4.classicalb.core.parser.node.AEventsModelClause)2 AWitness (de.be4.classicalb.core.parser.node.AWitness)2 PEvent (de.be4.classicalb.core.parser.node.PEvent)2 PExpression (de.be4.classicalb.core.parser.node.PExpression)2 PModelClause (de.be4.classicalb.core.parser.node.PModelClause)2 PWitness (de.be4.classicalb.core.parser.node.PWitness)2 TIdentifierLiteral (de.be4.classicalb.core.parser.node.TIdentifierLiteral)2 Test (org.junit.Test)2 BParser (de.be4.classicalb.core.parser.BParser)1 IDefinitions (de.be4.classicalb.core.parser.IDefinitions)1 CheckException (de.be4.classicalb.core.parser.exceptions.CheckException)1 AAssignSubstitution (de.be4.classicalb.core.parser.node.AAssignSubstitution)1 AAxiomsContextClause (de.be4.classicalb.core.parser.node.AAxiomsContextClause)1 AConjunctPredicate (de.be4.classicalb.core.parser.node.AConjunctPredicate)1 AEventBModelParseUnit (de.be4.classicalb.core.parser.node.AEventBModelParseUnit)1