Class: Depager::LALR::ShiftReducePrinter

Inherits:
AdvancedParser show all
Defined in:
lib/depager/plugins/srp.rb

Constant Summary

Constants inherited from Parser

Parser::ACC

Instance Attribute Summary

Attributes inherited from AdvancedParser

#basis, #decorator_index

Instance Method Summary collapse

Methods inherited from AdvancedParser

#accept, #error, #initialize, #reduce, #shift

Methods inherited from Parser

#accept, #action_table, #defred_after_shift_table, #defred_table, #error, #goto_table, #int_to_nonterm, #int_to_term, #lex, #nonterm_to_int, #parse, #reduce, #reduce_table, #shift, #term_to_int

Constructor Details

This class inherits a constructor from Depager::LALR::AdvancedParser

Instance Method Details

#after_acceptObject



35
36
37
# File 'lib/depager/plugins/srp.rb', line 35

def after_accept
  warn "acc."
end

#after_errorObject



39
40
41
42
43
44
45
# File 'lib/depager/plugins/srp.rb', line 39

def after_error
  st = stack.last
  la = int_to_term[lookahead[0]]
  warn "LA:<#{la}> last_state:#{st}"
  warn "LINE:<#{basis.line}>"
  warn dumpstack(stack), "\n"
end

#after_reduceObject



26
27
28
29
30
31
32
33
# File 'lib/depager/plugins/srp.rb', line 26

def after_reduce
  st = stack.last
  re = int_to_nonterm[stack[stack.size - 2][0]]
  la = int_to_term[lookahead[0]]
  warn "LA:<#{la}> reduce:<#{re}> state: ->#{st}"
  warn "LINE:<#{basis.line}>"
  warn dumpstack(stack), "\n"
end

#after_shiftObject



16
17
18
19
20
21
22
23
24
# File 'lib/depager/plugins/srp.rb', line 16

def after_shift
  st0 = stack[stack.size - 3]
  st = stack.last
  sh = int_to_term[stack[stack.size - 2][0]]
  la = int_to_term[lookahead[0]]
  warn "LA:<#{la}> shift:<#{sh}> state:#{st0}->#{st}"
  warn "LINE:<#{basis.line}>"
  warn dumpstack(stack), "\n"
end

#dumpstack(stack) ⇒ Object



2
3
4
5
6
7
8
9
10
11
12
13
14
# File 'lib/depager/plugins/srp.rb', line 2

def dumpstack(stack)
  stack.map.with_index do |v, x|
    if x.even?
      "(#{v})"
    elsif v[1] == :NT
      "#{int_to_nonterm[v[0]]}:#{v[1..].inspect}"
    elsif int_to_term[v[0]].instance_of?(String)
      "'#{int_to_term[v[0]]}':#{v[1..].inspect}"
    else
      "#{int_to_term[v[0]]}:#{v[1..].inspect}"
    end
  end.join(" ")
end