Search in sources :

Example 6 with PPredicate

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

the class DomBuilder method createPredicateAST.

private Start createPredicateAST(final PPredicate pPredicate) {
    Start start = new Start();
    APredicateParseUnit node2 = new APredicateParseUnit();
    start.setPParseUnit(node2);
    start.setEOF(EOF);
    node2.setPredicate((PPredicate) pPredicate.clone());
    node2.getPredicate().apply(new RenameIdentifiers());
    return start;
}
Also used : Start(de.be4.classicalb.core.parser.node.Start) APredicateParseUnit(de.be4.classicalb.core.parser.node.APredicateParseUnit)

Example 7 with PPredicate

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

the class DefinitionFilesTest method testRealFiles.

/*
	 * test with real files
	 */
@Test
public void testRealFiles() throws Exception {
    final BParser parser = new BParser("testcase");
    File machine = new File("src/test/resources/parsable/DefinitionFileTest.mch");
    parser.parseFile(machine, false);
    final IDefinitions definitions = parser.getDefinitions();
    final APredicateDefinitionDefinition def1 = (APredicateDefinitionDefinition) definitions.getDefinition("GRD2");
    assertEquals("GRD2", def1.getName().getText());
    assertEquals(0, def1.getParameters().size());
    assertTrue(def1.getRhs() instanceof PPredicate);
    final APredicateDefinitionDefinition def2 = (APredicateDefinitionDefinition) definitions.getDefinition("GRD1");
    assertEquals("GRD1", def2.getName().getText());
    assertEquals(0, def2.getParameters().size());
    assertTrue(def2.getRhs() instanceof PPredicate);
}
Also used : APredicateDefinitionDefinition(de.be4.classicalb.core.parser.node.APredicateDefinitionDefinition) IDefinitions(de.be4.classicalb.core.parser.IDefinitions) BParser(de.be4.classicalb.core.parser.BParser) PPredicate(de.be4.classicalb.core.parser.node.PPredicate) File(java.io.File) Test(org.junit.Test)

Example 8 with PPredicate

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

the class ASTPrologTest method testEvent.

@Test
public void testEvent() throws BCompoundException {
    final AEventBModelParseUnit model = new AEventBModelParseUnit();
    model.setName(new TIdentifierLiteral("mm"));
    final AEventsModelClause events = new AEventsModelClause();
    model.setModelClauses(Arrays.asList((PModelClause) events));
    AEvent event = new AEvent();
    events.setEvent(Arrays.asList((PEvent) event));
    event.setEventName(new TIdentifierLiteral("testevent"));
    event.setVariables(Arrays.asList(createId("param")));
    event.setGuards(Arrays.asList((PPredicate) new ATruthPredicate()));
    PSubstitution subst1 = new AAssignSubstitution(Arrays.asList(createId("x")), Arrays.asList(createId("param")));
    event.setAssignments(Arrays.asList(subst1));
    PWitness witness = new AWitness(new TIdentifierLiteral("ab"), new AEqualPredicate(createId("ab"), createId("y")));
    event.setWitness(Arrays.asList(witness));
    event.setRefines(Arrays.asList(new TIdentifierLiteral("abstract1"), new TIdentifierLiteral("abstract2")));
    checkAST(0, "event_b_model($,mm,[events($,[" + "event($,testevent,[abstract1,abstract2],[identifier($,param)],[truth($)],[]," + "[assign($,[identifier($,x)],[identifier($,param)])]," + "[witness($,identifier(%,ab),equal($,identifier($,ab),identifier($,y)))])])])", model);
}
Also used : AEqualPredicate(de.be4.classicalb.core.parser.node.AEqualPredicate) PModelClause(de.be4.classicalb.core.parser.node.PModelClause) PPredicate(de.be4.classicalb.core.parser.node.PPredicate) TIdentifierLiteral(de.be4.classicalb.core.parser.node.TIdentifierLiteral) PEvent(de.be4.classicalb.core.parser.node.PEvent) AEventBModelParseUnit(de.be4.classicalb.core.parser.node.AEventBModelParseUnit) AWitness(de.be4.classicalb.core.parser.node.AWitness) PSubstitution(de.be4.classicalb.core.parser.node.PSubstitution) PWitness(de.be4.classicalb.core.parser.node.PWitness) AEvent(de.be4.classicalb.core.parser.node.AEvent) ATruthPredicate(de.be4.classicalb.core.parser.node.ATruthPredicate) AEventsModelClause(de.be4.classicalb.core.parser.node.AEventsModelClause) AAssignSubstitution(de.be4.classicalb.core.parser.node.AAssignSubstitution) Test(org.junit.Test)

Example 9 with PPredicate

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

the class DomBuilder method inAOperation.

