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.
606 607 608 609 610 611 612 613 614 615 616 617 618 619 |
# File 'lib/racc/state.rb', line 606 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.
635 636 637 |
# File 'lib/racc/state.rb', line 635 def action @action end |
#closure ⇒ Object (readonly)
Returns the value of attribute closure.
626 627 628 |
# File 'lib/racc/state.rb', line 626 def closure @closure end |
#core ⇒ Object (readonly)
Returns the value of attribute core.
625 626 627 |
# File 'lib/racc/state.rb', line 625 def core @core end |
#defact ⇒ Object
default action
636 637 638 |
# File 'lib/racc/state.rb', line 636 def defact @defact end |
#goto_table ⇒ Object (readonly)
Returns the value of attribute goto_table.
628 629 630 |
# File 'lib/racc/state.rb', line 628 def goto_table @goto_table end |
#gotos ⇒ Object (readonly)
Returns the value of attribute gotos.
629 630 631 |
# File 'lib/racc/state.rb', line 629 def gotos @gotos end |
#ident ⇒ Object (readonly) Also known as: stateid, hash
Returns the value of attribute ident.
621 622 623 |
# File 'lib/racc/state.rb', line 621 def ident @ident end |
#ritems ⇒ Object (readonly)
Returns the value of attribute ritems.
632 633 634 |
# File 'lib/racc/state.rb', line 632 def ritems @ritems end |
#rrconf ⇒ Object (readonly)
Returns the value of attribute rrconf.
638 639 640 |
# File 'lib/racc/state.rb', line 638 def rrconf @rrconf end |
#rrules ⇒ Object (readonly)
Returns the value of attribute rrules.
633 634 635 |
# File 'lib/racc/state.rb', line 633 def rrules @rrules end |
#srconf ⇒ Object (readonly)
Returns the value of attribute srconf.
639 640 641 |
# File 'lib/racc/state.rb', line 639 def srconf @srconf end |
#stokens ⇒ Object (readonly)
Returns the value of attribute stokens.
631 632 633 |
# File 'lib/racc/state.rb', line 631 def stokens @stokens end |
Instance Method Details
#==(oth) ⇒ Object Also known as: eql?
647 648 649 |
# File 'lib/racc/state.rb', line 647 def ==(oth) @ident == oth.ident end |
#check_la(la_rules) ⇒ Object
664 665 666 667 668 669 670 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 |
# File 'lib/racc/state.rb', line 664 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
698 699 700 |
# File 'lib/racc/state.rb', line 698 def conflict? @conflict end |
#inspect ⇒ Object Also known as: to_s
641 642 643 |
# File 'lib/racc/state.rb', line 641 def inspect "<state #{@ident}>" end |
#la=(la) ⇒ Object
715 716 717 718 719 720 721 722 723 |
# File 'lib/racc/state.rb', line 715 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
653 654 655 656 657 658 659 660 661 662 |
# File 'lib/racc/state.rb', line 653 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
751 752 753 |
# File 'lib/racc/state.rb', line 751 def n_rrconflicts @rrconf ? @rrconf.size : 0 end |
#n_srconflicts ⇒ Object
747 748 749 |
# File 'lib/racc/state.rb', line 747 def n_srconflicts @srconf ? @srconf.size : 0 end |
#rr_conflict(high, low, ctok) ⇒ Object
725 726 727 728 729 730 731 732 733 734 |
# File 'lib/racc/state.rb', line 725 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
702 703 704 705 706 707 708 709 710 711 712 713 |
# File 'lib/racc/state.rb', line 702 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
736 737 738 739 740 741 742 743 744 745 |
# File 'lib/racc/state.rb', line 736 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 |