Search in sources :

Example 6 with AIdentifierExpression

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

the class MachineContext method caseAEnumeratedSetSet.

@Override
public void caseAEnumeratedSetSet(AEnumeratedSetSet node) {
    {
        List<TIdentifierLiteral> copy = new ArrayList<TIdentifierLiteral>(node.getIdentifier());
        String name = Utils.getTIdentifierListAsString(copy);
        exist(node.getIdentifier());
        enumeratedSets.put(name, node);
    }
    List<PExpression> copy = new ArrayList<PExpression>(node.getElements());
    for (PExpression e : copy) {
        AIdentifierExpression v = (AIdentifierExpression) e;
        String name = Utils.getTIdentifierListAsString(v.getIdentifier());
        exist(v.getIdentifier());
        enumValues.put(name, v);
    }
}
Also used : AIdentifierExpression(de.be4.classicalb.core.parser.node.AIdentifierExpression) ArrayList(java.util.ArrayList) List(java.util.List) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) TIdentifierLiteral(de.be4.classicalb.core.parser.node.TIdentifierLiteral) PExpression(de.be4.classicalb.core.parser.node.PExpression)

Example 7 with AIdentifierExpression

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

the class LTLFormulaVisitor method handleQuantification.

private void handleQuantification(de.be4.ltl.core.parser.node.Node node, String parameterName, String bPredicateString, PLtl ltl) {
    // create an identifier (b ast node) for the parameter of the
    // quantification
    List<TIdentifierLiteral> list = new ArrayList<TIdentifierLiteral>();
    list.add(new TIdentifierLiteral(parameterName));
    AIdentifierExpression parameterNode = new AIdentifierExpression(list);
    // add the created identifier to the current context
    Hashtable<String, AIdentifierExpression> currentContext = new Hashtable<String, AIdentifierExpression>();
    currentContext.put(parameterName, parameterNode);
    this.contextTable.add(currentContext);
    // collection the all parameters in
    ltlIdentifierTable.put(parameterName, parameterNode);
    // parse the b predicate and create a reference to the b ast node
    de.be4.classicalb.core.parser.node.Start start = parseBPredicate(bPredicateString);
    ltlNodeToBNodeTable.put(node, start);
    // collect all identifiers which can be used in the bPredicate and
    // verify the bPredicate
    LTLBPredicate ltlBPredicate = new LTLBPredicate(getUnifiedContext(), start);
    this.bPredicates.add(ltlBPredicate);
    machineContext.checkLTLBPredicate(ltlBPredicate);
    // remaining LTL formula
    ltl.apply(this);
    // remove currentContext from contextTable
    contextTable.remove(contextTable.size() - 1);
}
Also used : AIdentifierExpression(de.be4.classicalb.core.parser.node.AIdentifierExpression) Hashtable(java.util.Hashtable) ArrayList(java.util.ArrayList) TIdentifierLiteral(de.be4.classicalb.core.parser.node.TIdentifierLiteral)

Example 8 with AIdentifierExpression

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

the class StructType method createASTNode.

public PExpression createASTNode(Typechecker typechecker) {
    ArrayList<PRecEntry> list = new ArrayList<PRecEntry>();
    Set<Entry<String, BType>> entrySet = this.types.entrySet();
    for (Entry<String, BType> entry : entrySet) {
        String name = entry.getKey();
        BType type = entry.getValue();
        TIdentifierLiteral literal = new TIdentifierLiteral(name);
        ArrayList<TIdentifierLiteral> idList = new ArrayList<TIdentifierLiteral>();
        idList.add(literal);
        AIdentifierExpression id = new AIdentifierExpression(idList);
        ARecEntry recEntry = new ARecEntry(id, type.createASTNode(typechecker));
        list.add(recEntry);
    }
    AStructExpression node = new AStructExpression(list);
    typechecker.setType(node, new SetType(this));
    return node;
}
Also used : AIdentifierExpression(de.be4.classicalb.core.parser.node.AIdentifierExpression) ARecEntry(de.be4.classicalb.core.parser.node.ARecEntry) ArrayList(java.util.ArrayList) TIdentifierLiteral(de.be4.classicalb.core.parser.node.TIdentifierLiteral) AStructExpression(de.be4.classicalb.core.parser.node.AStructExpression) ARecEntry(de.be4.classicalb.core.parser.node.ARecEntry) PRecEntry(de.be4.classicalb.core.parser.node.PRecEntry) Entry(java.util.Map.Entry) PRecEntry(de.be4.classicalb.core.parser.node.PRecEntry)

