P6C::Tree ^

Post-process the parse tree into the form used by the rest of the compiler. This is faster than making a neat parse tree directly. Each parse tree node class (i.e. grammar rule) should define a tree function that takes a raw parse tree node, and returns a processed one. Both of these objects are blessed into the same class (don't call tree on a processed node, or val on a raw one, or bad things will happen). See Nodes.pm for descriptions of the various nodes -- there's mostly a one-to-one correspondence between them and the grammar rules, but a few of the rules that got inlined away reappear as node types, while some of the lower-level rules are not preserved.

Remember to update the appropriate tree function here if you change the grammar. The functions here appear in roughly the same order as the grammar rules in Parser.pm.

Parse tree handling utilities ^

infix_right_seq($seq)

Turn the list output from a rightop directive into a binary tree in the proper order.

infix_left_seq($seq)

Same for a leftop directive

maybe_tree($node)

Call tree on $node if appropriate. Useful for handling optional items and rules with empty alternations.

flatten_list($node)

Turn a leftop or rightop list into a list of parse tree nodes by calling tree on each of its elements.


parrot