treeANL() recursively traverses a derivation tree
and collects information about the derivation tree in an attributed
node list (ANL).
treeANL(
tree,
ST,
maxdepth = 5,
ANL = list(),
IL = list(),
count = 1,
depth = 1
)A list with three elements:
$count: The trail length (not needed).
$subtreedepth: The derivation tree depth (not needed).
$ANL: The attributed node list is a list of nodes.
Each node is represented as a list of the following attributes:
Node$ID: Id in the symbol table ST.
Node$NonTerminal: Is the symbol a non-terminal?
Node$Pos: Position in the trail.
Node$Depth: Depth of node.
Node$Rdepth: Residual depth for expansion.
Node$subtreedepth: Depth of subtree starting here.
Node$Index: R index of the node in the derivation tree.
Allows fast tree extraction and insertion.
A derivation tree.
A symbol table.
Limit on the depth of a derivation tree.
Attributed node list (empty on invocation).
Index function list (empty on invocation).
Trail count (1 on invocation).
Derivation tree depth (1 on invocation).
An attributed node has the following elements:
$ID: Id in the symbol table ST.
$NonTerminal: Is the symbol a non-terminal?
$Pos: Position in the trail.
$Depth: Depth of node.
$Rdepth: Residual depth for expansion.
$subtreedepth: Depth of subtree starting here.
$Index: R index of the node in the derivation tree.
Allows fast tree extraction and insertion.
These elements can be used e.g.
for inserting and extracting subtrees
(Pos or node$Index),
for checking
the feasibility of subtree substitution (ID),
for checking depth bounds
(Depth, RDepth, and subtreedepth),
...
Other Access Tree Parts:
filterANL(),
filterANLid(),
treeChildren(),
treeRoot()
g<-compileBNF(booleanGrammar())
a<-randomDerivationTree(g$Start, g)
b<-treeANL(a, g$ST)
c<-treeANL(a, g$ST, 10)
d<-treeANL(a, g$ST, maxdepth=10)
Run the code above in your browser using DataLab