use of de.be4.classicalb.core.parser.node.AIdentifierExpression in project probparsers by bendisposto.
the class OpSubstitutions method leaveScope.
private void leaveScope(final LinkedList<PExpression> identifiers) {
for (final PExpression expression : identifiers) {
if (expression instanceof AIdentifierExpression) {
final String identifierString = Utils.getTIdentifierListAsString(((AIdentifierExpression) expression).getIdentifier());
final Integer number = scopedVariables.get(identifierString);
if (number > 1) {
scopedVariables.put(identifierString, number - 1);
} else {
scopedVariables.remove(identifierString);
}
} else {
// IGNORE, typechecking is done later
}
}
}
use of de.be4.classicalb.core.parser.node.AIdentifierExpression in project probparsers by bendisposto.
the class OpSubstitutions method caseAFuncOpSubstitution.
@Override
public void caseAFuncOpSubstitution(final AFuncOpSubstitution node) {
final PExpression expression = node.getFunction();
PExpression idExpr = null;
LinkedList<PExpression> parameters = null;
Type type = null;
TIdentifierLiteral idToken = null;
String idString = null;
if (expression instanceof AFunctionExpression) {
// the operation was parsed as a function expression
final AFunctionExpression function = (AFunctionExpression) expression;
final PExpression funcId = function.getIdentifier();
if (funcId instanceof AIdentifierExpression) {
final AIdentifierExpression identifier = (AIdentifierExpression) funcId;
idString = Utils.getTIdentifierListAsString(identifier.getIdentifier());
idToken = identifier.getIdentifier().get(0);
type = definitions.getType(idString);
} else {
type = Type.NoDefinition;
}
idExpr = function.getIdentifier();
parameters = new LinkedList<>(function.getParameters());
} else if (expression instanceof AIdentifierExpression) {
// the operation was parsed as an identifier expression
final AIdentifierExpression identifier = (AIdentifierExpression) expression;
idString = Utils.getTIdentifierListAsString(identifier.getIdentifier());
idToken = identifier.getIdentifier().get(0);
type = definitions.getType(idString);
idExpr = expression;
parameters = new LinkedList<>();
} else {
// some other expression was parsed (NOT allowed)
throw new BParseException(null, "Expecting operation");
}
if (type != Type.NoDefinition && idToken != null) {
if (type == Type.Substitution || type == Type.ExprOrSubst) {
// create DefinitionSubstitution
final ADefinitionSubstitution defSubst = new ADefinitionSubstitution(new TDefLiteralSubstitution(idToken.getText(), idToken.getLine(), idToken.getPos()), parameters);
if (type == Type.ExprOrSubst) {
// type is determined now => set to Substitution
setTypeSubstDef(node, idString);
}
// transfer position information
final PositionedNode posNode = node;
final PositionedNode newPosNode = defSubst;
newPosNode.setStartPos(posNode.getStartPos());
newPosNode.setEndPos(posNode.getEndPos());
node.replaceBy(defSubst);
defSubst.apply(this);
} else {
// finding some other type here is an error!
throw new VisitorException(new CheckException("Expecting substitution here but found definition with type '" + type + "'", node));
}
} else {
// no def, no problem ;-)
final AOpSubstitution opSubst = new AOpSubstitution(idExpr, parameters);
opSubst.setStartPos(idExpr.getStartPos());
opSubst.setEndPos(idExpr.getEndPos());
node.replaceBy(opSubst);
opSubst.apply(this);
}
}
use of de.be4.classicalb.core.parser.node.AIdentifierExpression in project probparsers by bendisposto.
the class RulesMachineChecker method checkTagsAttribute.
private void checkTagsAttribute(POperationAttribute pOperationAttribute, LinkedList<PExpression> arguments) {
final List<String> tags = new ArrayList<>();
for (PExpression pExpression : arguments) {
if (pExpression instanceof AIdentifierExpression) {
final AIdentifierExpression ident = (AIdentifierExpression) pExpression;
final String identifierAsString = Utils.getTIdentifierListAsString(ident.getIdentifier());
tags.add(identifierAsString);
} else if (pExpression instanceof AStringExpression) {
final AStringExpression stringExpr = (AStringExpression) pExpression;
tags.add(stringExpr.getContent().getText());
} else {
errorList.add(new CheckException("Expected identifier or string after the TAGS attribute.", pOperationAttribute));
}
}
currentOperation.addTags(tags);
return;
}
use of de.be4.classicalb.core.parser.node.AIdentifierExpression in project probparsers by bendisposto.
the class RulesMachineChecker method checkFailedRuleErrorTypeOperator.
private void checkFailedRuleErrorTypeOperator(AOperatorPredicate node, final List<PExpression> arguments) {
if (arguments.size() != 2) {
this.errorList.add(new CheckException("The FAILED_RULE_ERROR_TYPE predicate operator expects exactly two arguments.", node));
return;
}
PExpression pExpression = node.getIdentifiers().get(0);
if (!(pExpression instanceof AIdentifierExpression)) {
this.errorList.add(new CheckException("The first argument of FAILED_RULE_ERROR_TYPE must be an identifier.", node));
return;
}
PExpression secondArg = node.getIdentifiers().get(1);
if (!(secondArg instanceof AIntegerExpression)) {
this.errorList.add(new CheckException("The second argument of FAILED_RULE_ERROR_TYPE must be an integer literal.", node));
return;
}
this.referencedRuleOperations.add((AIdentifierExpression) arguments.get(0));
return;
}
use of de.be4.classicalb.core.parser.node.AIdentifierExpression in project probparsers by bendisposto.
the class RulesMachineChecker method checkDependsOnComputationAttribute.
private void checkDependsOnComputationAttribute(POperationAttribute pOperationAttribute, LinkedList<PExpression> arguments) {
List<AIdentifierExpression> list = new ArrayList<>();
for (PExpression pExpression : arguments) {
if (pExpression instanceof AIdentifierExpression) {
list.add((AIdentifierExpression) pExpression);
} else {
errorList.add(new CheckException("Expected a list of identifiers after DEPENDS_ON_COMPUTATION.", pOperationAttribute));
}
}
currentOperation.addAllComputationDependencies(list);
return;
}
Aggregations