Search in sources :

Example 1 with ScopeException

use of de.prob.typechecker.exceptions.ScopeException 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 2 with ScopeException

use of de.prob.typechecker.exceptions.ScopeException 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)

Example 3 with ScopeException

use of de.prob.typechecker.exceptions.ScopeException in project probparsers by bendisposto.

the class MachineContext method caseAOpSubstitution.

@Override
public void caseAOpSubstitution(AOpSubstitution node) {
    if (node.getName() != null) {
        AIdentifierExpression op = (AIdentifierExpression) node.getName();
        String name = Utils.getTIdentifierListAsString(op.getIdentifier());
        Node o = operations.get(name);
        if (o != null) {
            this.referencesTable.put(op, o);
        } else {
            throw new ScopeException("Unknown operation '" + name + "'");
        }
    }
    {
        List<PExpression> copy = new ArrayList<PExpression>(node.getParameters());
        for (PExpression e : copy) {
            e.apply(this);
        }
    }
}
Also used : AIdentifierExpression(de.be4.classicalb.core.parser.node.AIdentifierExpression) Node(de.be4.classicalb.core.parser.node.Node) List(java.util.List) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) PExpression(de.be4.classicalb.core.parser.node.PExpression) ScopeException(de.prob.typechecker.exceptions.ScopeException)

Aggregations

ScopeException (de.prob.typechecker.exceptions.ScopeException)3 ArrayList (java.util.ArrayList)3 AIdentifierExpression (de.be4.classicalb.core.parser.node.AIdentifierExpression)2 PExpression (de.be4.classicalb.core.parser.node.PExpression)2 AOperation (de.be4.classicalb.core.parser.node.AOperation)1 Node (de.be4.classicalb.core.parser.node.Node)1 POperation (de.be4.classicalb.core.parser.node.POperation)1 LinkedHashMap (java.util.LinkedHashMap)1 LinkedList (java.util.LinkedList)1 List (java.util.List)1