Search in sources :

Example 1 with APowSubsetExpression

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

the class SetType method createASTNode.

public PExpression createASTNode(Typechecker typechecker) {
    APowSubsetExpression node = new APowSubsetExpression(subtype.createASTNode(typechecker));
    typechecker.setType(node, this);
    return node;
}
Also used : APowSubsetExpression(de.be4.classicalb.core.parser.node.APowSubsetExpression)

Example 2 with APowSubsetExpression

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

the class ASTPrologTest method testFreeType.

@Test
public void testFreeType() throws BCompoundException {
    final AConstructorFreetypeConstructor multi = new AConstructorFreetypeConstructor(new TIdentifierLiteral("multi"), new APowSubsetExpression(new AIntegerSetExpression()));
    final AConstructorFreetypeConstructor single = new AConstructorFreetypeConstructor(new TIdentifierLiteral("single"), new AIntegerSetExpression());
    final AFreetype freetype = new AFreetype(new TIdentifierLiteral("T"), Arrays.<PFreetypeConstructor>asList(multi, single));
    AFreetypesMachineClause clause = new AFreetypesMachineClause(Arrays.<PFreetype>asList(freetype));
    final StringWriter swriter = new StringWriter();
    NodeIdAssignment nodeids = new NodeIdAssignment();
    clause.apply(nodeids);
    IPrologTermOutput pout = new PrologTermOutput(new PrintWriter(swriter), false);
    PositionPrinter pprinter = new ClassicalPositionPrinter(nodeids);
    ASTProlog prolog = new ASTProlog(pout, pprinter);
    clause.apply(prolog);
    String code = swriter.toString();
    assertFalse(code.isEmpty());
    assertEquals("freetypes(0,[freetype(1,'T',[constructor(2,multi,pow_subset(3,integer_set(4))),constructor(5,single,integer_set(6))])])", code);
}
Also used : ClassicalPositionPrinter(de.be4.classicalb.core.parser.analysis.prolog.ClassicalPositionPrinter) PrologTermOutput(de.prob.prolog.output.PrologTermOutput) IPrologTermOutput(de.prob.prolog.output.IPrologTermOutput) PositionPrinter(de.be4.classicalb.core.parser.analysis.prolog.PositionPrinter) ClassicalPositionPrinter(de.be4.classicalb.core.parser.analysis.prolog.ClassicalPositionPrinter) AIntegerSetExpression(de.be4.classicalb.core.parser.node.AIntegerSetExpression) TIdentifierLiteral(de.be4.classicalb.core.parser.node.TIdentifierLiteral) NodeIdAssignment(de.be4.classicalb.core.parser.analysis.prolog.NodeIdAssignment) ASTProlog(de.be4.classicalb.core.parser.analysis.prolog.ASTProlog) StringWriter(java.io.StringWriter) AConstructorFreetypeConstructor(de.be4.classicalb.core.parser.node.AConstructorFreetypeConstructor) APowSubsetExpression(de.be4.classicalb.core.parser.node.APowSubsetExpression) AFreetypesMachineClause(de.be4.classicalb.core.parser.node.AFreetypesMachineClause) AFreetype(de.be4.classicalb.core.parser.node.AFreetype) IPrologTermOutput(de.prob.prolog.output.IPrologTermOutput) PrintWriter(java.io.PrintWriter) Test(org.junit.Test)

Example 3 with APowSubsetExpression

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

the class CreateFreetypeTest method createMachine.

