Search in sources :

Example 1 with ASubstitutionDefinitionDefinition

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

the class MachineContext method caseADefinitionsMachineClause.

/**
 * Definitions
 */
@Override
public void caseADefinitionsMachineClause(ADefinitionsMachineClause node) {
    definitionMachineClause = node;
    DefinitionsSorter.sortDefinitions(node);
    List<PDefinition> copy = node.getDefinitions();
    /*
		 * The definitions are not in a predefined order. In particular
		 * definitions can depend on each other. First all definitions are added
		 * to the definitions context table. Then all definitions are visited.
		 */
    Collection<PDefinition> definitionsToRemove = new HashSet<PDefinition>();
    for (PDefinition e : copy) {
        if (e instanceof AExpressionDefinitionDefinition) {
            AExpressionDefinitionDefinition def = (AExpressionDefinitionDefinition) e;
            String name = def.getName().getText();
            if (name.startsWith("ASSERT_LTL")) {
                LTLFormulaVisitor visitor = new LTLFormulaVisitor(name, this);
                visitor.parseDefinition(def);
                this.ltlVisitors.add(visitor);
                definitionsToRemove.add(def);
            } else if (name.startsWith("ANIMATION_")) {
                definitionsToRemove.add(def);
            }
            evalDefinitionName(((AExpressionDefinitionDefinition) e).getName().getText().toString(), e);
        } else if (e instanceof APredicateDefinitionDefinition) {
            evalDefinitionName(((APredicateDefinitionDefinition) e).getName().getText().toString(), e);
        } else if (e instanceof ASubstitutionDefinitionDefinition) {
            evalDefinitionName(((ASubstitutionDefinitionDefinition) e).getName().getText().toString(), e);
        }
    }
    /*
		 * At this point all LTL definitions (ASSERT_LTL) are removed. LTL
		 * formulas are stored in the Arraylist {@value #ltlVisitors}.
		 */
    copy.removeAll(definitionsToRemove);
    this.contextTable = new ArrayList<LinkedHashMap<String, Node>>();
    ArrayList<MachineContext> list = lookupReferencedMachines();
    for (int i = 0; i < list.size(); i++) {
        MachineContext s = list.get(i);
        contextTable.add(s.getDeferredSets());
        contextTable.add(s.getEnumeratedSets());
        contextTable.add(s.getEnumValues());
        contextTable.add(s.getConstants());
        contextTable.add(s.getVariables());
        contextTable.add(s.getDefinitions());
    }
    for (PDefinition e : copy) {
        e.apply(this);
    }
}
Also used : APredicateDefinitionDefinition(de.be4.classicalb.core.parser.node.APredicateDefinitionDefinition) ASubstitutionDefinitionDefinition(de.be4.classicalb.core.parser.node.ASubstitutionDefinitionDefinition) LinkedHashMap(java.util.LinkedHashMap) PDefinition(de.be4.classicalb.core.parser.node.PDefinition) AExpressionDefinitionDefinition(de.be4.classicalb.core.parser.node.AExpressionDefinitionDefinition) HashSet(java.util.HashSet)

Example 2 with ASubstitutionDefinitionDefinition

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

the class DefinitionCollector method inASubstitutionDefinitionDefinition.

@Override
public void inASubstitutionDefinitionDefinition(final ASubstitutionDefinitionDefinition node) {
    final String defName = node.getName().getText();
    final Type type = defTypes.getType(defName);
    addDefinition(node, type, defName);
}
Also used : Type(de.be4.classicalb.core.parser.IDefinitions.Type)

Example 3 with ASubstitutionDefinitionDefinition

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

the class ASTBuilder method addPrintSubDefinitionToIdefinitions.

public static void addPrintSubDefinitionToIdefinitions(IDefinitions definitions) {
    if (definitions.containsDefinition(PRINT)) {
        return;
    }
    /*-
		 * PRINT(x) == skip; 
		 * EXTERNAL_SUBSTITUTION_PRINT(T) == T; /* declare as external for any type T
		 */
    ASubstitutionDefinitionDefinition printDef = new ASubstitutionDefinitionDefinition();
    printDef.setName(new TDefLiteralSubstitution(PRINT));
    printDef.setParameters(createIdentifierList("value"));
    printDef.setRhs(new ASkipSubstitution());
    definitions.addDefinition(printDef, IDefinitions.Type.Substitution);
    AExpressionDefinitionDefinition forceDefType = new AExpressionDefinitionDefinition();
    forceDefType.setName(new TIdentifierLiteral("EXTERNAL_SUBSTITUTION_" + PRINT));
    forceDefType.setParameters(createIdentifierList("T"));
    forceDefType.setRhs(createIdentifier("T"));
    definitions.addDefinition(forceDefType, IDefinitions.Type.Expression);
}
Also used : TDefLiteralSubstitution(de.be4.classicalb.core.parser.node.TDefLiteralSubstitution) ASubstitutionDefinitionDefinition(de.be4.classicalb.core.parser.node.ASubstitutionDefinitionDefinition) ASkipSubstitution(de.be4.classicalb.core.parser.node.ASkipSubstitution) AExpressionDefinitionDefinition(de.be4.classicalb.core.parser.node.AExpressionDefinitionDefinition) TIdentifierLiteral(de.be4.classicalb.core.parser.node.TIdentifierLiteral)

Example 4 with ASubstitutionDefinitionDefinition

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

the class OpSubstitutions method setTypeSubstDef.

