Search in sources :

Example 11 with Node

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

the class MachineContext method caseAOperationsMachineClause.

@Override
public void caseAOperationsMachineClause(AOperationsMachineClause node) {
    this.operationMachineClause = 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<POperation> copy = new ArrayList<POperation>(node.getOperations());
    // first collect all operations
    for (POperation e : copy) {
        AOperation op = (AOperation) e;
        String name = Utils.getTIdentifierListAsString(op.getOpName());
        // existString(name);
        if (operations.keySet().contains(name)) {
            throw new ScopeException(String.format("Duplicate operation: '%s'", name));
        }
        operations.put(name, op);
    }
    // visit all operations
    for (POperation e : copy) {
        e.apply(this);
    }
}
Also used : AOperation(de.be4.classicalb.core.parser.node.AOperation) POperation(de.be4.classicalb.core.parser.node.POperation) ArrayList(java.util.ArrayList) LinkedHashMap(java.util.LinkedHashMap) ScopeException(de.prob.typechecker.exceptions.ScopeException)

Example 12 with Node

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

the class MachineContext method caseAMachineHeader.

@Override
public void caseAMachineHeader(AMachineHeader node) {
    this.header = node;
    if (machineName == null) {
        List<TIdentifierLiteral> nameList = new ArrayList<TIdentifierLiteral>(node.getName());
        this.machineName = Utils.getTIdentifierListAsString(nameList);
    }
    List<PExpression> copy = new ArrayList<PExpression>(node.getParameters());
    for (PExpression e : copy) {
        AIdentifierExpression p = (AIdentifierExpression) e;
        String name = Utils.getTIdentifierListAsString(p.getIdentifier());
        exist(p.getIdentifier());
        if (Character.isUpperCase(name.charAt(0))) {
            this.machineSetParameter.put(name, p);
        } else {
            this.machineScalarParameter.put(name, p);
        }
    }
}
Also used : AIdentifierExpression(de.be4.classicalb.core.parser.node.AIdentifierExpression) ArrayList(java.util.ArrayList) TIdentifierLiteral(de.be4.classicalb.core.parser.node.TIdentifierLiteral) PExpression(de.be4.classicalb.core.parser.node.PExpression)

Example 13 with Node

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

the class MachineContext method caseAAbstractConstantsMachineClause.

@Override
public void caseAAbstractConstantsMachineClause(AAbstractConstantsMachineClause node) {
    hasConstants = true;
    List<PExpression> copy = new ArrayList<PExpression>(node.getIdentifiers());
    for (PExpression e : copy) {
        AIdentifierExpression c = (AIdentifierExpression) e;
        String name = Utils.getTIdentifierListAsString(c.getIdentifier());
        exist(c.getIdentifier());
        constants.put(name, c);
    }
}
Also used : AIdentifierExpression(de.be4.classicalb.core.parser.node.AIdentifierExpression) ArrayList(java.util.ArrayList) PExpression(de.be4.classicalb.core.parser.node.PExpression)

Example 14 with Node

use of de.be4.classicalb.core.parser.node.Node 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 15 with Node

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

the class MachineContext method caseASeesMachineClause.

@Override
public void caseASeesMachineClause(ASeesMachineClause node) {
    this.seesMachineClause = node;
    List<PExpression> copy = new ArrayList<PExpression>(node.getMachineNames());
    for (PExpression e : copy) {
        AIdentifierExpression p = (AIdentifierExpression) e;
        String name = Utils.getTIdentifierListAsString(p.getIdentifier());
        try {
            exist(p.getIdentifier());
        } catch (ScopeException e2) {
            throw new ScopeException("Machine '" + name + "' is seen twice.");
        }
        seenMachines.put(name, p);
    }
}
Also used : AIdentifierExpression(de.be4.classicalb.core.parser.node.AIdentifierExpression) ArrayList(java.util.ArrayList) PExpression(de.be4.classicalb.core.parser.node.PExpression) ScopeException(de.prob.typechecker.exceptions.ScopeException)

Aggregations

CheckException (de.be4.classicalb.core.parser.exceptions.CheckException)42 PExpression (de.be4.classicalb.core.parser.node.PExpression)30 ArrayList (java.util.ArrayList)30 Node (de.be4.classicalb.core.parser.node.Node)20 AIdentifierExpression (de.be4.classicalb.core.parser.node.AIdentifierExpression)16 TIdentifierLiteral (de.be4.classicalb.core.parser.node.TIdentifierLiteral)12 TPragmaIdOrString (de.be4.classicalb.core.parser.node.TPragmaIdOrString)11 VisitorException (de.be4.classicalb.core.parser.exceptions.VisitorException)8 HashSet (java.util.HashSet)8 Token (de.be4.ltl.core.parser.node.Token)7 Type (de.be4.classicalb.core.parser.IDefinitions.Type)6 IOException (java.io.IOException)6 ASTProlog (de.be4.classicalb.core.parser.analysis.prolog.ASTProlog)5 PositionedNode (de.hhu.stups.sablecc.patch.PositionedNode)5 LinkedList (java.util.LinkedList)5 BCompoundException (de.be4.classicalb.core.parser.exceptions.BCompoundException)4 LinkedHashMap (java.util.LinkedHashMap)4 Test (org.junit.Test)4 ClassicalPositionPrinter (de.be4.classicalb.core.parser.analysis.prolog.ClassicalPositionPrinter)3 NodeIdAssignment (de.be4.classicalb.core.parser.analysis.prolog.NodeIdAssignment)3