Search in sources :

Example 6 with AExpressionDefinitionDefinition

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

the class DefinitionFilesTest method testOneDefinitionFile.

@Test
public void testOneDefinitionFile() throws BCompoundException {
    final String testMachine = "MACHINE Test\nDEFINITIONS \"DefFile\"; def1 == xx\nINVARIANT def2 = def3\nEND";
    final BParser parser = new BParser("testcase");
    parser.parse(testMachine, true, this);
    final IDefinitions definitions = parser.getDefinitions();
    final AExpressionDefinitionDefinition def1 = (AExpressionDefinitionDefinition) definitions.getDefinition("def1");
    assertEquals("def1", def1.getName().getText());
    assertEquals(0, def1.getParameters().size());
    assertTrue(def1.getRhs() instanceof AIdentifierExpression);
    final AExpressionDefinitionDefinition def2 = (AExpressionDefinitionDefinition) definitions.getDefinition("def2");
    assertEquals("def2", def2.getName().getText());
    assertEquals(0, def2.getParameters().size());
    assertTrue(def2.getRhs() instanceof AIdentifierExpression);
}
Also used : AIdentifierExpression(de.be4.classicalb.core.parser.node.AIdentifierExpression) IDefinitions(de.be4.classicalb.core.parser.IDefinitions) AExpressionDefinitionDefinition(de.be4.classicalb.core.parser.node.AExpressionDefinitionDefinition) BParser(de.be4.classicalb.core.parser.BParser) Test(org.junit.Test)

Example 7 with AExpressionDefinitionDefinition

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

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

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

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

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