Learn R Programming

xegaDerivationTrees (version 1.0.0.6)

treeANL: Builds an Attributed Node List (ANL) of a derivation tree.

Description

treeANL() recursively traverses a derivation tree and collects information about the derivation tree in an attributed node list (ANL).

Usage

treeANL(
  tree,
  ST,
  maxdepth = 5,
  ANL = list(),
  IL = list(),
  count = 1,
  depth = 1
)

Value

A list with three elements:

  1. $count: The trail length (not needed).

  2. $subtreedepth: The derivation tree depth (not needed).

  3. $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.

Arguments

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).

Details

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), ...

See Also

Other Access Tree Parts: filterANL(), filterANLid(), treeChildren(), treeRoot()

Examples

Run this code
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