// Create a new leaf node, and pass it the current leaf count,
// which is its DFA state position. Bump the leaf count after
// storing it. This makes the positions zero based since we
// store first and then increment.
//
nodeRet = new CMLeaf(specNode.type, specNode.value, fLeafCount++);
}
else
{
//
// Its not a leaf, so we have to recurse its left and maybe right
// nodes. Save both values before we recurse and trash the node.
//
final int leftNode = specNode.value;
final int rightNode = specNode.otherValue;
if ((specNode.type == XMLContentSpecNode.CONTENTSPECNODE_CHOICE)
|| (specNode.type == XMLContentSpecNode.CONTENTSPECNODE_SEQ))
{
//
// Recurse on both children, and return a binary op node
// with the two created sub nodes as its children. The node
// type is the same type as the source.
//
nodeRet = new CMBinOp
(
specNode.type
, buildSyntaxTree(leftNode, specNode)
, buildSyntaxTree(rightNode, specNode)
);
}
else if (specNode.type == XMLContentSpecNode.CONTENTSPECNODE_ZERO_OR_MORE)
{
nodeRet = new CMUniOp
(
specNode.type
, buildSyntaxTree(leftNode, specNode)
);
}
else if (specNode.type == XMLContentSpecNode.CONTENTSPECNODE_ZERO_OR_ONE)
{
// Convert to (x|epsilon)
nodeRet = new CMBinOp
(
XMLContentSpecNode.CONTENTSPECNODE_CHOICE
, buildSyntaxTree(leftNode, specNode)
, new CMLeaf(XMLContentSpecNode.CONTENTSPECNODE_LEAF, fEpsilonIndex)
);
}
else if (specNode.type == XMLContentSpecNode.CONTENTSPECNODE_ONE_OR_MORE)
{
// Convert to (x,x*)