5.3 Action Code

Each production can have action code associated with it. Action code is specified with a colon followed by a line of code or an indented block of code.

Actions associated with productions are not performed during parsing. Rather these functions can be called during a post-processing pass of the parse tree with the proctree function.

The action code is called with one argument named kids which is a list of right hand side elements. The value returned by the action code is associated with the production it belongs to. When the production is used in the right hand side of another production in the parse tree, its value will be passed in as an elements of the kids argument for that production's action code. See the API reference for more details.

If action code is not specified for a production, the default action is used. This action is simply return kids, which returns a list of the right hand side elements of the derivation. Some productions in the grammar are generated internally and have their own actions associated with them, as will be seen in the next section.

See the PyGgy Home Page.