Search in sources :

Example 1 with DefinitionUsageCheck

use of de.be4.classicalb.core.parser.analysis.checking.DefinitionUsageCheck in project probparsers by bendisposto.

the class BParser method performSemanticChecks.

private List<CheckException> performSemanticChecks(final Start rootNode) {
    final List<CheckException> list = new ArrayList<>();
    final SemanticCheck[] checks = { new ClausesCheck(), new SemicolonCheck(), new IdentListCheck(), new DefinitionUsageCheck(getDefinitions()), new PrimedIdentifierCheck(), new ProverExpressionsCheck() };
    for (SemanticCheck check : checks) {
        check.setOptions(parseOptions);
        check.runChecks(rootNode);
        list.addAll(check.getCheckExceptions());
    }
    return list;
}
Also used : SemicolonCheck(de.be4.classicalb.core.parser.analysis.checking.SemicolonCheck) IdentListCheck(de.be4.classicalb.core.parser.analysis.checking.IdentListCheck) SemanticCheck(de.be4.classicalb.core.parser.analysis.checking.SemanticCheck) ArrayList(java.util.ArrayList) ProverExpressionsCheck(de.be4.classicalb.core.parser.analysis.checking.ProverExpressionsCheck) ClausesCheck(de.be4.classicalb.core.parser.analysis.checking.ClausesCheck) PrimedIdentifierCheck(de.be4.classicalb.core.parser.analysis.checking.PrimedIdentifierCheck) DefinitionUsageCheck(de.be4.classicalb.core.parser.analysis.checking.DefinitionUsageCheck)

Example 2 with DefinitionUsageCheck

use of de.be4.classicalb.core.parser.analysis.checking.DefinitionUsageCheck in project probparsers by bendisposto.

the class OpSubstitutions method caseAFunctionExpression.

@Override
public void caseAFunctionExpression(final AFunctionExpression node) {
    if (node.getIdentifier() != null) {
        node.getIdentifier().apply(this);
    }
    if (node.getIdentifier() instanceof ADefinitionExpression && ((ADefinitionExpression) node.getIdentifier()).getParameters().isEmpty()) {
        final LinkedList<PExpression> paramList = new LinkedList<>(node.getParameters());
        final TIdentifierLiteral identifier = ((ADefinitionExpression) node.getIdentifier()).getDefLiteral();
        if (paramList.size() <= definitions.getParameterCount(identifier.getText())) {
            /*
				 * The parameters seem to belong to this definition, so we need
				 * to replace the FunctionExpression by a
				 * DefinitionFunctionExpression. If not enough parameters were
				 * given this will be found by a later check, i.e.
				 * DefinitionUsageCheck.
				 */
            final ADefinitionExpression newNode = replaceWithDefExpression(node, identifier, paramList);
            final List<PExpression> copy = newNode.getParameters();
            for (final PExpression e : copy) {
                e.apply(this);
            }
            return;
        }
    }
    /*
		 * Reached in case that: Identifier of this FunctionExpression is not a
		 * definition or there were more parameters than the definition needs
		 * (by declaration), so we asume the parameters belong to some other
		 * construct (for example a function a level higher in the AST).
		 */
    final List<PExpression> copy = node.getParameters();
    for (final PExpression e : copy) {
        e.apply(this);
    }
}
Also used : ADefinitionExpression(de.be4.classicalb.core.parser.node.ADefinitionExpression) PExpression(de.be4.classicalb.core.parser.node.PExpression) TIdentifierLiteral(de.be4.classicalb.core.parser.node.TIdentifierLiteral) LinkedList(java.util.LinkedList)

Aggregations

ClausesCheck (de.be4.classicalb.core.parser.analysis.checking.ClausesCheck)1 DefinitionUsageCheck (de.be4.classicalb.core.parser.analysis.checking.DefinitionUsageCheck)1 IdentListCheck (de.be4.classicalb.core.parser.analysis.checking.IdentListCheck)1 PrimedIdentifierCheck (de.be4.classicalb.core.parser.analysis.checking.PrimedIdentifierCheck)1 ProverExpressionsCheck (de.be4.classicalb.core.parser.analysis.checking.ProverExpressionsCheck)1 SemanticCheck (de.be4.classicalb.core.parser.analysis.checking.SemanticCheck)1 SemicolonCheck (de.be4.classicalb.core.parser.analysis.checking.SemicolonCheck)1 ADefinitionExpression (de.be4.classicalb.core.parser.node.ADefinitionExpression)1 PExpression (de.be4.classicalb.core.parser.node.PExpression)1 TIdentifierLiteral (de.be4.classicalb.core.parser.node.TIdentifierLiteral)1 ArrayList (java.util.ArrayList)1 LinkedList (java.util.LinkedList)1