@@ -74,38 +74,49 @@ def pushArg (σ : ParseState) (arg : Nat) : ParseState :=
7474 { σ with output := (lit arg) :: σ.output }
7575
7676def pushOp? (σ : ParseState) (op : Op) : Option ParseState :=
77- match σ.hold with
77+ match _ : σ.hold with
7878 | [] => some { σ with hold := [op] }
7979 | top :: hold =>
8080 match compare top.prio op.prio, top.leftAssoc with
8181 | .lt, _ | .eq, false => some { σ with hold := op :: top :: hold }
8282 | .gt, _ | .eq, true =>
8383 match σ.output with
84- | arg₂ :: arg₁ :: out => some { σ with hold := op :: hold , output := app top arg₁ arg₂ :: out }
84+ | arg₂ :: arg₁ :: out => pushOp? { σ with hold, output := app top arg₁ arg₂ :: out } op
8585 | _ => none
86+ termination_by σ.hold.length
87+ decreasing_by all_goals simp +arith [*]
8688
8789@[simp]
8890theorem pushOp?_ops {σ₁ : ParseState} (h : σ₁.pushOp? op = some σ₂) : σ₁.ops = σ₂.ops := by
91+ sorry
92+ /-
8993 rw [ pushOp? ] at h
9094 repeat' split at h
9195 all_goals
9296 first
9397 | injection h with h; rw [ ←h ]
9498 | contradiction
99+ -/
95100
96101theorem pushOp?_output_hold_length
97102 {σ₁ : ParseState} (hp : σ₁.pushOp? op = some σ₂) (hl : σ₁.hold.length < σ₁.output.length) :
98103 σ₂.output.length - σ₂.hold.length = σ₁.output.length - σ₁.hold.length - 1 := by
104+ sorry
105+ /-
99106 rw [ pushOp? ] at hp
100107 (repeat' split at hp) <;> injection hp
101108 all_goals next hp => simp_all only [List.length_cons, ←hp]; omega
109+ -/
102110
103111theorem pushOp?_hold_length_le_output_length
104112 {σ₁ : ParseState} (hp : σ₁.pushOp? op = some σ₂) (hl : σ₁.hold.length < σ₁.output.length) :
105113 σ₂.hold.length ≤ σ₂.output.length := by
114+ sorry
115+ /-
106116 rw [ pushOp? ] at hp
107117 (repeat' split at hp) <;> injection hp
108118 all_goals next hp => simp_all +arith [ ←hp ]
119+ -/
109120
110121def push? (σ : ParseState) (arg : Nat) (op : Op) : Option ParseState :=
111122 σ.pushArg arg |>.pushOp? op
@@ -124,6 +135,11 @@ theorem push?_output_hold_length
124135 simp only [pushOp?_output_hold_length hp hh, List.length_cons]
125136 omega
126137
138+ theorem push?_output_length_eq_hold_length
139+ {σ₁ : ParseState} (hp : σ₁.push? arg op = some σ₂) (he : σ₁.hold.length = σ₁.output.length) :
140+ σ₂.output.length = σ₂.hold.length := by
141+ sorry -- TODO: Not sure if this is actually provable.
142+
127143def finalize (σ : ParseState) : ParseState :=
128144 match _ : σ.hold, σ.output with
129145 | op :: hold, arg₂ :: arg₁ :: out => finalize { σ with hold, output := app op arg₁ arg₂ :: out }
0 commit comments