Class: Rley::Parser::GFGEarleyParser
- Inherits:
-
Base::BaseParser
- Object
- Base::BaseParser
- Rley::Parser::GFGEarleyParser
- Defined in:
- lib/rley/parser/gfg_earley_parser.rb
Overview
Implementation of a parser that uses the Earley parsing algorithm.
Instance Attribute Summary collapse
-
#gf_graph ⇒ GFG::GrmFlowGraph
readonly
The Grammar Flow graph generated from the provided grammar.
Attributes inherited from Base::BaseParser
Instance Method Summary collapse
-
#initialize(aGrammar) ⇒ GFGEarleyParser
constructor
Constructor.
-
#parse(aTokenSequence) ⇒ GFGParsing
Parse a sequence of input tokens.
Methods included from Base::GrmItemsBuilder
Constructor Details
#initialize(aGrammar) ⇒ GFGEarleyParser
Constructor.
17 18 19 20 |
# File 'lib/rley/parser/gfg_earley_parser.rb', line 17 def initialize(aGrammar) super(aGrammar) @gf_graph = GFG::GrmFlowGraph.new(dotted_items) end |
Instance Attribute Details
#gf_graph ⇒ GFG::GrmFlowGraph (readonly)
The Grammar Flow graph generated from the provided grammar.
13 14 15 |
# File 'lib/rley/parser/gfg_earley_parser.rb', line 13 def gf_graph @gf_graph end |
Instance Method Details
#parse(aTokenSequence) ⇒ GFGParsing
Parse a sequence of input tokens. tokenizer/scanner/lexer.
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/rley/parser/gfg_earley_parser.rb', line 26 def parse(aTokenSequence) result = GFGParsing.new(gf_graph) token_count = aTokenSequence.size if token_count.zero? && !grammar.start_symbol.nullable? return unexpected_empty_input(result) end aTokenSequence.each_with_index do |token, i| parse_for_token(result, i) if token.terminal.kind_of?(String) symb = grammar.name2symbol[token.terminal] token.instance_variable_set(:@terminal, symb) end scan_success = scan_rule(result, i, token) break unless scan_success end parse_for_token(result, token_count) unless result.failure_reason result.done # End of parsing process return result end |