Class: Racc::State
Relationships & Source Files | |
Inherits: | Object |
Defined in: | lib/racc/state.rb |
Overview
A LALR state.
Class Method Summary
- .new(ident, core) ⇒ State constructor
Instance Attribute Summary
- #action readonly
- #closure readonly
- #conflict? ⇒ Boolean readonly
- #core readonly
-
#defact
rw
default action.
- #goto_table readonly
- #gotos readonly
-
#hash
readonly
Alias for #ident.
- #ident (also: #stateid, #hash) readonly
- #la=(la) writeonly
- #ritems readonly
- #rrconf readonly
- #rrules readonly
- #srconf readonly
-
#stateid
readonly
Alias for #ident.
- #stokens readonly
Instance Method Summary
- #==(oth) (also: #eql?)
- #check_la(la_rules)
-
#eql?(oth)
Alias for #==.
- #inspect (also: #to_s)
- #make_closure(core)
- #n_rrconflicts
- #n_srconflicts
- #rr_conflict(high, low, ctok)
- #rruleid(rule)
- #sr_conflict(shift, reduce)
-
#to_s
Alias for #inspect.
Constructor Details
.new(ident, core) ⇒ State
# 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 (readonly)
[ GitHub ]# File 'lib/racc/state.rb', line 642
attr_reader :action
#closure (readonly)
[ GitHub ]# File 'lib/racc/state.rb', line 633
attr_reader :closure
#conflict? ⇒ Boolean
(readonly)
[ GitHub ]
# File 'lib/racc/state.rb', line 705
def conflict? @conflict end
#core (readonly)
[ GitHub ]# File 'lib/racc/state.rb', line 632
attr_reader :core
#defact (rw)
default action
# File 'lib/racc/state.rb', line 643
attr_accessor :defact # default action
#goto_table (readonly)
[ GitHub ]# File 'lib/racc/state.rb', line 635
attr_reader :goto_table
#gotos (readonly)
[ GitHub ]# File 'lib/racc/state.rb', line 636
attr_reader :gotos
#hash (readonly)
Alias for #ident.
# File 'lib/racc/state.rb', line 630
alias hash ident
#ident (readonly) Also known as: #stateid, #hash
[ GitHub ]# File 'lib/racc/state.rb', line 628
attr_reader :ident
#la=(la) (writeonly)
[ GitHub ]#ritems (readonly)
[ GitHub ]# File 'lib/racc/state.rb', line 639
attr_reader :ritems
#rrconf (readonly)
[ GitHub ]# File 'lib/racc/state.rb', line 645
attr_reader :rrconf
#rrules (readonly)
[ GitHub ]# File 'lib/racc/state.rb', line 640
attr_reader :rrules
#srconf (readonly)
[ GitHub ]# File 'lib/racc/state.rb', line 646
attr_reader :srconf
#stateid (readonly)
Alias for #ident.
# File 'lib/racc/state.rb', line 629
alias stateid ident
#stokens (readonly)
[ GitHub ]# File 'lib/racc/state.rb', line 638
attr_reader :stokens
Instance Method Details
#==(oth) Also known as: #eql?
[ GitHub ]# File 'lib/racc/state.rb', line 654
def ==(oth) @ident == oth.ident end
#check_la(la_rules)
[ GitHub ]# 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
#eql?(oth)
Alias for #==.
# File 'lib/racc/state.rb', line 658
alias eql? ==
#inspect Also known as: #to_s
[ GitHub ]# File 'lib/racc/state.rb', line 648
def inspect "<state #{@ident}>" end
#make_closure(core)
[ GitHub ]#n_rrconflicts
[ GitHub ]# File 'lib/racc/state.rb', line 758
def n_rrconflicts @rrconf ? @rrconf.size : 0 end
#n_srconflicts
[ GitHub ]# File 'lib/racc/state.rb', line 754
def n_srconflicts @srconf ? @srconf.size : 0 end
#rr_conflict(high, low, ctok)
[ GitHub ]# 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)
[ GitHub ]# 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)
[ GitHub ]# 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
#to_s
Alias for #inspect.
# File 'lib/racc/state.rb', line 652
alias to_s inspect