A syntax tree represents a business rule. It is an instance of the XML schema that defines an abstract syntax, and specifies the structure of the XML object that represents a rule. It does not, therefore, depend on the locale.
A syntax tree is the result of BRL artifact interpretation or editing. It is an internal representation of this artifact. It generates IRL code for this rule. You access the abstract syntax tree using IlrSyntaxTree.
Semantic checking as well as other tasks are performed against this syntax tree.
You use an IlrBRLParser to create a syntax tree from a BRL artifact.
The abstract syntax tree is composed of nodes. The
IlrSyntaxTree.Node class
represents a node in the tree. There is a single root node in a syntax tree.
You retrieve the parent of a node with the method
getSuperNode. This method
returns null
for the root node.
Each node has a name corresponding to an element in the abstract syntax.
Each node can contain:
Call iterator to retrieve an iterator used to iterate depth first over subnodes from a given node. To filter the nodes to be iterated over, pass an IlrSyntaxTree.NodeTester interface to iterator(NodeTester). For example, if you want to iterate over all subnodes named class:
IlrSyntaxTree.Iterator iterator = node.iterator(“class”) while (iterator.hasNextNode()) { System.out.println("subnode: "+ subnode.getName()) }
The following code example shows a node translator for the <T-if-then-else>
node type:
public IlrStatement process(IlrSyntaxTree.Node node, IlrTranslationContext context) { // Process the test node context.processNode(node.getSubNode("test")); IlrBlockActionStatement blockaction = new IlrBlockActionStatement(node); blockaction.setKind(IF_THEN_ELSE); IlrBlockActionStatement thenaction = new IlrBlockActionStatement(node); thenaction.setKind(IF_THEN_ELSE_THEN); IlrSyntaxTree.Iterator thenActionsNodeIter = node.iterator("then-action", IlrSyntaxTree.SUBNODES); while (thenActionsNodeIter.hasNextNode()) { IlrSyntaxTree.Node actionNode = thenActionsNodeIter.nextNode().getSubNode(0); if (actionNode != null) { IlrActionStatement action = (IlrActionStatement) context.processNode(actionNode); if (action != null) { thenaction.addAction(action); } } } blockaction.addAction(thenaction); IlrSyntaxTree.Iterator elseActionsNodeIter = node.iterator("else-action", IlrSyntaxTree.SUBNODES); if (elseActionsNodeIter.hasNext()) { IlrBlockActionStatement elseaction = new IlrBlockActionStatement(node); elseaction.setKind(IF_THEN_ELSE_ELSE); while (elseActionsNodeIter.hasNextNode()) { IlrSyntaxTree.Node actionNode = elseActionsNodeIter.nextNode().getSubNode(0); if (actionNode != null) { IlrActionStatement action = (IlrActionStatement) context.processNode(actionNode); if (action != null) { elseaction.addAction(action); } } } blockaction.addAction(elseaction); } return blockaction; }@core