Class: Aurum::ParsingTableGenerator::State
- Inherits:
-
Array
- Object
- Array
- Aurum::ParsingTableGenerator::State
- Defined in:
- lib/aurum/parsing_table_generator.rb
Instance Attribute Summary collapse
-
#actions ⇒ Object
readonly
Returns the value of attribute actions.
-
#direct_read ⇒ Object
readonly
Returns the value of attribute direct_read.
-
#handles ⇒ Object
readonly
Returns the value of attribute handles.
-
#kernels ⇒ Object
readonly
Returns the value of attribute kernels.
-
#non_handles ⇒ Object
readonly
Returns the value of attribute non_handles.
-
#read_reduce ⇒ Object
readonly
Returns the value of attribute read_reduce.
Instance Method Summary collapse
- #==(other) ⇒ Object
- #[](symbol) ⇒ Object
- #conflict? ⇒ Boolean
- #conflicted_actions ⇒ Object
- #goto(symbol) ⇒ Object
- #inconsistent? ⇒ Boolean
-
#initialize(elements) ⇒ State
constructor
A new instance of State.
- #only_shift?(symbol) ⇒ Boolean
- #predsucceors(symbols = nil) ⇒ Object
Constructor Details
#initialize(elements) ⇒ State
Returns a new instance of State.
391 392 393 394 395 396 397 398 399 400 401 |
# File 'lib/aurum/parsing_table_generator.rb', line 391 def initialize elements super elements @actions, @predsucceors, @read_reduce = {}, [], nil @handles, @non_handles, @kernels, @direct_read = [], [], [], [].to_set for item in elements (item.is_handle ? @handles : @non_handles) << item @kernels << item if item.is_kernel @direct_read << item.dot_symbol if item.dot_symbol end @read_reduce = first.production if size == 1 && first.is_handle end |
Instance Attribute Details
#actions ⇒ Object (readonly)
Returns the value of attribute actions.
390 391 392 |
# File 'lib/aurum/parsing_table_generator.rb', line 390 def actions @actions end |
#direct_read ⇒ Object (readonly)
Returns the value of attribute direct_read.
390 391 392 |
# File 'lib/aurum/parsing_table_generator.rb', line 390 def direct_read @direct_read end |
#handles ⇒ Object (readonly)
Returns the value of attribute handles.
390 391 392 |
# File 'lib/aurum/parsing_table_generator.rb', line 390 def handles @handles end |
#kernels ⇒ Object (readonly)
Returns the value of attribute kernels.
390 391 392 |
# File 'lib/aurum/parsing_table_generator.rb', line 390 def kernels @kernels end |
#non_handles ⇒ Object (readonly)
Returns the value of attribute non_handles.
390 391 392 |
# File 'lib/aurum/parsing_table_generator.rb', line 390 def non_handles @non_handles end |
#read_reduce ⇒ Object (readonly)
Returns the value of attribute read_reduce.
390 391 392 |
# File 'lib/aurum/parsing_table_generator.rb', line 390 def read_reduce @read_reduce end |
Instance Method Details
#==(other) ⇒ Object
442 443 444 445 446 |
# File 'lib/aurum/parsing_table_generator.rb', line 442 def == other return false unless other.kind_of?(State) && (@kernels.size == other.kernels.size) return true if equal? other @kernels.all? {|x| other.kernels.include? x} end |
#[](symbol) ⇒ Object
403 404 405 406 |
# File 'lib/aurum/parsing_table_generator.rb', line 403 def [] symbol @actions[symbol] = Set.new([]) unless @actions.has_key? symbol @actions[symbol] end |
#conflict? ⇒ Boolean
412 413 414 |
# File 'lib/aurum/parsing_table_generator.rb', line 412 def conflict? inconsistent? && @actions.any? {|symbol, actions| actions.length > 1} end |
#conflicted_actions ⇒ Object
416 417 418 |
# File 'lib/aurum/parsing_table_generator.rb', line 416 def conflicted_actions @actions.find_all {|symbol, actions| actions.length > 1} end |
#goto(symbol) ⇒ Object
424 425 426 427 |
# File 'lib/aurum/parsing_table_generator.rb', line 424 def goto symbol shift = self[symbol].find {|x| x.kind_of? Aurum::ShiftAction } shift.state if shift end |
#inconsistent? ⇒ Boolean
408 409 410 |
# File 'lib/aurum/parsing_table_generator.rb', line 408 def inconsistent? @handles.size > 1 || (@handles.size == 1 && @kernels.size != 1) end |
#only_shift?(symbol) ⇒ Boolean
420 421 422 |
# File 'lib/aurum/parsing_table_generator.rb', line 420 def only_shift? symbol !self[symbol].empty? && @actions[symbol].all? {|x| x.kind_of? ShiftAction} end |
#predsucceors(symbols = nil) ⇒ Object
429 430 431 432 433 434 435 436 437 438 439 440 |
# File 'lib/aurum/parsing_table_generator.rb', line 429 def predsucceors(symbols = nil) symbols or return @predsucceors result = [self] for symbol in symbols new_result = [] for x in result new_result |= x.predsucceors.find_all {|predsucceor| predsucceor.any? {|item| item.dot_symbol == symbol}} end result.replace new_result end result end |