View source: R/derivationTrees.R
treeANL | R Documentation |
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
)
tree |
A derivation tree. |
ST |
A symbol table. |
maxdepth |
Limit on the depth of a derivation tree. |
ANL |
Attributed node list (empty on invocation). |
IL |
Index function list (empty on invocation). |
count |
Trail count (1 on invocation). |
depth |
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
),
...
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.
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)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.