PCT::Node - base class for PAST and POST nodes


This file implements the base class for abstract syntax tree (PAST) and opcode syntax tree (POST) nodes in the Parrot Compiler Toolkit.

PCT::Node ^

PCT::Node is the base class for all PAST and POST nodes. It's derived from class Capture, so that it has both array and hash components. The array component is used to maintain a node's children, while the hash component contains the attributes of the node. In general we provide and use accessor methods for a node's attributes, instead of accessing the hash component directly.

Every PAST/POST node has name, source, and pos attributes. The name attribute is the node's name, if any, while source and pos are used to identify the location in the original source code for the node. The source and pos values are generally set by the node method below.

Other node attributes are generally defined by subclasses of PCT::Node.

init([child1, child2, ..., ] [attr1=>val1, attr2=>val2, ... ])

Initialize a node with the given children and attributes. Adds each child to the node (using the push method, below) and calls the appropriate accessor method for each attribute. And returns the node.

new([child1, child2, ..., ] [attr1=>val1, attr2=>val2, ...])

Create a new PAST node of initialized with the given children and attributes. Returns the newly created node.


Create and returns a clone of a PAST node.


Add child to the beginning of the invocant's list of children.


Remove the first child from the invocant's list of children. Returns the child.


Add child to the end of the invocant's list of children.


Remove the last child from the invocant's list of children. Returns the child.

push_new(class, [child1, child2, ..., ] [attr1=>val1, attr2=>val2, ...])

(Deprecated.) Creates a new node of type class, initializes it with the given children and attributes, and adds it to the end of the invocant's array of children. Returns the newly created node.

iterator( )

Returns a newly initialized iterator for the invocant's list of children.


Sets the invocant's source and pos attributes to those of val. If val is another PAST node, then source and pos are simply copied from that node, otherwise val is assumed to be a Match object and obtains source/position information from that.


Accessor method -- sets/returns the name attribute of the invocant.

attr(STR attrname, PMC value, INT has_value)

Helper method for accessors. If has_value is true then set the invocant's value of attrname to value. Returns the (resulting) value of attrname in the invocant.

unique([STR fmt])

Generate a unique number that can be used as an identifier. If fmt is provided, then it will be used as a prefix to the unique number.


Patrick Michaud <> is the author and maintainer. Please send patches and suggestions to the Parrot porters or Perl 6 compilers mailing lists.


2006-11-20 Patrick Michaud added first draft of POD documentation. 2007-11-21 Re-implementation with pdd26 compliance, compiler toolkit 2007-12-07 Refactor PAST::Node into separate PCT::Node component.


Copyright (C) 2006-2008, The Perl Foundation.