Reduction Object

 

Description

When the parsing engine has read enough tokens to conclude a rule in the grammar is complete, it is 'reduced' and passed to the developer. Basically a 'reduction'  will contain the tokens which correspond to the symbols of the rule. Tokens can represent actual data read from the file (a.k.a. terminals), but also may contain objects as well. Since a reduction contains the terminals of a rule as well as the nonterminals (reductions made earlier), the parser engine creates a 'parse tree'   which contains a break down of the source text along the grammar's rules.

Essentially, when a reduction takes place, the GOLDParser object will respond with the gpMsgReduce message, create a new Reduction object, and then store it in the CurrentReduction property. This property can be read and then reassigned to another object if you decide to create your own objects. However, this is not required since the parse tree will be created using the produced Reduction.

The Reduction object is designed to be general purpose - able to store any rule, but at a cost. Since it is general purpose, there is additional overhead required that would not be needed in a specialized object. Invariably there will be numerous instances of the Reduction object, so it was was designed to use as little memory as possible while maintaining basic functionality.

 

Properties

Property Data Type Access Description
ParentRule Rule Read only Returns the reference of  the rule in the GOLDParser object's Rule Table that the Reduction represents.
TokenCount Integer (16-bit) Read only Returns the number of tokens that consist the body of the Reduction. This will always be equal to the number of symbols in the ParentRule.
Tokens (Index) Token Read only Returns one of the tokens that consist the body of the reduction. The index of the token ranges from 0 to TokenCount -1
Tag Integer (16-bit) Read/Write This is a general purpose field that can be used at the developer's leisure.

 

Methods

This object does not contain any methods.