private void setTypeSubstDef(final AFuncOpSubstitution node, final String idString) {
    final AExpressionDefinitionDefinition oldDefinition = (AExpressionDefinitionDefinition) definitions.getDefinition(idString);
    final Node defRhs = oldDefinition.getRhs();
    final PSubstitution rhsSubst;
    if (defRhs instanceof AFunctionExpression) {
        final AFunctionExpression rhsFunction = (AFunctionExpression) defRhs;
        rhsSubst = new AOpSubstitution(rhsFunction.getIdentifier(), new LinkedList<PExpression>(rhsFunction.getParameters()));
        rhsSubst.setStartPos(rhsFunction.getStartPos());
        rhsSubst.setEndPos(rhsFunction.getEndPos());
    } else if (defRhs instanceof AIdentifierExpression) {
        final AIdentifierExpression rhsIdent = (AIdentifierExpression) defRhs;
        rhsSubst = new AOpSubstitution(rhsIdent, new LinkedList<PExpression>());
        rhsSubst.setStartPos(rhsIdent.getStartPos());
        rhsSubst.setEndPos(rhsIdent.getEndPos());
    } else {
        // some other expression was parsed (NOT allowed)
        throw new VisitorException(new CheckException("Expecting operation", node));
    }
    final TIdentifierLiteral oldDefId = oldDefinition.getName();
    final TDefLiteralSubstitution defId = new TDefLiteralSubstitution(oldDefId.getText(), oldDefId.getLine(), oldDefId.getPos());
    final ASubstitutionDefinitionDefinition substDef = new ASubstitutionDefinitionDefinition(defId, new LinkedList<PExpression>(oldDefinition.getParameters()), rhsSubst);
    substDef.setStartPos(oldDefinition.getStartPos());
    substDef.setEndPos(oldDefinition.getEndPos());
    definitions.replaceDefinition(idString, Type.Substitution, substDef);
    oldDefinition.replaceBy(substDef);
}
Also used : CheckException(de.be4.classicalb.core.parser.exceptions.CheckException) TDefLiteralSubstitution(de.be4.classicalb.core.parser.node.TDefLiteralSubstitution) AIdentifierExpression(de.be4.classicalb.core.parser.node.AIdentifierExpression) Node(de.be4.classicalb.core.parser.node.Node) PositionedNode(de.hhu.stups.sablecc.patch.PositionedNode) ASubstitutionDefinitionDefinition(de.be4.classicalb.core.parser.node.ASubstitutionDefinitionDefinition) PExpression(de.be4.classicalb.core.parser.node.PExpression) TIdentifierLiteral(de.be4.classicalb.core.parser.node.TIdentifierLiteral) LinkedList(java.util.LinkedList) PSubstitution(de.be4.classicalb.core.parser.node.PSubstitution) AFunctionExpression(de.be4.classicalb.core.parser.node.AFunctionExpression) AExpressionDefinitionDefinition(de.be4.classicalb.core.parser.node.AExpressionDefinitionDefinition) AOpSubstitution(de.be4.classicalb.core.parser.node.AOpSubstitution) VisitorException(de.be4.classicalb.core.parser.exceptions.VisitorException)

Example 5 with ASubstitutionDefinitionDefinition

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

the class RulesMachineChecker method caseASubstitutionDefinitionDefinition.

@Override
public void caseASubstitutionDefinitionDefinition(ASubstitutionDefinitionDefinition node) {
    final String name = node.getName().getText();
    this.definitions.add(name);
    if ("GOAL".equals(name)) {
        errorList.add(new CheckException("The GOAL definition must be a predicate.", node));
        return;
    }
    this.identifierScope.createNewScope(new LinkedList<>(node.getParameters()));
    node.getRhs().apply(this);
    this.identifierScope.removeScope();
}
Also used : CheckException(de.be4.classicalb.core.parser.exceptions.CheckException)

Aggregations

AExpressionDefinitionDefinition (de.be4.classicalb.core.parser.node.AExpressionDefinitionDefinition)3 ASubstitutionDefinitionDefinition (de.be4.classicalb.core.parser.node.ASubstitutionDefinitionDefinition)3 CheckException (de.be4.classicalb.core.parser.exceptions.CheckException)2 TDefLiteralSubstitution (de.be4.classicalb.core.parser.node.TDefLiteralSubstitution)2 TIdentifierLiteral (de.be4.classicalb.core.parser.node.TIdentifierLiteral)2 Type (de.be4.classicalb.core.parser.IDefinitions.Type)1 VisitorException (de.be4.classicalb.core.parser.exceptions.VisitorException)1 AFunctionExpression (de.be4.classicalb.core.parser.node.AFunctionExpression)1 AIdentifierExpression (de.be4.classicalb.core.parser.node.AIdentifierExpression)1 AOpSubstitution (de.be4.classicalb.core.parser.node.AOpSubstitution)1 APredicateDefinitionDefinition (de.be4.classicalb.core.parser.node.APredicateDefinitionDefinition)1 ASkipSubstitution (de.be4.classicalb.core.parser.node.ASkipSubstitution)1 Node (de.be4.classicalb.core.parser.node.Node)1 PDefinition (de.be4.classicalb.core.parser.node.PDefinition)1 PExpression (de.be4.classicalb.core.parser.node.PExpression)1 PSubstitution (de.be4.classicalb.core.parser.node.PSubstitution)1 PositionedNode (de.hhu.stups.sablecc.patch.PositionedNode)1 HashSet (java.util.HashSet)1 LinkedHashMap (java.util.LinkedHashMap)1 LinkedList (java.util.LinkedList)1