def generate_rules(grammar)
      rules        = []
      action_index = 0
      rule_indices = grammar.rule_indices
      term_indices = grammar.terminal_indices

      grammar.rules.each_with_index do |rule, rule_index|
        rule.branches.each do |branch|
          row = [TYPES[:action], action_index]

          action_index += 1

          branch.steps.reverse_each do |step|
            if step.is_a?(Terminal)
              row << TYPES[:terminal]
              row << term_indices[step] + 1

            elsif step.is_a?(Rule)
              row << TYPES[:rule]
              row << rule_indices[step]

            elsif step.is_a?(Epsilon)
              row << TYPES[:epsilon]
              row << 0

            elsif step.is_a?(Operator)
              row << TYPES[step.type]
              row << rule_indices[step.receiver]

              unless SKIP_VALUE_STACK.include?(step.type)
                row << TYPES[:add_value_stack]
                row << 0
              end
            end
          end

          rules << row
        end
      end

      return rules
    end
def generate_rules(grammar)
      rules        = []
      action_index = 0
      rule_indices = grammar.rule_indices
      term_indices = grammar.terminal_indices

      grammar.rules.each_with_index do |rule, rule_index|
        rule.branches.each do |branch|
          row = [TYPES[:action], action_index]

          action_index += 1

          branch.steps.reverse_each do |step|
            if step.is_a?(Terminal)
              row << TYPES[:terminal]
              row << term_indices[step] + 1

            elsif step.is_a?(Rule)
              row << TYPES[:rule]
              row << rule_indices[step]

            elsif step.is_a?(Epsilon)
              row << TYPES[:epsilon]
              row << 0

            elsif step.is_a?(Operator)
              row << TYPES[step.type]
              row << rule_indices[step.receiver]

              unless SKIP_VALUE_STACK.include?(step.type)
                row << TYPES[:add_value_stack]
                row << 0
              end
            end
          end

          rules << row
        end
      end

      return rules
    end
Builds the rules table of the parser. Each row is built in reverse order.

 @param [LL::CompiledGrammar] grammar
 @return [Array]