@Override
public void inAOperation(final AOperation node) {
    String name = extractIdentifierName(node.getOpName());
    if (prefix != null && !prefix.equals(name)) {
        name = prefix + "." + name;
    }
    List<PExpression> paramIds = node.getParameters();
    final List<String> params = extractIdentifiers(paramIds);
    final List<String> output = extractIdentifiers(node.getReturnValues());
    Operation operation = new Operation(name, params, output);
    PSubstitution body = node.getOperationBody();
    List<ClassicalBGuard> guards = new ArrayList<>();
    if (body instanceof ASelectSubstitution) {
        PPredicate condition = ((ASelectSubstitution) body).getCondition();
        List<PPredicate> predicates = getPredicates(condition);
        for (PPredicate pPredicate : predicates) {
            guards.add(new ClassicalBGuard(createPredicateAST(pPredicate)));
        }
    }
    if (body instanceof APreconditionSubstitution) {
        PPredicate condition = ((APreconditionSubstitution) body).getPredicate();
        List<PPredicate> predicates = getPredicates(condition);
        for (PPredicate pPredicate : predicates) {
            guards.add(new ClassicalBGuard(createPredicateAST(pPredicate)));
        }
    }
    List<ClassicalBAction> actions = new ArrayList<>();
    actions.add(new ClassicalBAction(createSubstitutionAST(body)));
    operation = operation.set(Action.class, new ModelElementList<>(actions));
    operation = operation.set(Guard.class, new ModelElementList<>(guards));
    operations.add(operation);
}
Also used : ASelectSubstitution(de.be4.classicalb.core.parser.node.ASelectSubstitution) Action(de.prob.model.representation.Action) ArrayList(java.util.ArrayList) ModelElementList(de.prob.model.representation.ModelElementList) AOperation(de.be4.classicalb.core.parser.node.AOperation) PPredicate(de.be4.classicalb.core.parser.node.PPredicate) PExpression(de.be4.classicalb.core.parser.node.PExpression) APreconditionSubstitution(de.be4.classicalb.core.parser.node.APreconditionSubstitution) PSubstitution(de.be4.classicalb.core.parser.node.PSubstitution) Guard(de.prob.model.representation.Guard)

Example 10 with PPredicate

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

the class EventBMachineTranslator method processEvents.

private AEventsModelClause processEvents() {
    List<PEvent> events = new ArrayList<>();
    for (Event e : machine.getEvents()) {
        AEvent event = new AEvent();
        event.setEventName(new TIdentifierLiteral(e.getName()));
        event.setStatus(extractEventStatus(e));
        nodeInfos.put(event, new Tuple2<>(machine.getName(), e.getName()));
        List<TIdentifierLiteral> refined = new ArrayList<>();
        for (Event ref : e.getRefines()) {
            refined.add(new TIdentifierLiteral(ref.getName()));
        }
        event.setRefines(refined);
        List<PExpression> params = new ArrayList<>();
        for (EventParameter eventParameter : e.getParameters()) {
            PExpression pExpression = (PExpression) eventParameter.getExpression().getAst();
            nodeInfos.put(pExpression, new Tuple2<>(machine.getName(), eventParameter.getName()));
            params.add(pExpression);
        }
        event.setVariables(params);
        List<PPredicate> guards = new ArrayList<>();
        List<PPredicate> thms = new ArrayList<>();
        for (EventBGuard eventBGuard : e.getGuards()) {
            PPredicate ppred = (PPredicate) ((EventB) eventBGuard.getPredicate()).getAst();
            nodeInfos.put(ppred, new Tuple2<>(machine.getName(), eventBGuard.getName()));
            if (eventBGuard.isTheorem()) {
                thms.add(ppred);
            } else {
                guards.add(ppred);
            }
        }
        event.setGuards(guards);
        event.setTheorems(thms);
        List<PWitness> witnesses = new ArrayList<>();
        for (Witness witness : e.getWitnesses()) {
            PPredicate ppred = (PPredicate) witness.getPredicate().getAst();
            nodeInfos.put(ppred, new Tuple2<>(machine.getName(), witness.getName()));
            witnesses.add(new AWitness(new TIdentifierLiteral(witness.getName()), ppred));
        }
        event.setWitness(witnesses);
        List<PSubstitution> actions = new ArrayList<>();
        for (EventBAction eventBAction : e.getActions()) {
            PSubstitution psub = (PSubstitution) ((EventB) eventBAction.getCode()).getAst();
            nodeInfos.put(psub, new Tuple2<>(machine.getName(), eventBAction.getName()));
            actions.add(psub);
        }
        event.setAssignments(actions);
        events.add(event);
    }
    return new AEventsModelClause(events);
}
Also used : ArrayList(java.util.ArrayList) PPredicate(de.be4.classicalb.core.parser.node.PPredicate) EventBGuard(de.prob.model.eventb.EventBGuard) PEvent(de.be4.classicalb.core.parser.node.PEvent) TIdentifierLiteral(de.be4.classicalb.core.parser.node.TIdentifierLiteral) PExpression(de.be4.classicalb.core.parser.node.PExpression) EventParameter(de.prob.model.eventb.EventParameter) AWitness(de.be4.classicalb.core.parser.node.AWitness) PWitness(de.be4.classicalb.core.parser.node.PWitness) PSubstitution(de.be4.classicalb.core.parser.node.PSubstitution) AEvent(de.be4.classicalb.core.parser.node.AEvent) AWitness(de.be4.classicalb.core.parser.node.AWitness) Witness(de.prob.model.eventb.Witness) PWitness(de.be4.classicalb.core.parser.node.PWitness) Event(de.prob.model.eventb.Event) AEvent(de.be4.classicalb.core.parser.node.AEvent) PEvent(de.be4.classicalb.core.parser.node.PEvent) EventBAction(de.prob.model.eventb.EventBAction) AEventsModelClause(de.be4.classicalb.core.parser.node.AEventsModelClause)

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