Sha256: 3526c7cf4929243dd862aa8013ab6ff180fac57c9783a7cda4d0dc6931837b03

Contents?: true

Size: 1.11 KB

Versions: 27

Compression:

Stored size: 1.11 KB

Contents

require_relative 'state_set'
require_relative 'parse_state'

module Rley # This module is used as a namespace
  module Parser # This module is used as a namespace
    # Also called a parse table
    # A one-dimensional array with n + 1 entries (n = number of input tokens).
    class Chart
      attr_reader(:state_sets)

      def initialize(startDottedItem, tokenCount)
        @state_sets = Array.new(tokenCount + 1) { |_| StateSet.new }
        push_state(startDottedItem, 0, 0)
      end

      # The dotted item/rule used to seed the parse chart.
      # It corresponds to the start production and a dot placed
      # at the beginning of the rhs
      def start_dotted_rule()
        return self[0].states.first.dotted_rule
      end

      # Access the state set at given position
      def [](index)
        return state_sets[index]
      end

      # Push a parse state for the chart entry with given index
      def push_state(aDottedItem, anOrigin, anIndex)
        new_state = ParseState.new(aDottedItem, anOrigin)
        self[anIndex].push_state(new_state)
      end
    end # class
  end # module
end # module

# End of file

Version data entries

27 entries across 27 versions & 1 rubygems

Version Path
rley-0.1.12 lib/rley/parser/chart.rb
rley-0.1.11 lib/rley/parser/chart.rb
rley-0.1.10 lib/rley/parser/chart.rb
rley-0.1.09 lib/rley/parser/chart.rb
rley-0.1.08 lib/rley/parser/chart.rb
rley-0.1.07 lib/rley/parser/chart.rb
rley-0.1.06 lib/rley/parser/chart.rb
rley-0.1.05 lib/rley/parser/chart.rb
rley-0.1.04 lib/rley/parser/chart.rb
rley-0.1.03 lib/rley/parser/chart.rb
rley-0.1.02 lib/rley/parser/chart.rb
rley-0.1.01 lib/rley/parser/chart.rb
rley-0.1.00 lib/rley/parser/chart.rb
rley-0.0.18 lib/rley/parser/chart.rb
rley-0.0.17 lib/rley/parser/chart.rb
rley-0.0.16 lib/rley/parser/chart.rb
rley-0.0.15 lib/rley/parser/chart.rb
rley-0.0.14 lib/rley/parser/chart.rb
rley-0.0.13 lib/rley/parser/chart.rb
rley-0.0.12 lib/rley/parser/chart.rb