Class: Racc::State

### Home Classes Methods

### In Files

- lib/racc/state.rb

### Parent

Object

### Methods

- ::new
- #==
- #check_la
- #conflict?
- #eql?
- #inspect
- #la=
- #make_closure
- #n_rrconflicts
- #n_srconflicts
- #rr_conflict
- #rruleid
- #sr_conflict
- #to_s

### Files

- Manifest.txt
- README.rdoc
- pre-setup
- NEWS.en.rdoc
- grammar.en.rdoc

### Class/Module Index

Quicksearch

- Racc
- Racc::Accept
- Racc::ActionTable
- Racc::CompileError
- Racc::DebugFlags
- Racc::Error
- Racc::Goto
- Racc::Grammar
- Racc::Grammar::DefinitionEnv
- Racc::Grammar::PrecedenceDefinitionEnv
- Racc::GrammarFileParser
- Racc::GrammarFileParser::Result
- Racc::GrammarFileScanner
- Racc::ISet
- Racc::Item
- Racc::LocationPointer
- Racc::LogFileGenerator
- Racc::OrMark
- Racc::ParseError
- Racc::ParseError
- Racc::Parser
- Racc::ParserClassGenerator
- Racc::ParserFileGenerator
- Racc::ParserFileGenerator::Params
- Racc::Prec
- Racc::RRconflict
- Racc::Reduce
- Racc::Rule
- Racc::SRconflict
- Racc::Shift
- Racc::SourceText
- Racc::State
- Racc::StateTransitionTable
- Racc::StateTransitionTableGenerator
- Racc::States
- Racc::Sym
- Racc::SymbolTable
- Racc::UserAction
- Object
- Object::ParseError
- Array

No matching classes.

# Racc::State

A LALR state.

### Attributes

action[R]
closure[R]
core[R]
defact[RW]
goto_table[R]
gotos[R]
hash[R]
ident[R]
ritems[R]
rrconf[R]
rrules[R]
srconf[R]
stateid[R]
stokens[R]

### Public Class Methods

new(ident, core) click to toggle source

    # File lib/racc/state.rb, line 608
    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

### Public Instance Methods

==(oth) click to toggle source

    # File lib/racc/state.rb, line 649
    def ==(oth)
      @ident == oth.ident
    end

Also aliased as: eql?
check_la(la_rules) click to toggle source

    # File lib/racc/state.rb, line 666
    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?() click to toggle source

    # File lib/racc/state.rb, line 700
    def conflict?
      @conflict
    end

eql?(oth) click to toggle source
Alias for: ==
inspect() click to toggle source

    # File lib/racc/state.rb, line 643
    def inspect
      "<state #{@ident}>"
    end

Also aliased as: to_s
la=(la) click to toggle source

    # File lib/racc/state.rb, line 717
    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) click to toggle source

    # File lib/racc/state.rb, line 655
    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.expand
        end
      end
      set.to_a
    end

n_rrconflicts() click to toggle source

    # File lib/racc/state.rb, line 753
    def n_rrconflicts
      @rrconf ? @rrconf.size : 0
    end

n_srconflicts() click to toggle source

    # File lib/racc/state.rb, line 749
    def n_srconflicts
      @srconf ? @srconf.size : 0
    end

rr_conflict(high, low, ctok) click to toggle source

    # File lib/racc/state.rb, line 727
    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) click to toggle source

    # File lib/racc/state.rb, line 704
    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) click to toggle source

    # File lib/racc/state.rb, line 738
    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() click to toggle source
Alias for: inspect

[Validate]

Generated with the Darkfish Rdoc Generator 2.