typedef struct {...} *ANY;
typedef int TYPE;
ANY parent(any)
ANY any;
TYPE type(any)
ANY any;
TYPE tag(any)
ANY any;
STRING typename(any)
ANY any;
STRING gtypename(ntype)
TYPE ntype;
BOOLEAN islist(any)
ANY any;
BOOLEAN istoken(any)
ANY any;
ANY top;
These components of the run-time library are the predefined types and macros that refer to all parse tree and liststructure nodes. Also included is the top global variable, the root of the specification parse tree.
ANY is the core data type of all parse tree and liststructure nodes. All new data types that ivy*meta SDTB creates from the grammar section are extensions to ANY. ANY may be used as a generic data type for parameters and variables whose specific types are not determined until run-time (by using the type macro).
The ANY type includes a number of basic fields that are common to all parse tree and list-structure nodes. The values in these fields are accessed through the macros and functions described here. These macros and functions can be
applied to any parse tree or list-structure node.
The istoken macro returns TRUE if the node is a token node, and FALSE if it is any other kind of node (see TOKEN(5) ). The islist macro returns TRUE if the node has the extra fields necessary for holding lists, and FALSE if it does not. All list-structure nodes, and all nonterminal and token nodes used as sequence items in the grammar will have the extra list fields (see LIST(5) ).
TYPE is the predefined type for the type index values that are generated for each node type. Each node has a TYPE field where its type index value is stored, and the type macro accesses this value. The type macro can be used by generic routines to discriminate among nodes of different types.
Each node has another field that stores a TYPE value; this field is accessed via the tag macro. This field is only used in nonterminal nodes; it holds the type index value of the first named item in the grammar rule alternative that is below the nonterminal node in the parse tree.
The parent macro can be applied to any node; it returns the node's parent node in the parse tree. If the node is the root of the parse tree then the parent macro will return NULL.
The typename macro returns the string representation of a node's type. The gtypename macro also returns the string representation of a type; however, the argument to gtypename is a type index value rather than a node.
top is a global variable that holds the root node of the specification parse tree.
Given the following two grammar rules:
input: ( expr+ )
expr: ( num | left:expr oper right:expr | id )
then the following expressions return these values: