Example: New expression type
As an example of new IRL code generation, you can generate IRL code for a new expression type.
Deprecated feature:
Support for custom business rule
languages is deprecated in V8.8.1. This feature will be removed in
a future release of the product. See Deprecated features for migration
details.
To generate IRL code for a new expression type, the implementation of printExpression must handle all new expressions:
public void printExpression(IlrSyntaxTree.Node node, IlrStatement stmt,
IlrAbstractCodeGenerator codeGenerator) {
if ("T-custom-expression1".equals(node.getType())) {
…
}
else if ("T-custom-expression1".equals(node.getType())) {
…
}
…
}
The following example shows how to generate the IRL code for the new expression T-kind-of:
public class BALExtCodeGeneratorExtender implements IlrCodeGeneratorExtender {
IlrCodeGeneratorExtender#printExpression(IlrSyntaxTree.Node, IlrStatement,
IlrAbstractCodeGenerator))
/**
* Handles the printing of 'T-kind-of' expression.
*/
public void printExpression(IlrSyntaxTree.Node node, IlrStatement stmt,
IlrAbstractCodeGenerator codeGenerator) {
if ("T-kind-of".equals(node.getType())) {
printIsKindOfNode(node, stmt, codeGenerator);
}
}
/**
* Prints the new 'T-kind-of' expression.
*/
private void printIsKindOfNode(IlrSyntaxTree.Node node,
IlrStatement stmt,
IlrAbstractCodeGenerator codeGenerator) {
IlrIRLCodeGenerator irlCodeGenerator = (IlrIRLCodeGenerator) codeGenerator;
irlCodeGenerator.print("(");
irlCodeGenerator.printExpressionNode(node.getSubNode(0), stmt, null);
irlCodeGenerator.print(" instanceof ");
IlrSyntaxTree.Node targetNode = node.getSubNode(1);
IlrConcept concept = IlrTranslationHelper.getConcept(targetNode,
codeGenerator.getVocabulary());
codeGenerator.print(codeGenerator.getTranslationSupport().getTypeString(concept
));
irlCodeGenerator.print(")");
}
…
}
You then register this code generator extender in the concrete syntax as follows:
<T-kind-of>.codeGeneratorExtender.irl =
balsample_extensions.brl.BALExtCodeGeneratorExtender