Class: Racc::State
Overview
A LALR state.
Instance Attribute Summary collapse
-
#action ⇒ Object
readonly
Returns the value of attribute action.
-
#closure ⇒ Object
readonly
Returns the value of attribute closure.
-
#core ⇒ Object
readonly
Returns the value of attribute core.
-
#defact ⇒ Object
default action.
-
#goto_table ⇒ Object
readonly
Returns the value of attribute goto_table.
-
#gotos ⇒ Object
readonly
Returns the value of attribute gotos.
-
#ident ⇒ Object
(also: #stateid, #hash)
readonly
Returns the value of attribute ident.
-
#ritems ⇒ Object
readonly
Returns the value of attribute ritems.
-
#rrconf ⇒ Object
readonly
Returns the value of attribute rrconf.
-
#rrules ⇒ Object
readonly
Returns the value of attribute rrules.
-
#srconf ⇒ Object
readonly
Returns the value of attribute srconf.
-
#stokens ⇒ Object
readonly
Returns the value of attribute stokens.
Instance Method Summary collapse
- #==(oth) ⇒ Object (also: #eql?)
- #check_la(la_rules) ⇒ Object
- #conflict? ⇒ Boolean
-
#initialize(ident, core) ⇒ State
constructor
A new instance of State.
- #inspect ⇒ Object (also: #to_s)
- #la=(la) ⇒ Object
- #make_closure(core) ⇒ Object
- #n_rrconflicts ⇒ Object
- #n_srconflicts ⇒ Object
- #rr_conflict(high, low, ctok) ⇒ Object
- #rruleid(rule) ⇒ Object
- #sr_conflict(shift, reduce) ⇒ Object
Constructor Details
#initialize(ident, core) ⇒ State
Returns a new instance of State.
613 614 615 616 617 618 619 620 621 622 623 624 625 626 |
# File 'lib/racc/state.rb', line 613 def initialize(ident, core) @ident = ident @core = core @goto_table = {} @gotos = {} @stokens = nil @ritems = nil @action = {} @defact = nil @rrconf = nil @srconf = nil @closure = make_closure(@core) end |
Instance Attribute Details
#action ⇒ Object (readonly)
Returns the value of attribute action.
642 643 644 |
# File 'lib/racc/state.rb', line 642 def action @action end |
#closure ⇒ Object (readonly)
Returns the value of attribute closure.
633 634 635 |
# File 'lib/racc/state.rb', line 633 def closure @closure end |
#core ⇒ Object (readonly)
Returns the value of attribute core.
632 633 634 |
# File 'lib/racc/state.rb', line 632 def core @core end |
#defact ⇒ Object
default action
643 644 645 |
# File 'lib/racc/state.rb', line 643 def defact @defact end |
#goto_table ⇒ Object (readonly)
Returns the value of attribute goto_table.
635 636 637 |
# File 'lib/racc/state.rb', line 635 def goto_table @goto_table end |
#gotos ⇒ Object (readonly)
Returns the value of attribute gotos.
636 637 638 |
# File 'lib/racc/state.rb', line 636 def gotos @gotos end |
#ident ⇒ Object (readonly) Also known as: stateid, hash
Returns the value of attribute ident.
628 629 630 |
# File 'lib/racc/state.rb', line 628 def ident @ident end |
#ritems ⇒ Object (readonly)
Returns the value of attribute ritems.
639 640 641 |
# File 'lib/racc/state.rb', line 639 def ritems @ritems end |
#rrconf ⇒ Object (readonly)
Returns the value of attribute rrconf.
645 646 647 |
# File 'lib/racc/state.rb', line 645 def rrconf @rrconf end |
#rrules ⇒ Object (readonly)
Returns the value of attribute rrules.
640 641 642 |
# File 'lib/racc/state.rb', line 640 def rrules @rrules end |
#srconf ⇒ Object (readonly)
Returns the value of attribute srconf.
646 647 648 |
# File 'lib/racc/state.rb', line 646 def srconf @srconf end |
#stokens ⇒ Object (readonly)
Returns the value of attribute stokens.
638 639 640 |
# File 'lib/racc/state.rb', line 638 def stokens @stokens end |
Instance Method Details
#==(oth) ⇒ Object Also known as: eql?
654 655 656 |
# File 'lib/racc/state.rb', line 654 def ==(oth) @ident == oth.ident end |
#check_la(la_rules) ⇒ Object
671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 |
# File 'lib/racc/state.rb', line 671 def check_la(la_rules) @conflict = false s = [] r = [] @closure.each do |ptr| if t = ptr.dereference if t.terminal? s[t.ident] = t if t.ident == 1 # $error @conflict = true end end else r.push ptr.rule end end unless r.empty? if not s.empty? or r.size > 1 @conflict = true end end s.compact! @stokens = s @rrules = r if @conflict @la_rules_i = la_rules.size @la_rules = r.map {|i| i.ident } la_rules.concat r else @la_rules_i = @la_rules = nil end end |
#conflict? ⇒ Boolean
705 706 707 |
# File 'lib/racc/state.rb', line 705 def conflict? @conflict end |
#inspect ⇒ Object Also known as: to_s
648 649 650 |
# File 'lib/racc/state.rb', line 648 def inspect "<state #{@ident}>" end |
#la=(la) ⇒ Object
722 723 724 725 726 727 728 729 730 |
# File 'lib/racc/state.rb', line 722 def la=(la) return unless @conflict i = @la_rules_i @ritems = r = [] @rrules.each do |rule| r.push Item.new(rule, la[i]) i += 1 end end |
#make_closure(core) ⇒ Object
660 661 662 663 664 665 666 667 668 669 |
# File 'lib/racc/state.rb', line 660 def make_closure(core) set = ISet.new core.each do |ptr| set.add ptr if t = ptr.dereference and t.nonterminal? set.update_a t. end end set.to_a end |
#n_rrconflicts ⇒ Object
758 759 760 |
# File 'lib/racc/state.rb', line 758 def n_rrconflicts @rrconf ? @rrconf.size : 0 end |
#n_srconflicts ⇒ Object
754 755 756 |
# File 'lib/racc/state.rb', line 754 def n_srconflicts @srconf ? @srconf.size : 0 end |
#rr_conflict(high, low, ctok) ⇒ Object
732 733 734 735 736 737 738 739 740 741 |
# File 'lib/racc/state.rb', line 732 def rr_conflict(high, low, ctok) c = RRconflict.new(@ident, high, low, ctok) @rrconf ||= {} if a = @rrconf[ctok] a.push c else @rrconf[ctok] = [c] end end |
#rruleid(rule) ⇒ Object
709 710 711 712 713 714 715 716 717 718 719 720 |
# File 'lib/racc/state.rb', line 709 def rruleid(rule) if i = @la_rules.index(rule.ident) @la_rules_i + i else puts '/// rruleid' p self p rule p @rrules p @la_rules_i raise 'racc: fatal: cannot get reduce rule id' end end |
#sr_conflict(shift, reduce) ⇒ Object
743 744 745 746 747 748 749 750 751 752 |
# File 'lib/racc/state.rb', line 743 def sr_conflict(shift, reduce) c = SRconflict.new(@ident, shift, reduce) @srconf ||= {} if a = @srconf[shift] a.push c else @srconf[shift] = [c] end end |