Class Parser.LR.Rule

Description

This object is used to represent a BNF-rule in the LR parser.


Variable action

function(:void)|string|zero Parser.LR.Rule.action

Description

Action to do when reducing this rule. function - call this function. string - call this function by name in the object given to the parser. The function is called with arguments corresponding to the values of the elements of the rule. The return value of the function will be the value of this non-terminal. The default rule is to return the first argument.


Variable has_tokens

int Parser.LR.Rule.has_tokens

Description

This rule contains tokens


Variable nonterminal

int Parser.LR.Rule.nonterminal

Description

Non-terminal this rule reduces to.


Variable num_nonnullables

int Parser.LR.Rule.num_nonnullables

Description

This rule has this many non-nullable symbols at the moment.


Variable number

int Parser.LR.Rule.number

Description

Sequence number of this rule (used for conflict resolving) Also used to identify the rule.


Variable pri

Priority|zero Parser.LR.Rule.pri

Description

Priority and associativity of this rule.


Variable symbols

array(string|int) Parser.LR.Rule.symbols

Description

The actual rule


Method create

Parser.LR.Rule Parser.LR.Rule(int nt, array(string|int) r, function(:void)|string|void a)

Description

Create a BNF rule.

Example

The rule

rule : nonterminal ":" symbols ";" { add_rule };

might be created as

rule(4, ({ 9, ":", 5, ";" }), "add_rule");

where 4 corresponds to the nonterminal "rule", 9 to "nonterminal" and 5 to "symbols", and the function "add_rule" is too be called when this rule is reduced.

Parameter nt

Non-terminal to reduce to.

Parameter r

Symbol sequence that reduces to nt.

Parameter a

Action to do when reducing according to this rule. function - Call this function. string - Call this function by name in the object given to the parser. The function is called with arguments corresponding to the values of the elements of the rule. The return value of the function will become the value of this non-terminal. The default rule is to return the first argument.