use of de.be4.classicalb.core.parser.IDefinitions 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);
}
use of de.be4.classicalb.core.parser.IDefinitions 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);
}
use of de.be4.classicalb.core.parser.IDefinitions 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);
}
use of de.be4.classicalb.core.parser.IDefinitions 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);
}
use of de.be4.classicalb.core.parser.IDefinitions 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);
}
Aggregations