lib/rley/parser/earley_parser.rb in rley-0.2.15 vs lib/rley/parser/earley_parser.rb in rley-0.3.00

- old
+ new

@@ -1,32 +1,20 @@ -require_relative '../syntax/grammar' -require_relative 'grm_items_builder' # Use mix-in module -require_relative 'parse_tracer' -require_relative 'parsing' +require_relative 'base_parser' module Rley # This module is used as a namespace module Parser # This module is used as a namespace # Implementation of a parser that uses the Earley parsing algorithm. - class EarleyParser - include GrmItemsBuilder # Mix-in module for created dotted items of given grammar - - # The grammar of the language. - attr_reader(:grammar) - - # The dotted items/rules for the productions of the grammar - attr_reader(:dotted_items) - + class EarleyParser < BaseParser # A Hash that defines the mapping: non-terminal => [start dotted items] attr_reader(:start_mapping) # A Hash that defines the mapping: dotted item => next dotted item # In other words, the 'next_mapping' allows to find the dotted item # after "advancing" the dot attr_reader(:next_mapping) def initialize(aGrammar) - @grammar = aGrammar - @dotted_items = build_dotted_items(grammar) # Method from mixin + super(aGrammar) @start_mapping = build_start_mapping(dotted_items) @next_mapping = build_next_mapping(dotted_items) end # Parse a sequence of input tokens.