ENCLOSING(5)

Table of Contents

Name

enclosing returns an ancestral node of a parse tree node

Synopsis

ANY enclosing(tree, ntype)

ANY tree;
/* parse tree node */ TYPE ntype; /* type of ancestral node */

Description

This component of the run-time library is a function that returns the first parse tree node of type ntype in the ancestral line of node tree, beginning with the parent of tree. If there is no such node, then NULL is returned. The functions uniquenode and nthnode (see UNIQUENODE(5) and TRAVERSE(5) ) perform similar functions for descendent nodes.

Example

With the following grammar section:
input: ( expr+ )
expr: ( id | «(» left:expr oper expr «)» )

id:
<[a-z]+> oper: <[+*]> and the specification input: (a + b) ((c + d)*e) then if x were a variable holding the EXPR node associated with the identifier d, the following expressions would return the values given:
type(x)
returns Expr
enclosing(x,Id)
returns NULL
enclosing(x,Input)
returns top
enclosing(x,Expr)
returns the EXPR node of (c+d) enclosing(enclosing(x,Expr),Expr) returns the EXPR node of ((c+d)*e)

See Also

ANY(5)
TRAVERSE(5)
UNIQUENODE(5)


© 1990 Lucent Technologies, Inc
© 1998 Harmony Software, Inc