Definition next_ptd (ptd:pt_dot): option pt_dot :=
  match ptd with
    | Shift_ptd term sem ptl ptlz =>
      Some (build_pt_dot ptl (Cons_ptl_ptlz (Terminal_pt term sem) ptlz))
    | Reduce_ptd ptlz =>
      let 'existT _ _ (existT _ _ (ptz, pt)) := pop_ptlz Nil_ptl ptlz in
      match ptz in pt_zipper sym _ _ return parse_tree sym _ _ -> _ with
        | Top_ptz => fun pt => None
        | Cons_ptl_ptz ptl ptlz' =>
          fun pt => Some (build_pt_dot ptl (Cons_ptl_ptlz pt ptlz'))
      end pt
  end.

Lemma parse_fix_complete: forall (ptd:pt_dot) (stack:stack) (n_steps:nat), ptd_stack_compat ptd stack -> match parse_fix init stack (ptd_buffer ptd) n_steps with | OK (Parsed_pr sem_res buffer_end_res) => sem_res = full_sem /\ buffer_end_res = buffer_end /\ S (ptd_cost ptd) <= n_steps | OK Fail_pr => False | OK Timeout_pr => n_steps < S (ptd_cost ptd) | Err => True end.