private Start createMachine(String name) {
    final AFreetypesMachineClause freetypes = createFreetype();
    final AConstantsMachineClause variables = new AConstantsMachineClause(createIdentifiers(VAR_NAME));
    final AMemberPredicate member = new AMemberPredicate(createIdentifier(VAR_NAME), new APowSubsetExpression(createIdentifier(FREETYPE_NAME)));
    final AInvariantMachineClause inv = new AInvariantMachineClause(member);
    final AInitialisationMachineClause init = new AInitialisationMachineClause(createAssignment(VAR_NAME, new AEmptySetExpression()));
    final AOperationsMachineClause operations = createOperations();
    final AMachineHeader header = new AMachineHeader(createIdLits(name), EMPTY_EXPRS);
    final AAbstractMachineParseUnit machine = new AAbstractMachineParseUnit(new AMachineMachineVariant(), header, Arrays.asList(freetypes, variables, inv, init, operations));
    return new Start(machine, new EOF());
}
Also used : AMachineMachineVariant(de.be4.classicalb.core.parser.node.AMachineMachineVariant) AInitialisationMachineClause(de.be4.classicalb.core.parser.node.AInitialisationMachineClause) AMachineHeader(de.be4.classicalb.core.parser.node.AMachineHeader) AConstantsMachineClause(de.be4.classicalb.core.parser.node.AConstantsMachineClause) Start(de.be4.classicalb.core.parser.node.Start) AMemberPredicate(de.be4.classicalb.core.parser.node.AMemberPredicate) AAbstractMachineParseUnit(de.be4.classicalb.core.parser.node.AAbstractMachineParseUnit) AOperationsMachineClause(de.be4.classicalb.core.parser.node.AOperationsMachineClause) AInvariantMachineClause(de.be4.classicalb.core.parser.node.AInvariantMachineClause) AFreetypesMachineClause(de.be4.classicalb.core.parser.node.AFreetypesMachineClause) APowSubsetExpression(de.be4.classicalb.core.parser.node.APowSubsetExpression) AEmptySetExpression(de.be4.classicalb.core.parser.node.AEmptySetExpression) EOF(de.be4.classicalb.core.parser.node.EOF)

Example 4 with APowSubsetExpression

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

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

APowSubsetExpression (de.be4.classicalb.core.parser.node.APowSubsetExpression)5 TIdentifierLiteral (de.be4.classicalb.core.parser.node.TIdentifierLiteral)3 AExpressionDefinitionDefinition (de.be4.classicalb.core.parser.node.AExpressionDefinitionDefinition)2 AFreetypesMachineClause (de.be4.classicalb.core.parser.node.AFreetypesMachineClause)2 ATotalFunctionExpression (de.be4.classicalb.core.parser.node.ATotalFunctionExpression)2 ASTProlog (de.be4.classicalb.core.parser.analysis.prolog.ASTProlog)1 ClassicalPositionPrinter (de.be4.classicalb.core.parser.analysis.prolog.ClassicalPositionPrinter)1 NodeIdAssignment (de.be4.classicalb.core.parser.analysis.prolog.NodeIdAssignment)1 PositionPrinter (de.be4.classicalb.core.parser.analysis.prolog.PositionPrinter)1 AAbstractMachineParseUnit (de.be4.classicalb.core.parser.node.AAbstractMachineParseUnit)1 AConstantsMachineClause (de.be4.classicalb.core.parser.node.AConstantsMachineClause)1 AConstructorFreetypeConstructor (de.be4.classicalb.core.parser.node.AConstructorFreetypeConstructor)1 AEmptySequenceExpression (de.be4.classicalb.core.parser.node.AEmptySequenceExpression)1 AEmptySetExpression (de.be4.classicalb.core.parser.node.AEmptySetExpression)1 AFreetype (de.be4.classicalb.core.parser.node.AFreetype)1 AInitialisationMachineClause (de.be4.classicalb.core.parser.node.AInitialisationMachineClause)1 AIntegerSetExpression (de.be4.classicalb.core.parser.node.AIntegerSetExpression)1 AInvariantMachineClause (de.be4.classicalb.core.parser.node.AInvariantMachineClause)1 AMachineHeader (de.be4.classicalb.core.parser.node.AMachineHeader)1 AMachineMachineVariant (de.be4.classicalb.core.parser.node.AMachineMachineVariant)1