bootstrap/peg_cbyte.rb
# note: a simpler implementation might create an intermediate parent for each child
a simpler implementation might create an intermediate parent for each child
a simpler implementation might create an intermediate parent for each child
def output_parse(out)
                    out.c.puts "\n// BEGIN #{self.inspect}"
                    out.c.puts "case #{@parse_state}:"
                    out.c.indent += 1
                    out.c.puts "if (top >= self->max_stack_size - 3) return -5;"
                    out.c.puts "stack[++top] = tree_stack[tree_top]->num_children; // num_children - backtrack point"
                    out.c.puts "stack[++top] = offset; // save offset for backtrack"
                    out.c.indent -= 1
                    @data.each do |c|
                        c.output_parse(out)
                        out.c.puts "\n// CSUCC #{c.inspect}"
                        out.c.puts "case #{@child_succ_states[c]}:"
                        out.c.indent += 1
                        out.c.puts "top -= 2;"
                        out.c.puts "state = #{@parent.next_state(self)}; continue;"
                        out.c.indent -= 1
                        out.c.puts "\n// CFAIL #{c.inspect}"
                        out.c.puts "case #{@child_fail_states[c]}:"
                        out.c.indent += 1
                        out.c.puts "offset = stack[top]; // restore saved offset (backtrack)"
                        out.c.puts "for (int i = tree_stack[tree_top]->num_children - stack[top-1]; i > 0; --i) " +
                            "{ Node_pop_child(tree_stack[tree_top]); }"
                        out.c.puts "// pass through"
                        out.c.indent -= 1
                    end
                    out.c.puts "\n// FAIL  #{self.inspect}"
                    out.c.puts "case #{@failure_state}:"
                    out.c.indent += 1
                    out.c.puts "top -= 2;"
                    out.c.puts "state = #{@parent.fail_state(self)}; continue;"
                    out.c.indent -= 1
                    out.c.puts "\n// END   #{self.inspect}"
                end
def output_parse ( out ) out . c . puts "\n// BEGIN #{self.inspect}" out . c . puts "case #{@parse_state}:" out . c . indent += 1 out . c . puts "if (top >= self->max_stack_size - 3) return -5;" out . c . puts "stack[++top] = tree_stack[tree_top]->num_children; // num_children - backtrack point" out . c . puts "stack[++top] = offset; // save offset for backtrack" out . c . indent -= 1 @data . each do | c | c . output_parse ( out ) out . c . puts "\n// CSUCC #{c.inspect}" out . c . puts "case #{@child_succ_states[c]}:" out . c . indent += 1 out . c . puts "top -= 2;" out . c . puts "state = #{@parent.next_state(self)}; continue;" out . c . indent -= 1 out . c . puts "\n// CFAIL #{c.inspect}" out . c . puts "case #{@child_fail_states[c]}:" out . c . indent += 1 out . c . puts "offset = stack[top]; // restore saved offset (backtrack)" out . c . puts "for (int i = tree_stack[tree_top]->num_children - stack[top-1]; i > 0; --i) " + "{ Node_pop_child(tree_stack[tree_top]); }" out . c . puts "// pass through" out . c . indent -= 1 end out . c . puts "\n// FAIL  #{self.inspect}" out . c . puts "case #{@failure_state}:" out . c . indent += 1 out . c . puts "top -= 2;" out . c . puts "state = #{@parent.fail_state(self)}; continue;" out . c . indent -= 1 out . c . puts "\n// END   #{self.inspect}" end
note: a simpler implementation might create an intermediate parent for each child
note : a simpler implementation might create an intermediate parent for each child
out
<not_specific>