Search in sources :

Example 11 with AExpressionDefinitionDefinition

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

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

the class RulesMachineChecker method caseAExpressionDefinitionDefinition.

@Override
public void caseAExpressionDefinitionDefinition(AExpressionDefinitionDefinition 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)

Example 13 with AExpressionDefinitionDefinition

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

the class LTLFormulaVisitor method parseDefinition.

public void parseDefinition(AExpressionDefinitionDefinition def) {
    if (!(def.getRhs() instanceof AStringExpression)) {
        throw new LTLParseException("Error: LTL formula is not in a string representation.");
    }
    AStringExpression stringNode = (AStringExpression) def.getRhs();
    this.ltlFormula = stringNode.getContent().getText();
    try {
        this.ltlFormulaStart = parseLTLFormula(ltlFormula);
    } catch (Exception e) {
        String message = "Parsing definition " + name + " (line " + def.getStartPos().getLine() + "):\n";
        throw new LTLParseException(message + e.getMessage());
    }
}
Also used : LTLParseException(de.prob.typechecker.exceptions.LTLParseException) AStringExpression(de.be4.classicalb.core.parser.node.AStringExpression) LexerException(de.be4.ltl.core.parser.lexer.LexerException) ParserException(de.be4.ltl.core.parser.parser.ParserException) ScopeException(de.prob.typechecker.exceptions.ScopeException) LTLParseException(de.prob.typechecker.exceptions.LTLParseException) IOException(java.io.IOException) BCompoundException(de.be4.classicalb.core.parser.exceptions.BCompoundException)

Example 14 with AExpressionDefinitionDefinition

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

the class DefinitionCollector method caseAConversionDefinition.

@Override
public void caseAConversionDefinition(AConversionDefinition node) {
    PDefinition def = node.getDefinition();
    if (def instanceof AExpressionDefinitionDefinition) {
        AExpressionDefinitionDefinition exprDef = (AExpressionDefinitionDefinition) def;
        final String defName = exprDef.getName().getText();
        final Type type = defTypes.getType(defName);
        addDefinition(node, type, defName);
    } else {
        this.exceptions.add(new CheckException("Only an expression is allowed on the right hand side of a conversion definition.", node));
    }
}
Also used : PDefinition(de.be4.classicalb.core.parser.node.PDefinition) Type(de.be4.classicalb.core.parser.IDefinitions.Type) CheckException(de.be4.classicalb.core.parser.exceptions.CheckException) AExpressionDefinitionDefinition(de.be4.classicalb.core.parser.node.AExpressionDefinitionDefinition)

Example 15 with AExpressionDefinitionDefinition

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

the class DefinitionCollector method inAExpressionDefinitionDefinition.

@Override
public void inAExpressionDefinitionDefinition(final AExpressionDefinitionDefinition 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)

Aggregations

AExpressionDefinitionDefinition (de.be4.classicalb.core.parser.node.AExpressionDefinitionDefinition)12 TIdentifierLiteral (de.be4.classicalb.core.parser.node.TIdentifierLiteral)8 ATotalFunctionExpression (de.be4.classicalb.core.parser.node.ATotalFunctionExpression)5 AStringExpression (de.be4.classicalb.core.parser.node.AStringExpression)4 CheckException (de.be4.classicalb.core.parser.exceptions.CheckException)3 AIdentifierExpression (de.be4.classicalb.core.parser.node.AIdentifierExpression)3 ASubstitutionDefinitionDefinition (de.be4.classicalb.core.parser.node.ASubstitutionDefinitionDefinition)3 TStringLiteral (de.be4.classicalb.core.parser.node.TStringLiteral)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 APowSubsetExpression (de.be4.classicalb.core.parser.node.APowSubsetExpression)2 ASeqExpression (de.be4.classicalb.core.parser.node.ASeqExpression)2 AStringSetExpression (de.be4.classicalb.core.parser.node.AStringSetExpression)2 PDefinition (de.be4.classicalb.core.parser.node.PDefinition)2 PExpression (de.be4.classicalb.core.parser.node.PExpression)2 TDefLiteralSubstitution (de.be4.classicalb.core.parser.node.TDefLiteralSubstitution)2 Test (org.junit.Test)2 BCompoundException (de.be4.classicalb.core.parser.exceptions.BCompoundException)1 VisitorException (de.be4.classicalb.core.parser.exceptions.VisitorException)1