![]() | ![]() | ![]() | Node Phrase Types |
As mentioned above, the phrase types Nident
and
Nconst
are used to label nodes representing the leaves of
the syntax tree. All of the other node phrase names defined in the
enumeration type nodetype
are used to label internal nodes.
All of these other node phrase names are listed and described
below.
There are several important subgroups of node phrase types. One
important group is the group of "list" phrases including
Ntypelist
and Nvallist
and all of the other phrase types
whose names end with "list" (other than Nlist). These nodes are used to represent
lists of items in the program. In all cases, such nodes take
2 children. The left child ( child[0]
) of a list node points to
the first element of the list (i.e. a type definition,
value binding or whatever element type is appropriate). The
right child ( child[1]
) points to the remainder of the list.
Its value is either NULL ( = 0 ) or a pointer to
another list node of the same type.
Other important groups of phrase types include the
variable phrase types ( Nident
and Nselect
)
and the expression phrase types ( which includes all
the variable phrase types in addition to all the constructors,
"unaries" and "binaries"
mentioned in the table below).
All of the phrase names used in internal tree nodes are described in the list below. This list is organized so that node labels for phrase types occur in roughly the same order as the corresponding rules of the STApL grammar in the Draft Report on the STApL Programming Language handout.
Node | Num. of | |
Type | Children | Description |
Nprogram | 3 | Represents an entire program. Child[0] is the Nident node for the program's name. Child[1] is a (possibly NULL) list of Ntypelist nodes. Child[2] is an Nbody sub-tree. |
Nbody | 3 | Represents the body of a program or function. Child[0] is a (possibly NULL) list of Nvallist nodes. Child[1] is a (possibly NULL) list of Nfunclist nodes. Child[3] is an expression subtree. |
Ntypelist | 2 | List header used to build lists of Ntypedefn nodes. |
Ntypedefn | 2 | Used to represent a single type definition. Child[0] will be an Nident node for the name of the type. Child[1] will be an Nlist or Nrecord node describing the type itself. |
Nlist | 1 | Represents a list type declaration. Child[0] is is an Nident node for the type name specified for the elements of the list. |
Nrecord | 1 | Represents a record specification. Child[0] is a Nfieldlist containing the field specifications for all the components of the record. |
Nfieldlist | 2 | Used to represent lists of record field specifications. Child[0] will be an Ndecl. |
Ndecl | 2 | Used to represent parameter declarations and record field
specifications. Both children should be of type Nident.
Child[0] is the identifier being declared. Child[1] is
the type name. Remember that a special symbol table entry
is created
during initialization to allow uniform treatment of the
type integer . |
Nvallist | 2 | Used to represent lists of value declarations. Child[0] will be an Nvaldecl. |
Nvaldecl | 2 | Used to represent the value bindings specified in a body. Child[0] is an Nident node indicating the identifier with which a value is being associated. Child[1] will be an expression sub-tree describing the expression to be evaluated to determine the correct value for the identifier. |
Nfunclist | 2 | Used to represent lists of function definitions. Child[0] will be an Nfuncdefn. |
Nfuncdefn | 4 | Used to represent a function's definition. Child[0] is an Nident node for the function's name. Child[1] is a ( possibly NULL ) list of Nformallist nodes. Child[2] is an Nident node specifying the type name for the function's return type. Child[3] is an Nbody node for the function's body. |
Nformallist | 2 | Used to represent lists of formal parameter specifications. Child[0] will be an Ndecl. |
Nexprlist | 2 | Used to represent lists of actual parameters and arguments to constructors. Child[0] will be a node of one of the expression phrase types. |
Ncall | 2 | Represents a function call expression. Child[0] will be an Nident node for the function's name. Child[1] points to a (possibly NULL) list of Nexprlist nodes. |
Nif | 3 | Represents an if expression. Child[0] points to a sub-tree representing the "boolean" expression. Child[1] points to the expression found in the then part. Child[2] points to the expression representing the else part. |
Nselect | 2 | Represents an expression formed by selecting a component from some record variable. Child[0] describes the record sub-variable. Child[1] is an Nident node for the name of the component being selected. |
Nlistconstr | 2 | Represents a list construction expression. Child[0] is an Nident node for the name of the type of list to be created. Child[0] is a (possibly NULL) Nexprlist containing the expressions that should be evaluated to produce the values to be placed in the list. |
Nrecdconstr | 2 | Represents a record construction expression. Child[0] is an Nident node for the name of the type of record to be created. Child[0] is a (possibly NULL) Nexprlist containing the expressions that should be evaluated to produce the values to be associated with the records component names. |
Nnil | 0 | Used to represent an occurrence of the constant nil. |
unaries | 1 | The node labels Nnot and Nneg are used to represent
expressions formed using the logical not operator
(! ) and the arithmetic negation operator
(unary - ). Child[0] points to a sub-tree
representing the expression to whose value the
operator should be applied. |
binaries | 2 | The node labels Nor, Nand, Nlt, Ngt, Neq, Nle, Nge, Nne, Nplus, Nminus, Ntimes, Ndiv and Nmod are used to represent expressions formed using the logical, relational and arithmetic binary operators. The sub-expressions to whose values the operator should be applied are pointed to by child[0] and child[1]. |
Nerror | 0 | Inserted in tree at points where an error was detected in the syntax of a phrase. Actually, the only place that such nodes ever appear is as elements of "lists". So, the only place you need to check for them is when processing expression lists, parameter lists, etc. |
![]() | ![]() | ![]() | Node Phrase Types |