Example 9 with AIdentifierExpression

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

the class AbstractOperation method getRequiredDependencies.

public Set<AbstractOperation> getRequiredDependencies() {
    if (this.requiredDependencies == null) {
        this.requiredDependencies = new HashSet<>();
        HashSet<AIdentifierExpression> aIdentifierSet = new HashSet<>();
        aIdentifierSet.addAll(this.dependsOnComputationList);
        aIdentifierSet.addAll(this.dependsOnRuleList);
        HashSet<String> directDependencies = new HashSet<>();
        for (AIdentifierExpression aIdentifier : aIdentifierSet) {
            directDependencies.add(aIdentifier.getIdentifier().get(0).getText());
        }
        if (transitiveDependencies != null) {
            for (AbstractOperation abstractOperation : this.transitiveDependencies) {
                String opName = abstractOperation.getName();
                if (this.implicitDependenciesToComputations.contains(abstractOperation) || directDependencies.contains(opName)) {
                    requiredDependencies.add(abstractOperation);
                } else if (functionCallMap.containsKey(opName)) {
                    requiredDependencies.addAll(abstractOperation.getRequiredDependencies());
                }
            }
        }
    }
    return new HashSet<>(requiredDependencies);
}
Also used : AIdentifierExpression(de.be4.classicalb.core.parser.node.AIdentifierExpression) HashSet(java.util.HashSet)

Example 10 with AIdentifierExpression

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

the class RulesMachineChecker method caseAIdentifierExpression.

@Override
public void caseAIdentifierExpression(AIdentifierExpression node) {
    List<TIdentifierLiteral> copy = new ArrayList<>(node.getIdentifier());
    if (copy.size() > 1) {
        this.errorList.add(new CheckException("Identifier renaming is not allowed in a RULES_MACHINE.", node));
    }
    final String name = copy.get(0).getText();
    if (currentOperation != null) {
        currentOperation.addReadVariable(node);
    }
    if (!this.identifierScope.contains(name)) {
        addReadIdentifier(node);
    }
}
Also used : CheckException(de.be4.classicalb.core.parser.exceptions.CheckException) ArrayList(java.util.ArrayList) TIdentifierLiteral(de.be4.classicalb.core.parser.node.TIdentifierLiteral)

Aggregations

AIdentifierExpression (de.be4.classicalb.core.parser.node.AIdentifierExpression)43 PExpression (de.be4.classicalb.core.parser.node.PExpression)27 ArrayList (java.util.ArrayList)25 CheckException (de.be4.classicalb.core.parser.exceptions.CheckException)22 TIdentifierLiteral (de.be4.classicalb.core.parser.node.TIdentifierLiteral)14 Node (de.be4.classicalb.core.parser.node.Node)5 Test (org.junit.Test)5 BException (de.be4.classicalb.core.parser.exceptions.BException)4 VisitorException (de.be4.classicalb.core.parser.exceptions.VisitorException)4 HashSet (java.util.HashSet)4 LinkedList (java.util.LinkedList)4 AExpressionDefinitionDefinition (de.be4.classicalb.core.parser.node.AExpressionDefinitionDefinition)3 AFunctionExpression (de.be4.classicalb.core.parser.node.AFunctionExpression)3 AIntegerExpression (de.be4.classicalb.core.parser.node.AIntegerExpression)3 AStringExpression (de.be4.classicalb.core.parser.node.AStringExpression)3 BParser (de.be4.classicalb.core.parser.BParser)2 IDefinitions (de.be4.classicalb.core.parser.IDefinitions)2 Type (de.be4.classicalb.core.parser.IDefinitions.Type)2 AEqualPredicate (de.be4.classicalb.core.parser.node.AEqualPredicate)2 AExpressionParseUnit (de.be4.classicalb.core.parser.node.AExpressionParseUnit)2