Search in sources :

Example 31 with TIdentifierLiteral

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

the class ASTBuilder method addChooseDefinition.

public static void addChooseDefinition(IDefinitions iDefinitions) {
    if (iDefinitions.containsDefinition(CHOOSE)) {
        return;
    }
    /*-
		 * TO_STRING(S) == "0";
		 * EXTERNAL_FUNCTION_TO_STRING(X) == (X --> STRING);
		 */
    AExpressionDefinitionDefinition chooseDef = new AExpressionDefinitionDefinition();
    chooseDef.setName(new TIdentifierLiteral(CHOOSE));
    chooseDef.setParameters(createIdentifierList("X"));
    chooseDef.setRhs(new AStringExpression(new TStringLiteral("a member of X")));
    iDefinitions.addDefinition(chooseDef, IDefinitions.Type.Expression);
    AExpressionDefinitionDefinition chooseDefType = new AExpressionDefinitionDefinition();
    chooseDefType.setName(new TIdentifierLiteral("EXTERNAL_FUNCTION_CHOOSE"));
    chooseDefType.setParameters(createIdentifierList("T"));
    chooseDefType.setRhs(new ATotalFunctionExpression(new APowSubsetExpression(createIdentifier("T")), createIdentifier("T")));
    iDefinitions.addDefinition(chooseDefType, IDefinitions.Type.Expression);
}
Also used : APowSubsetExpression(de.be4.classicalb.core.parser.node.APowSubsetExpression) AExpressionDefinitionDefinition(de.be4.classicalb.core.parser.node.AExpressionDefinitionDefinition) AStringExpression(de.be4.classicalb.core.parser.node.AStringExpression) TStringLiteral(de.be4.classicalb.core.parser.node.TStringLiteral) TIdentifierLiteral(de.be4.classicalb.core.parser.node.TIdentifierLiteral) ATotalFunctionExpression(de.be4.classicalb.core.parser.node.ATotalFunctionExpression)

Example 32 with TIdentifierLiteral

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

the class ASTBuilder method addPrintSubDefinitionToIdefinitions.

public static void addPrintSubDefinitionToIdefinitions(IDefinitions definitions) {
    if (definitions.containsDefinition(PRINT)) {
        return;
    }
    /*-
		 * PRINT(x) == skip; 
		 * EXTERNAL_SUBSTITUTION_PRINT(T) == T; /* declare as external for any type T
		 */
    ASubstitutionDefinitionDefinition printDef = new ASubstitutionDefinitionDefinition();
    printDef.setName(new TDefLiteralSubstitution(PRINT));
    printDef.setParameters(createIdentifierList("value"));
    printDef.setRhs(new ASkipSubstitution());
    definitions.addDefinition(printDef, IDefinitions.Type.Substitution);
    AExpressionDefinitionDefinition forceDefType = new AExpressionDefinitionDefinition();
    forceDefType.setName(new TIdentifierLiteral("EXTERNAL_SUBSTITUTION_" + PRINT));
    forceDefType.setParameters(createIdentifierList("T"));
    forceDefType.setRhs(createIdentifier("T"));
    definitions.addDefinition(forceDefType, IDefinitions.Type.Expression);
}
Also used : TDefLiteralSubstitution(de.be4.classicalb.core.parser.node.TDefLiteralSubstitution) ASubstitutionDefinitionDefinition(de.be4.classicalb.core.parser.node.ASubstitutionDefinitionDefinition) ASkipSubstitution(de.be4.classicalb.core.parser.node.ASkipSubstitution) AExpressionDefinitionDefinition(de.be4.classicalb.core.parser.node.AExpressionDefinitionDefinition) TIdentifierLiteral(de.be4.classicalb.core.parser.node.TIdentifierLiteral)

Example 33 with TIdentifierLiteral

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

the class ASTBuilder method createAIdentifierExpression.

public static AIdentifierExpression createAIdentifierExpression(TIdentifierLiteral identifierLiteral) {
    final String name = identifierLiteral.getText();
    ArrayList<TIdentifierLiteral> list = new ArrayList<>();
    TIdentifierLiteral literal = new TIdentifierLiteral(name);
    list.add(literal);
    AIdentifierExpression result = new AIdentifierExpression(list);
    result.setStartPos(identifierLiteral.getStartPos());
    result.setEndPos(identifierLiteral.getEndPos());
    return result;
}
Also used : AIdentifierExpression(de.be4.classicalb.core.parser.node.AIdentifierExpression) ArrayList(java.util.ArrayList) TIdentifierLiteral(de.be4.classicalb.core.parser.node.TIdentifierLiteral)

