Search in sources :

Example 1 with ATotalFunctionExpression

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

the class ASTBuilder method addFormatToStringDefinition.

public static void addFormatToStringDefinition(IDefinitions iDefinitions) {
    if (iDefinitions.containsDefinition(FORMAT_TO_STRING)) {
        return;
    }
    /*-
		 * FORMAT_TO_STRING(MyFormatString,ListOfValues) == "0";
		 * EXTERNAL_FUNCTION_FORMAT_TO_STRING(TO_STRING_TYPE) == STRING*seq(TO_STRING_TYPE) --> STRING;
		 */
    AExpressionDefinitionDefinition formatDef = new AExpressionDefinitionDefinition();
    formatDef.setName(new TIdentifierLiteral(FORMAT_TO_STRING));
    formatDef.setParameters(createExpressionList("S", "T"));
    formatDef.setRhs(new AStringExpression(new TStringLiteral("abc")));
    iDefinitions.addDefinition(formatDef, IDefinitions.Type.Expression);
    AExpressionDefinitionDefinition formatType = new AExpressionDefinitionDefinition();
    formatType.setName(new TIdentifierLiteral("EXTERNAL_FUNCTION_FORMAT_TO_STRING"));
    formatType.setParameters(createExpressionList("T"));
    formatType.setRhs(new ATotalFunctionExpression(new AMultOrCartExpression(new AStringSetExpression(), new ASeqExpression(createIdentifier("T"))), new AStringSetExpression()));
    iDefinitions.addDefinition(formatType, IDefinitions.Type.Expression);
}
Also used : AStringSetExpression(de.be4.classicalb.core.parser.node.AStringSetExpression) AMultOrCartExpression(de.be4.classicalb.core.parser.node.AMultOrCartExpression) ASeqExpression(de.be4.classicalb.core.parser.node.ASeqExpression) 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 2 with ATotalFunctionExpression

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

the class ASTBuilder method addToStringDefinition.

public static void addToStringDefinition(IDefinitions definitions) {
    if (definitions.containsDefinition(TO_STRING)) {
        return;
    }
    /*-
		 * TO_STRING(S) == "0"; 
		 * EXTERNAL_FUNCTION_TO_STRING(X) == X -->STRING;
		 */
    AExpressionDefinitionDefinition toStringDef = new AExpressionDefinitionDefinition();
    toStringDef.setName(new TIdentifierLiteral(TO_STRING));
    toStringDef.setParameters(createIdentifierList("S"));
    toStringDef.setRhs(new AStringExpression(new TStringLiteral("0")));
    definitions.addDefinition(toStringDef, IDefinitions.Type.Expression);
    AExpressionDefinitionDefinition toStringTypeDef = new AExpressionDefinitionDefinition();
    toStringTypeDef.setName(new TIdentifierLiteral("EXTERNAL_FUNCTION_TO_STRING"));
    toStringTypeDef.setParameters(createIdentifierList("X"));
    toStringTypeDef.setRhs(new ATotalFunctionExpression(createIdentifier("X"), new AStringSetExpression()));
    definitions.addDefinition(toStringTypeDef, IDefinitions.Type.Expression);
}
Also used : AStringSetExpression(de.be4.classicalb.core.parser.node.AStringSetExpression) 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 3 with ATotalFunctionExpression

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

the class ASTBuilder method addSortDefinition.

public static void addSortDefinition(IDefinitions iDefinitions) {
    if (iDefinitions.containsDefinition(SORT)) {
        return;
    }
    /*- SORT
		 *  SORT(X) == [];
		 *  EXTERNAL_FUNCTION_SORT(T) == POW(T)-->seq(T);
		 */
    AExpressionDefinitionDefinition sortDef = new AExpressionDefinitionDefinition();
    sortDef.setName(new TIdentifierLiteral(SORT));
    sortDef.setParameters(createExpressionList("X"));
    sortDef.setRhs(new AEmptySequenceExpression());
    iDefinitions.addDefinition(sortDef, IDefinitions.Type.Expression);
    AExpressionDefinitionDefinition sortType = new AExpressionDefinitionDefinition();
    sortType.setName(new TIdentifierLiteral("EXTERNAL_FUNCTION_SORT"));
    sortType.setParameters(createExpressionList("T"));
    sortType.setRhs(new ATotalFunctionExpression(new APowSubsetExpression(createIdentifier("T")), new ASeqExpression(createIdentifier("T"))));
    iDefinitions.addDefinition(sortType, IDefinitions.Type.Expression);
}
Also used : AEmptySequenceExpression(de.be4.classicalb.core.parser.node.AEmptySequenceExpression) APowSubsetExpression(de.be4.classicalb.core.parser.node.APowSubsetExpression) ASeqExpression(de.be4.classicalb.core.parser.node.ASeqExpression) AExpressionDefinitionDefinition(de.be4.classicalb.core.parser.node.AExpressionDefinitionDefinition) TIdentifierLiteral(de.be4.classicalb.core.parser.node.TIdentifierLiteral) ATotalFunctionExpression(de.be4.classicalb.core.parser.node.ATotalFunctionExpression)

Example 4 with ATotalFunctionExpression

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

the class ASTBuilder method addForceDefinition.

public static void addForceDefinition(IDefinitions iDefinitions) {
    if (iDefinitions.containsDefinition(FORCE)) {
        return;
    }
    /*-
		 * EXTERNAL_FUNCTION_FORCE(T) == T --> T; 
		 * FORCE(value) == value;
		 * forces evaluation of symbolic set representations 
		 * usage: FORCE({ x | x:1..100 & x mod 2 = 0 } )
		 */
    AExpressionDefinitionDefinition forceDef = new AExpressionDefinitionDefinition();
    forceDef.setName(new TIdentifierLiteral(FORCE));
    String value = "value";
    forceDef.setParameters(createIdentifierList(value));
    forceDef.setRhs(createIdentifier(value));
    iDefinitions.addDefinition(forceDef, IDefinitions.Type.Expression);
    AExpressionDefinitionDefinition forceDefType = new AExpressionDefinitionDefinition();
    forceDefType.setName(new TIdentifierLiteral("EXTERNAL_FUNCTION_" + FORCE));
    forceDefType.setParameters(createIdentifierList("T"));
    forceDefType.setRhs(new ATotalFunctionExpression(createIdentifier("T"), createIdentifier("T")));
    iDefinitions.addDefinition(forceDefType, IDefinitions.Type.Expression);
}
Also used : AExpressionDefinitionDefinition(de.be4.classicalb.core.parser.node.AExpressionDefinitionDefinition) TIdentifierLiteral(de.be4.classicalb.core.parser.node.TIdentifierLiteral) ATotalFunctionExpression(de.be4.classicalb.core.parser.node.ATotalFunctionExpression)

Example 5 with ATotalFunctionExpression

use of de.be4.classicalb.core.parser.node.ATotalFunctionExpression 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)

Aggregations

AExpressionDefinitionDefinition (de.be4.classicalb.core.parser.node.AExpressionDefinitionDefinition)5 ATotalFunctionExpression (de.be4.classicalb.core.parser.node.ATotalFunctionExpression)5 TIdentifierLiteral (de.be4.classicalb.core.parser.node.TIdentifierLiteral)5 AStringExpression (de.be4.classicalb.core.parser.node.AStringExpression)3 TStringLiteral (de.be4.classicalb.core.parser.node.TStringLiteral)3 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 AEmptySequenceExpression (de.be4.classicalb.core.parser.node.AEmptySequenceExpression)1 AMultOrCartExpression (de.be4.classicalb.core.parser.node.AMultOrCartExpression)1