def generate_table(grammar)
      branch_index = 0
      term_indices = grammar.terminal_indices
      columns      = grammar.terminals.length + 1

      table = Array.new(grammar.rules.length) do
        Array.new(columns, -1)
      end

      grammar.rules.each_with_index do |rule, rule_index|
        rule.branches.each do |branch|
          branch.first_set.each do |step|
            # For terminals we'll base the column index on the terminal index.
            if step.is_a?(Terminal)
              terminal_index = term_indices[step]

              table[rule_index][terminal_index + 1] = branch_index

            # For the rest (= epsilon) we'll update all columns that haven't
            # been updated yet.
            else
              table[rule_index].each_with_index do |col, col_index|
                table[rule_index][col_index] = branch_index if col == -1
              end
            end
          end

          branch_index += 1
        end
      end

      return table
    end
def generate_table(grammar)
      branch_index = 0
      term_indices = grammar.terminal_indices
      columns      = grammar.terminals.length + 1

      table = Array.new(grammar.rules.length) do
        Array.new(columns, -1)
      end

      grammar.rules.each_with_index do |rule, rule_index|
        rule.branches.each do |branch|
          branch.first_set.each do |step|
            # For terminals we'll base the column index on the terminal index.
            if step.is_a?(Terminal)
              terminal_index = term_indices[step]

              table[rule_index][terminal_index + 1] = branch_index

            # For the rest (= epsilon) we'll update all columns that haven't
            # been updated yet.
            else
              table[rule_index].each_with_index do |col, col_index|
                table[rule_index][col_index] = branch_index if col == -1
              end
            end
          end

          branch_index += 1
        end
      end

      return table
    end
Generates the table array for the parser. This array has the following
 structure:

     [
       [EOF, TERMINAL 1, TERMINAL 2, TERMINAL 3, ...]
     ]

 EOF is always the first column and is used when running out of input while
 processing a rule.

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