Example 34 with TIdentifierLiteral

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

the class ASTBuilder method addBooleanPreferenceDefinition.

public static void addBooleanPreferenceDefinition(IDefinitions iDefinitions, String name, boolean bool) {
    AExpressionDefinitionDefinition def = new AExpressionDefinitionDefinition(new TIdentifierLiteral(name), new ArrayList<PExpression>(), bool ? new ABooleanTrueExpression() : new ABooleanFalseExpression());
    iDefinitions.addDefinition(def, IDefinitions.Type.Expression);
}
Also used : AExpressionDefinitionDefinition(de.be4.classicalb.core.parser.node.AExpressionDefinitionDefinition) ABooleanTrueExpression(de.be4.classicalb.core.parser.node.ABooleanTrueExpression) ABooleanFalseExpression(de.be4.classicalb.core.parser.node.ABooleanFalseExpression) TIdentifierLiteral(de.be4.classicalb.core.parser.node.TIdentifierLiteral) PExpression(de.be4.classicalb.core.parser.node.PExpression)

Example 35 with TIdentifierLiteral

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

the class BMachine method addPromotesClause.

public void addPromotesClause(List<String> operationList) {
    APromotesMachineClause promotes = new APromotesMachineClause();
    List<PExpression> opList = new ArrayList<>();
    for (String name : operationList) {
        List<TIdentifierLiteral> idList = new ArrayList<>();
        idList.add(new TIdentifierLiteral(name));
        AIdentifierExpression idExpr = new AIdentifierExpression(idList);
        opList.add(idExpr);
    }
    promotes.setOperationNames(opList);
    this.parseUnit.getMachineClauses().add(promotes);
}
Also used : AIdentifierExpression(de.be4.classicalb.core.parser.node.AIdentifierExpression) ArrayList(java.util.ArrayList) APromotesMachineClause(de.be4.classicalb.core.parser.node.APromotesMachineClause) PExpression(de.be4.classicalb.core.parser.node.PExpression) TIdentifierLiteral(de.be4.classicalb.core.parser.node.TIdentifierLiteral)

Aggregations

TIdentifierLiteral (de.be4.classicalb.core.parser.node.TIdentifierLiteral)44 ArrayList (java.util.ArrayList)23 AIdentifierExpression (de.be4.classicalb.core.parser.node.AIdentifierExpression)13 PExpression (de.be4.classicalb.core.parser.node.PExpression)9 CheckException (de.be4.classicalb.core.parser.exceptions.CheckException)8 AExpressionDefinitionDefinition (de.be4.classicalb.core.parser.node.AExpressionDefinitionDefinition)8 ATotalFunctionExpression (de.be4.classicalb.core.parser.node.ATotalFunctionExpression)5 LinkedList (java.util.LinkedList)4 BException (de.be4.classicalb.core.parser.exceptions.BException)3 APowSubsetExpression (de.be4.classicalb.core.parser.node.APowSubsetExpression)3 AStringExpression (de.be4.classicalb.core.parser.node.AStringExpression)3 PSubstitution (de.be4.classicalb.core.parser.node.PSubstitution)3 TStringLiteral (de.be4.classicalb.core.parser.node.TStringLiteral)3 TIdentifierLiteral (de.be4.eventbalg.core.parser.node.TIdentifierLiteral)3 VisitorException (de.be4.classicalb.core.parser.exceptions.VisitorException)2 AConstructorFreetypeConstructor (de.be4.classicalb.core.parser.node.AConstructorFreetypeConstructor)2 ADefinitionExpression (de.be4.classicalb.core.parser.node.ADefinitionExpression)2 AEqualPredicate (de.be4.classicalb.core.parser.node.AEqualPredicate)2 AEvent (de.be4.classicalb.core.parser.node.AEvent)2 AEventBModelParseUnit (de.be4.classicalb.core.parser.node.AEventBModelParseUnit)2