# File lib/racc/logfilegenerator.rb, line 92
92: def action_out(f, state)
93: r = ''
94: e = ''
95: sr = state.srconf && state.srconf.dup
96: rr = state.rrconf && state.rrconf.dup
97: acts = state.action
98: keys = acts.keys
99: keys.sort! {|a,b| a.ident <=> b.ident }
100:
101: [ Shift, Reduce, Error, Accept ].each do |klass|
102: keys.delete_if do |tok|
103: act = acts[tok]
104: if act.kind_of?(klass)
105: outact f, tok, act
106: if sr and c = sr.delete(tok)
107: outsrconf f, c
108: end
109: if rr and c = rr.delete(tok)
110: outrrconf f, c
111: end
112:
113: true
114: else
115: false
116: end
117: end
118: end
119: sr.each {|tok, c| outsrconf f, c } if sr
120: rr.each {|tok, c| outrrconf f, c } if rr
121:
122: act = state.defact
123: if not act.kind_of?(Error) or @debug_flags.any?
124: outact f, '$default', act
125: end
126:
127: f.puts
128: state.goto_table.each do |t, st|
129: if t.nonterminal?
130: f.printf " %-12s go to state %d\n", t.to_s, st.ident
131: end
132: end
133: end
# File lib/racc/logfilegenerator.rb, line 135
135: def outact(f, t, act)
136: case act
137: when Shift
138: f.printf " %-12s shift, and go to state %d\n",
139: t.to_s, act.goto_id
140: when Reduce
141: f.printf " %-12s reduce using rule %d (%s)\n",
142: t.to_s, act.ruleid, act.rule.target.to_s
143: when Accept
144: f.printf " %-12s accept\n", t.to_s
145: when Error
146: f.printf " %-12s error\n", t.to_s
147: else
148: raise "racc: fatal: wrong act for outact: act=#{act}(#{act.class})"
149: end
150: end
# File lib/racc/logfilegenerator.rb, line 22
22: def output(out)
23: output_conflict out; out.puts
24: output_useless out; out.puts
25: output_rule out; out.puts
26: output_token out; out.puts
27: output_state out
28: end
Warnings
# File lib/racc/logfilegenerator.rb, line 34
34: def output_conflict(out)
35: @states.each do |state|
36: if state.srconf
37: out.printf "state %d contains %d shift/reduce conflicts\n",
38: state.stateid, state.srconf.size
39: end
40: if state.rrconf
41: out.printf "state %d contains %d reduce/reduce conflicts\n",
42: state.stateid, state.rrconf.size
43: end
44: end
45: end
Rules
# File lib/racc/logfilegenerator.rb, line 172
172: def output_rule(out)
173: out.print "-------- Grammar --------\n\n"
174: @grammar.each do |rl|
175: if @debug_flags.any? or rl.ident != 0
176: out.printf "rule %d %s: %s\n",
177: rl.ident, rl.target.to_s, rl.symbols.join(' ')
178: end
179: end
180: end
# File lib/racc/logfilegenerator.rb, line 66
66: def output_state(out)
67: out << "--------- State ---------\n"
68:
69: showall = @debug_flags.la || @debug_flags.state
70: @states.each do |state|
71: out << "\nstate #{state.ident}\n\n"
72:
73: (showall ? state.closure : state.core).each do |ptr|
74: pointer_out(out, ptr) if ptr.rule.ident != 0 or showall
75: end
76: out << "\n"
77:
78: action_out out, state
79: end
80: end
Tokens
# File lib/racc/logfilegenerator.rb, line 186
186: def output_token(out)
187: out.print "------- Symbols -------\n\n"
188:
189: out.print "**Nonterminals, with rules where they appear\n\n"
190: @grammar.each_nonterminal do |t|
191: tmp = %s (%d) on right: %s on left : %s
192: out.printf tmp, t.to_s, t.ident,
193: symbol_locations(t.locate).join(' '),
194: symbol_locations(t.heads).join(' ')
195: end
196:
197: out.print "\n**Terminals, with rules where they appear\n\n"
198: @grammar.each_terminal do |t|
199: out.printf " %s (%d) %s\n",
200: t.to_s, t.ident, symbol_locations(t.locate).join(' ')
201: end
202: end
# File lib/racc/logfilegenerator.rb, line 47
47: def output_useless(out)
48: used = []
49: @grammar.each do |rl|
50: if rl.useless?
51: out.printf "rule %d (%s) never reduced\n",
52: rl.ident, rl.target.to_s
53: end
54: end
55: @grammar.each_nonterminal do |t|
56: if t.useless?
57: out.printf "useless nonterminal %s\n", t.to_s
58: end
59: end
60: end
# File lib/racc/logfilegenerator.rb, line 160
160: def outrrconf(f, confs)
161: confs.each do |c|
162: r = c.low_prec
163: f.printf " %-12s [reduce using rule %d (%s)]\n",
164: c.token.to_s, r.ident, r.target.to_s
165: end
166: end
# File lib/racc/logfilegenerator.rb, line 152
152: def outsrconf(f, confs)
153: confs.each do |c|
154: r = c.reduce
155: f.printf " %-12s [reduce using rule %d (%s)]\n",
156: c.shift.to_s, r.ident, r.target.to_s
157: end
158: end
# File lib/racc/logfilegenerator.rb, line 82
82: def pointer_out(out, ptr)
83: buf = sprintf("%4d) %s :", ptr.rule.ident, ptr.rule.target.to_s)
84: ptr.rule.symbols.each_with_index do |tok, idx|
85: buf << ' _' if idx == ptr.index
86: buf << ' ' << tok.to_s
87: end
88: buf << ' _' if ptr.reduce?
89: out.puts buf
90: end
Disabled; run with --debug to generate this.
Generated with the Darkfish Rdoc Generator 1.1.6.