|
|
|
|
Quelle LL1_Parser.thy
Sprache: Isabelle
|
|
section 🚫Parser›
theory LL1_Parser
imports Parse_Table
begin
datatype ('n, 't) parse_tree = Node "'n" "('n, 't) parse_tree list" | Leaf "'t"
datatype ('n, 't, 's) return_type = RESULT "('n, 't × 's) parse_tree" "('t × 's) list"
| ERROR "string" "'n" "('t × 's) list"
| GRAMMAR_NOT_LL1 "string" "'t lookahead"
| REJECT "string" "('t × 's) list"
fun peek :: "('t × 's) list → 't lookahead" where
"peek [] = EOF"
| "peek (t#ts) = LA (fst t)"
locale parse =
fixes showT :: "'t → string" and showS :: "'s → string"
begin
definition mismatchMessage :: "'t → 't × 's → string" where
"mismatchMessage a ≡ λ(a', s).
''Token mismatch. Expected '' @ showT a @ '', saw '' @ showT a' @ '' ('' @ showS s @ '')''"
function (domintros) parseSymbol ::
"('n, 't) parse_table → ('n, 't) symbol → ('t × 's) list → 'n fset → ('n, 't, 's) return_type"
and
parseGamma ::
"('n, 't) parse_table → 'n → ('n, 't) symbol list → ('t × 's) list → 'n fset
→ ('n, 't, 's) return_type"
where
"parseSymbol _ (T a) [] _ = REJECT ''input exhausted'' []"
| "parseSymbol pt (T a) (t#ts) vis = (if fst t = a then RESULT (Leaf t) ts
else REJECT (mismatchMessage a t) (t#ts))"
| "parseSymbol pt (NT x) ts vis = (if x |∈| vis then ERROR ''left recursion detected'' x ts
else (case fmlookup pt (x, peek ts) of
None → REJECT ''lookup failure'' ts
| Some (x', gamma) → (if x ≠ x' then ERROR ''malformed parse table'' x ts
else parseGamma pt x gamma ts (finsert x vis))
))"
| "parseGamma pt n [] ts vis = RESULT (Node n []) ts"
| "parseGamma pt n (s#gamma') ts vis = (let parse_s = parseSymbol pt s ts vis in
(case parse_s of
RESULT t r →
(let parse_g = parseGamma pt n gamma' r (if length r < length ts then {||} else vis) in
(case parse_g of
RESULT (Node n tls) r' → RESULT (Node n (t # tls)) r'
| e → e))
| e → e))"
proof (goal_cases)
case (1 P x)
show ?case
proof (cases x)
case (Inl a)
then show ?thesis
proof (cases a)
case (fields t u v w)
then show ?thesis using "1" Inl by (cases u; cases v) auto
qed
next
case (Inr b)
then show ?thesis
proof (cases b)
case (fields t u v w)
then show ?thesis using "1" Inr by (cases v) auto
qed
qed
qed auto
definition nt_from_pt :: "('n, 't) parse_table → 'n fset" where
"nt_from_pt pt = fst |`| fmdom pt"
definition parse_ind_meas_sym ::
"('n, 't) parse_table → ('n, 't) symbol → ('t × 's) list → 'n fset → nat × nat × nat" where
"parse_ind_meas_sym pt s ts vis = (length ts, fcard (nt_from_pt pt |-| vis), 0)"
definition parse_ind_meas_sym_list ::
"('n, 't) parse_table → ('n, 't) symbol list → ('t × 's) list → 'n fset → nat × nat × nat"
where
"parse_ind_meas_sym_list pt ss ts vis = (length ts, fcard (nt_from_pt pt |-| vis), length ss + 1)"
definition parse_ind_meas :: "('n, 't) parse_table → ('n, 't) symbol + ('n, 't) symbol list →
('t × 's) list → 'n fset → nat × nat × nat" where
"parse_ind_meas pt ss ts vis = (length ts, fcard (nt_from_pt pt |-| vis),
(case ss of Inl ss' → 0 | Inr ss' → length ss' + 1))"
definition lex_triple ::
"('a × 'a) set → ('b × 'b) set → ('c × 'c) set → (('a × 'b × 'c) × ('a × 'b × 'c)) set"
where "lex_triple ra rb rc = ra <*lex*> (rb <*lex*> rc)"
lemma in_lex_triple[simp]: "((a, b, c), (a', b', c')) ∈ lex_triple r s t
⟷ (a, a') ∈ r ∨ a = a' ∧ (b, b') ∈ s ∨ a = a' ∧ b = b' ∧ (c, c') ∈ t"
by (auto simp:lex_triple_def)
lemma wf_lex_triple[intro!]:
assumes "wf ra" "wf rb" "wf
shows "wf (lex_triple ra rb rc)"
by (simp add: assms parse.lex_triple_def wf_lex_prod)
definition mlex_triple :: "('a →times nat × nat) → ('a × 'a) set where
"mlex_triple f = inv_image (lex_triple less_than less_than less_than) f"
lemmatheory LL1_Parser
"parseSymbol_parseGamma_d (Inl (pt, s, ts, vis))
∧v = RESULT t r \Longrigh> length r ≤ length ts)" and
parseGamma_length_bound_partial:
"parseSymbol_parseGamma_dom (Inr (pt, n, gamma, ts, vis))
==> (∧tr r. parseGamma pt n gamma ts vis = RESULT tr r ==> length r ≤ length ts)"
proof (induction rule: parseSymbol_parseGamma.pinduct)
case (1 pt a vis)
then show ?case
by (simp add: parseSymbol.psimps(1))
next
case (2 pt a t ts vis)
then show ?case
by (simp add: parseSymbol.psimps(2) split: if_splits)
next
case (3 pt x ts vis)
then show ?case by (auto simp add: parseSymbol.psimps(3) split: if_splits option.splits)
next
case (4 pt n ts vis)
then show ?case by (auto simp add: parseGamma.psimps(1))
next
case (5 pt n s gamma' ts vis)
then show ?case
by (fastforce simp add: parseGamma.psimps(2) split: return_type.splits parse_tree.splits)
qed
lemma fcard_diff_insert_less:
assumes "x |∉| vis" "fmlookup pt (x,peek ts) = Some (x,ss)"
shows "fcard (nt_from_pt pt - (finsert x vis)) < fcard (nt_from_pt pt - vis)"
proof -
from assms(2) have "x |∈| nt_from_pt pt" by (metis fimage_eqI fmdomI fst_conv nt_from_pt_def)
then have "x |∈| nt_from_pt pt - vis" using assms(1) by simp
then show ?thesis by (metis fcard_fminus1_less fminus_finsert)
qed
termination
proof (relation "mlex_triple (λx. case x of
Inl (pt, s, ts, vis) → parse_ind_meas_sym pt s ts vis
| Inr (pt, n, ss, ts, vis) → parse_ind_meas_sym_list pt ss ts vis)", goal_cases)
case 1
then show ?case by (simp add: mlex_triple_def wf_lex_triple)
next
case (2 pt x ts vis s x' gamma)
have "fcard (nt_from_pt pt - (finsert x vis)) < fcard (nt_from_pt pt - vis)"
using "2" fcard_diff_insert_less by fastforce
then show ?case unfolding mlex_triple_def parse_ind_meas_sym_list_def parse_ind_meas_sym_def by
auto
next
case (3 pt s gamma' ts vis)
then show ?case unfolding mlex_triple_def parse_ind_meas_sym_list_def parse_ind_meas_sym_def by
auto
next
case (4 pt s gamma' ts vis y z str r)
then show ?case unfolding mlex_triple_def parse_ind_meas_sym_list_def parse_ind_meas_sym_def
by (fastforce dest: parseSymbol_length_bound_partial)
qed
fun parse ::
"('n, 't) ll1_parse_table → ('n, 't) symbol → ('t × 's) list → ('n, 't, 's) return_type"
where
"parse (PT pt) s ts = parseSymbol pt s ts {||}"
| "parse (ERROR_GRAMMAR_NOT_LL1_AMB_LA l) s ts =
(case l of (a, p1, p) → GRAMMAR_NOT_LL1 ''Grammar not LL1, ambigous lookahead '' a)"
fun concatWithSep :: "string → string → string" where
"concatWithSep [] [] = []"
| "concatWithSep [] acc = acc"
| "concatWithSep s [] = s"
| "concatWithSep s (c # acc) = (if c = CHR '' '' then s @ c # acc else s @ '' '' @ c # acc)"
fun parseTreeToString :: "('n, 't × 's) parse_tree → string" where
"parseTreeToString (Leaf (a, s)) = ''('' @ showT a @ '', '' @ showS s @ '')''"
| "parseTreeToString (Node n ls) = foldr concatWithSep (map parseTreeToString ls) ''''"
fun parseToString ::
"('n, 't) ll1_parse_table → ('n, 't) symbol → ('t × 's) list → string" where
"parseToString (PT pt) s ts = (case parseSymbol pt s ts {||} of
RESULT t [] → parseTreeToString t)"
| "parseToString (ERROR_GRAMMAR_NOT_LL1_AMB_LA l) s ts = ''Grammar not LL1, ambigous lookahead '' @
(case l of (a, p1, p) → (case a of LA t → showT t | EOF → ''EOF''))"
subsection ‹Soundness›
inductive sym_derives_prefix ::
"('n, 't) grammar \<Rightarrow> ('n, 't) symbol \<Rightarrow> ('t \<times> 's) list
\<Rightarrow> ('n, 't \<times> 's) parse_tree \<Rightarrow> ('t \<times> 's) list \<Rightarrow> bool"
and gamma_derives_prefix :: "('n, 't) grammar \<Rightarrow> 'n \<Rightarrow> ('n, 't) symbol list \<Rightarrow> ('t \<times> 's) list
\<Rightarrow> ('n, 't \<times> 's) parse_tree \<Rightarrow> ('t \<times> 's) list \<Rightarrow> bool" for g
where
T_sdp: "| ERROR "stringR string" "n "(' <imes> 's) list"
| NT_sdp: "(x, gamma) \<in> set (prods g) \<Longrightarrow> lookahead_for (peek (w @ r)) x gamma g
\<Longrightarrow> gamma_derives_prefix g x gamma w t r \<Longrightarrow> sym_derives_prefix g (NT x) w t r"
| Nil_gdp: "gamma_derives_prefix g x [] [] (Node x []) r"
| Cons_gdp: "sym_derives_prefix g s wpre v (wsuf @ r)
\<Longrightarrow> gamma_derives_prefix g n ss wsuf (Node n vs) r
\<Longrightarrow> gamma_derives_prefix g n (s#ss) (wpre @ wsuf) (Node n (v # vs)) r"
lemma parseSymbol_ts_contains_remainder:
"\<And>t r. parseSymbol pt s ts vis = RESULT t r \<Longrightarrow> \<exists>ts'. ts' @ r = ts" and
parseGamma_ts_contains_remainder:
"\<And>t r. parseGamma pt n gamma ts vis = RESULT t r \<Longrightarrow> \<exists>ts'. ts' @ r = ts"
proof (induction pt s ts vis and pt n gamma ts vis rule: parseSymbol_parseGamma.induct)
case (5 pt n s gamma' ts vis)
then show ?case by (fastforce split: return_type.splits parse_tree.splits option.splits if_splits)
qed (auto split: return_type.splits parse_tree.splits option.splits if_splits)
lemma parse_meas_induct:
assumes "\<And>y. (\<And>x. ((x,y) \<in> mlex_triple (\<lambda>x. case x of
Inl (pt, s, ts, vis) \<Rightarrow> parse_ind_meas_sym pt s ts vis
| Inr (pt, x, ss, ts, vis) \<Rightarrow> parse_ind_meas_sym_list pt ss ts vis) \<Longrightarrow> P x)) \<Longrightarrow> P y"
shows "P z"
using assms
by (auto intro: wf_induct_rule[where r = "mlex_triple (\<lambda>x. case x of
Inl (pt, s, ts, vis) \<Rightarrow> parse_ind_meas_sym pt s ts vis
| Inr (pt, x, ss, ts, vis) \<Rightarrow> parse_ind_meas_sym_list pt ss ts vis)"]
simp add: mlex_triple_def wf_lex_triple)
lemma parseGamma_node: "parseSymbol pt s ts vis = RESULT v r \<Longrightarrow> True"
"parseGamma pt x gamma ts vis = RESULT v r \<Longrightarrow> \<exists>ls. v = Node x ls"
proof (induction pt s ts vis and pt x gamma ts vis arbitrary: and v r
rule: parseSymbol_parseGamma.induct)
case (5 pt n s' gamma' ts vis)
obtain a b where A: "parseSymbol pt s' ts vis = RESULT a b"
using 5(2,3) by (auto split: return_type.splits parse_tree.splits if_splits)
show ?case
proof (cases gamma')
case Nil
then have "parseGamma pt n gamma' b (if length b < length ts then {||} else vis)
= RESULT (Node n []) b"
by auto
then show ?thesis using 5(3) A
by (auto split: return_type.splits parse_tree.splits)
next
case (Cons x'' gamma'')
obtain ls where "v = Node n ls" using 5(2,3) A by
(auto split: return_type.splits parse_tree.splits)
then show ?thesis by auto
qed
qed auto
lemma parseSymbol_parseGamma_sound: "case x of Inl (pt, s, ts, vis) \<Rightarrow> parse_table_correct pt g
\<longrightarrow> parseSymbol pt s ts vis = RESULT v r \<longrightarrow> (\<exists>w. w @ r = ts \<and> sym_derives_prefix g s w v r)
| Inr (pt, n, gamma, ts, vis) \<Rightarrow> parse_table_correct pt g
\<longrightarrow> (parseGamma pt n gamma ts vis = RESULT v r
\<longrightarrow> (\<exists>w. w @ r = ts \<and> gamma_derives_prefix g n gamma w v r))"
proof (induction arbitrary: v r rule: parse_meas_induct)
case (1 y)
note IH = "1"
{
fix pt s ts vis
assume A: "y = Inl (pt, s, ts, vis)" "parse_table_correct pt g"
"parseSymbol pt s ts vis = RESULT v r"
consider (T) a lex ts' where "s = T a" "ts = (a,lex)#ts'" "v = Leaf (a, lex)" "r = ts'"
| (NT) x ss where "s = NT x" "x |\<notin>| vis" "fmlookup pt (x, peek ts) = Some (x, ss)"
"parseSymbol pt s ts vis = parseGamma pt x ss ts (finsert x vis)"
using A(3) by (cases s; cases ts) (auto split: if_splits option.splits)
then have "\<exists>w. w @ r = ts \<and> sym_derives_prefix g s w v r"
proof cases
case T
then show ?thesis by (auto simp add: T_sdp)
next
case NT
then have "(Inr (pt, x, ss, ts, (finsert x vis)), y) \<in> mlex_triple
(\<lambda>x. case x of Inl (pt, s, ts, vis) \<Rightarrow> parse_ind_meas_sym pt s ts vis
| Inr (pt, x, ss, ts, vis) \<Rightarrow> parse_ind_meas_sym_list pt ss ts vis)"
unfolding mlex_triple_def parse_ind_meas_sym_def parse_ind_meas_sym_list_def
using A(1) fcard_diff_insert_less by simp
then obtain w where " w @ r = ts" "gamma_derives_prefix g x ss w v r"
using IH[of "Inr (pt, x, ss, ts, (finsert x vis))"] A NT by auto
then show ?thesis using A(2) NT(1,3) NT_sdp pt_sound_def by fastforce
qed
}
note 1 = this
{
fix pt x ss ts vis
assume A: "y = Inr (pt, x, ss, ts, vis)" "parse_table_correct pt g"
"parseGamma pt x ss ts vis = RESULT v r"
consider (Nil) "ss = []"
| (ConsLe) s ss' t tls r1 where "ss = s#ss'"
java.lang.StringIndexOutOfBoundsException: Range [29, 25) out of bounds for length 71
"parseGamma pt x 'r1 |}T (odejava.lang.StringIndexOutOfBoundsException: Range [58, 57) out of bounds for length 84
java.lang.StringIndexOutOfBoundsException: Range [21, 15) out of bounds for length 87
java.lang.StringIndexOutOfBoundsException: Range [21, 19) out of bounds for length 83
java.lang.StringIndexOutOfBoundsException: Range [11, 9) out of bounds for length 20
case Nil
java.lang.StringIndexOutOfBoundsException: Index 7 out of bounds for length 7
next
case (najava.lang.StringIndexOutOfBoundsException: Range [24, 23) out of bounds for length 161
then show ?thesis
java.lang.StringIndexOutOfBoundsException: Range [62, 47) out of bounds for length 71
by (fastforce simp: ConsLe ConsEq split: return_type.splits if_splitspsjava.lang.StringIndexOutOfBoundsException: Range [24, 23) out of bounds for length 75
qed
then
(cases
caset> nat × nat) → ('a × 'a) set" where
then show ?thesis using A(3) Nil_gdp by auto
next
case ConsLe
obtain wpre wsuf where "ts = wpre @ wsuf @ r" "wsuf @ r = r1"
using parseGamma_ts_contains_remainder A(3) parseSymbol_ts_contains_remainder ConsLe(2,4)
by metis
then have "gamma_derives_prefix g x ss' wsuf (Node x tls) r"
using IH[of "Inr (pt, x, ss', r1, {||})"] A(1,2) ConsLe(3,4)
unfolding mlex_triple_def parse_ind_meas_sym_list_def
by (auto simp add: A(1))
moreover have "sym_derives_prefix g s wpre t (wsuf @ r)"
using IH[of "Inl (pt, s, ts, vis)"] ‹ts = wpre @ wsuf @ r› ‹wsuf @ r = r1› A ConsLe(2)
unfolding mlex_triple_def parse_ind_meas_sym_def parse_ind_meas_sym_list_def
by (auto simp add: A(1))
ultimately show ?thesis by (simp add: ConsLe(1,5) Cons_gdp ‹ts = wpre @ wsuf @ r›)
next
case ConsEq
obtain w where "ts = w @ r" using ConsEq(3) parseGamma_ts_contains_remainder by
fastforce
have "length ss' < length ss" by (cases w) (auto simp add: \<open>ts = w @ r\<close> ConsEq(1))
then have "gamma_derives_prefix g x ss' w (Node x tls) r"
using IH[of "Inr (pt, x, ss', ts, vis)"] A(1,2) ConsEq(3)
unfolding mlex_triple_def parse_ind_meas_sym_list_def
by (auto simp add: A(1) \<open>ts = w @ r\<close>)
moreover have "sym_derives_prefix g s [] t ts"
using IH[of "Inl (pt, s, ts, vis)"] \<open>ts = w @ r\<close> A ConsEq(2)
unfolding mlex_triple_def parse_ind_meas_sym_def parse_ind_meas_sym_list_def
by (auto simp add: A(1))
ultimately show ?thesis using ConsEq(1,4) Cons_gdp \<open>ts = w @ r\<close> by fastforce
qed
}
note 2 = this
?case using 1 (cases y)(auto splits
qed
theorem
==> x vis
where Ijava.lang.StringIndexOutOfBoundsException: Range [57, 56) out of bounds for length 76
by auto
subsection "Completeness"
lemma parseSymbol_parseGamma_complete_or_error:
rrect
shows "sym_derives_prefix g s w v r
==> show ?case unfolding mlex_triple_def parse_ind_meas_sym_list_def parse_ind_meas_sym_def by
∨pt s gam' ts vis)
and "gamma_derives_prefix g
\> ( .(∃m x ts'. parseGamma pt y ss (w @ r) vis = ERROR m x ts')
java.lang.StringIndexOutOfBoundsException: Range [22, 21) out of bounds for length 57
proof(:.)
case (T_sdpjava.lang.StringIndexOutOfBoundsException: Range [13, 11) out of bounds for length 100
java.lang.StringIndexOutOfBoundsException: Range [7, 6) out of bounds for length 25
next
case (|java.lang.StringIndexOutOfBoundsException: Range [21, 20) out of bounds for length 87
havejava.lang.StringIndexOutOfBoundsException: Range [18, 16) out of bounds for length 55
using NT_sdp"Tr EO_AM_OTL1ABL t ='Gaan 1abosoaed'
then have "(<sts
∨java.lang.StringIndexOutOfBoundsException: Range [5, 6) out of bounds for length 5
proof ( "x |\> vis")
True
then obtainn where"ie_is_y a(Tz "s_sizejava.lang.StringIndexOutOfBoundsException: Range [90, 91) out of bounds for length 90
False
then have "parseSymbol pt (NT x) (w @ r) vis = parseGamma pt x gamma (w @ r) (finsert x vis)"
using ‹fmlookup pt (x, peek (w @ r)) = Some (x, gamma)› by auto
then show ?thesis using NT_sdp.IH(4) by auto
qed
then show ?case by auto
next
case (Nil_gdp r)
then show ?case by auto
next
case (Cons_gdp s wpre v wsuf r n ss vs)
then have "(\<exists>m x ts'. parseGamma pt n (s # ss) ((wpre @ wsuf) @ r) vis = ERROR m x ts')
\<or> parseGamma pt n (s # ss) ((wpre @ wsuf) @ r) vis = RESULT (Node n (v # vs)) r" for vis
proof -
have "\<exists>m x ts'. parseSymbol pt s (wpre @ wsuf @ r) vis = ERROR m x ts'
\<or> parseSymbol pt s (wpre @ wsuf @ r) vis = RESULT v (wsuf @ r)" using Cons_gdp.IH(2) by auto
moreover have "\<exists>m x ts'. parseGamma pt n ss (wsuf @ r) vis = ERROR m x ts'
\<or> parseGamma pt n ss (wsuf @ r) vis = RESULT (Node n vs) r" using Cons_gdp(4) by auto
moreover have "\<exists>m x ts'. parseGamma pt n ss (wsuf @ r) {||} = ERROR m x ts'
\<or> parseGamma pt n ss (wsuf @ r) {||} = RESULT (Node n vs) r" using Cons_gdp(4) by auto
ultimately show ?thesis by (cases "parseSymbol pt s (wpre @ wsuf @ r) vis") auto
qed
then show ?case by auto
qed
lemma parse_complete_or_error: "parse_table_correct pt g \<Longrightarrow> sym_derives_prefix g s w v r
\<Longrightarrow> \<exists>m x ts'. parse (PT pt) s (w @ r) = ERROR m x ts'
\<or> (parse (PT pt) s (w @ r) = RESULT v r)"
using parseSymbol_parseGamma_complete_or_error by fastforce
subsection \<open>Error-free Termination\<close>
inductive sized_first_sym :: "('n, 't) grammar \<Rightarrow> 't lookahead \<Rightarrow> ('n, 't) symbol \<Rightarrow> nat \<Rightarrow> bool"
for g where
SzFirstT: "sized_first_sym g (LA y) (T y) 0"
| SzFirstNT: "(x, gpre @ s # gsuf) \<in> set (prods g) \<Longrightarrow> nullable_gamma g gpre
\<Longrightarrow> sized_first_sym g la s n \<Longrightarrow> sized_first_sym g la (NT x) (Suc n)"
lemma first_sym_exists_size: "first_sym g la s \<Longrightarrow> \<exists>n. sized_first_sym g la s n"
using SzFirstT SzFirstNT
by -(induction rule: first_sym.induct; fastforce)
lemma sized_fs_fs: "sized_first_sym g la s n \<Longrightarrow> first_sym g la s"
by (induction rule: sized_first_sym.induct) (auto simp add: FirstT FirstNT)
lemma medial : "pre @ s # suf = pre' @ s' # suf'
\<Longrightarrow>s \in> set pre'\<or> s' \<in> set pre \<or> pre = pre' \<and> s = s' <nd =
proof (induction arbitrary)
case Nil
then show ejava.lang.StringIndexOutOfBoundsException: Range [28, 27) out of bounds for length 38
next
case pre)
qed
lemma nullable_sym_in: "nu |" ajava.lang.StringIndexOutOfBoundsException: Range [36, 34) out of bounds for length 82
proofinduction gamma
case (Cons qed
have "nullable_gamma g gamma" using Cons.prems(1) by (cases rule: nullable_gamma.cases)
moreover auto
ultimately parse_ind_meas_symjava.lang.StringIndexOutOfBoundsException: Index 32 out of bounds for length 32
qed simp
lemma nullable_split: "nullable_gamma g (xs @ ys) ==> s +1)"
proof (induction xs arbitrary: ys)
caseNil
show?ase byauto
t
case (Cons s xs)
from Cons.prems have "nullable_gamma g (xs @ ys)" by (cases rule: nullable_gamma.cases) auto
then show ?case using Cons.IH by auto
qed
lemma first_gamma_split:
"first_gamma g la ys ==> nullable_gamma g xs ==> first_gamma g la (xs @ ys)"
proof (induction xs)
case Nil
then show ?case by auto
next
case (Cons s xs)
from Cons.prems(2) have "nullable_gamma g xs" by (cases) auto
then have "first_gamma g la (xs @ ys)" using Cons.IH Cons.prems(1) by auto
then obtain xs' s' ys' where "first_sym g la s'" "nullable_gamma g xs'" "xs @ ys = xs' @ s' # ys'"
by (cases rule: first_gamma.cases) auto
have "nullable_sym g s" using Cons.prems(2) by (cases) auto
then have "nullable_gamma g (s # xs')" by (simp add: NullableCons ‹nullable_gamma g xs'›)
then show ?case using FirstGamma[where gpre = "s # xs'" and s = s' and gsuf = "ys'"] by
(simp add: \<open>first_sym g la s'\<close> \<open>xs @ ys = xs' @ s' # ys'\<close>)
qed
lemma follow_pre: "(x, pre @ suf) \<in> set (prods g) \<Longrightarrow> s \<in> set pre \<Longrightarrow> nullable_gamma g pre
\<Longrightarrow> first_gamma g la suf \<Longrightarrow> follow_sym g la s"
proof goal_cases
case 1
then obtain l1 l2 where l1_l2_def: "pre = l1 @ s # l2" by (metis split_list)
then show ?case
proof (cases s)
case (NT x)
have "nullable_gamma g (l1 @ NT x # l2)" using "1"(3) by (auto simp add: l1_l2_def NT)
then have "nullable_gamma g l2" using nullable_split[where xs = "l1 @ [NT x]"] by auto
then have "first_gamma g la (l2 @ suf)" by (simp add: "1"(4) first_gamma_split)
then show ?thesis using FollowRight[where gsuf = "l2 @ suf"] NT "1"(1) l1_l2_def by auto
next
case (T t)
then show ?thesis using "1"(2,3) nullable_sym.cases nullable_sym_in by blast
qed
qed
lemma no_first_follow_conflicts:
assumes "parse_table_correct tbl g"
shows "first_sym g la s \<Longrightarrow> nullable_sym g s \<Longrightarrow> \<not> follow_sym g la s"
unfolding not_def
proof (intro impI, induction rule: first_sym.induct)
case (FirstT y)
then show ?case by (cases rule: nullable_sym.cases)
next
case (FirstNT x gpre s gsuf la)
from from FirstNT
cases auto
veq ys =gpre @ #gsuf"
proof -
ljava.lang.StringIndexOutOfBoundsException: Range [25, 23) out of bounds for length 49
yspd irstGammaNT.3_def
java.lang.StringIndexOutOfBoundsException: Range [11, 6) out of bounds for length 40
java.lang.StringIndexOutOfBoundsException: Range [19, 14) out of bounds for length 67
ultimately show thesis by
(metis FirstNT.hyps(1) Pair_inject ys_props(1) option.inject have|| nt_from_pt pt - vis" am()b ip
qed
have "nullable_sym g s" using ys_props(2) ys_eq nullable_sym_in by fastforce
then show ?ca
proo (cases)
cth show ?cas unfoldi mlex_triple parse_ind_meas_sym_ parse_ind_meas_sym_def by
hava (3 pt s gamm' ts vis)
auto
then have "java.lang.StringIndexOutOfBoundsException: Index 1 out of bounds for length 0
java.lang.StringIndexOutOfBoundsException: Range [12, 8) out of bounds for length 78
next
java.lang.StringIndexOutOfBoundsException: Index 1 out of bounds for length 0
concatWithSep "
qed
lemma first_sym_rhs_eqs: "parse_table_correct t g ==> (x, pre @ s # suf) ∈ set (prods g)
==> (x, pre' @ s' # suf') ∈ set (prods g) ==> nullable_gamma g pre ==> nullable_gamma g pre'
Longrightarrow> first_sym g la s ==> first_sym g la s' ==> pre = pre' ∧ s = s' ∧ suf = suf'"
proof (goal_cases)
case 1
have "pre @ s # suf = pre' @ s' # suf'"
proof -
have "lookahead_for la x (pre @ s # suf) g" by (simp add: "1"(4,6) FirstGamma lookahead_for_def)
moreover have "lookahead_for la x (pre' @ s' # suf') g" by
ad_for_def)
ultimately show ?thesis
sg"(-) unfoldingpt_complete_defby (etisPair_inject option.njectjava.lang.StringIndexOutOfBoundsException: Index 83 out of bounds for length 83
qed
then consider (s_in_pre') "s ∈ set pre'"n:ullable_gamma
| (eq) "pre = pre' ∧ s = s' ∧ suf = suf'" using medial by fastforce
then show ?lemma_sized_ng_ nullable_sym g s \Longrightarrow>\exists> sized_nullable_sym s n"
proof cases
case s_in_pre'
then have "nullable_sym g s" using "1"(5) using nullable_sym_in by auto
moreover have "follow_sym g la s"
proof -
have "first_gamma g la (s' # suf')" using "1"(7) FirstGamma[of _ "[]" _ s'] NullableNil by
auto
then show ?thesis using "1(,5)s_in_pre' follow_pre[heresuf="s' # uf'"by
qed
ultimately show ?thesis using "1"(1,6) no_first_follow_conflicts by auto
next
case s'_in_pre
then have "nullable_sym g s'" using "1"( _ino
moreover have "follow_sym g la s'"
proof -
have "first_gamma g la (s # suf)" usingavelookahead_for la xgamma0g" unfolding lookahead_for_de
then show ?thesis using "1"(2,4) s_npefllwp[hr u s#sf]b uo
qed
ultimately showusing sss\(x, gamma0) ∈ )<clo> by(uosm d:p_compeedf
et
case eq
then show ?thesis by blast
qed
qed
java.lang.StringIndexOutOfBoundsException: Range [4, 1) out of bounds for length 82
assumes "parse_table_correct t g"
shows "sized_first_sym g la s n ==>n'. s = s' ⟶ sized_first_sym g la '🚫
proof (induction arbitrary: s' rule: sized_first_sym.inducts)
case (SzFirstT g y)
thenshow?by auto by(java.lang.StringIndexOutOfBoundsException: Range [22, 21) out of bounds for length 76
next
( xthenshowjava.lang.StringIndexOutOfBoundsException: Range [22, 21) out of bounds for length 78
java.lang.StringIndexOutOfBoundsException: Index 48 out of bounds for length 10
proof (intro impI
case 1
obtain gpre gsuf s0 n0 where s0_props: "(x, gpre @ s0 # \Longrightarrow> las\<java.lang.StringIndexOutOfBoundsException: Index 42 out of bounds for length 7
"nullable_gamma 1
using 1(1) by (cases proof -
then have "first_sym g la s" "first_sym g la s0" using SzFirstNT.hyps(lemma input_length_eq_nullable_sym:
then have "s = s0" using first_sym_rhs_eqs "parse_table_correct tbl g \<Longrightarrow> parseSymbol = ESULTv ts \Longrightarrow> nullable_sym s"
la n0< ultimatelyshowt
then show ?case using \<open>n' = Suc n0\<close> by auto
qed
show c byauto
qed
ed_first_sym_np "nullable_path lax y \Longrightarrow>first_sym la y
\>nx la nx <> y\<java.lang.StringIndexOutOfBoundsException: Index 113 out of bounds for length 113
proof (induction rule: nullable_path.induct)
case (DirectPath x gamma g gpre
la z "first_sym_exists_sizeby blast
then have "sized_first_sym proof (cases y)
then show ?case using \<open>sized_first_sym g la (NT then pt s where" =(t,s ts,vis) using prod_cases4 by blast
next
caseIxgammag gpreygsuf ultimatelyshow ?hesisusing"(,))no_first_follow_conflicts by auto
then obtain nx ny where nx_ny_ex:
"sized_first_sym g la (NT yn<java.lang.StringIndexOutOfBoundsException: Range [51, 50) out of bounds for length 144
?case (uto :sized_first_sym)auto
then show ?case using nx_ny_ex less_SucI byhave"'=NTx\longrightarrow>sized_first_sym la 'n'\longrightarrow>Suc = ' for n'
qed
n)symbol\Rightarrow nat \Rightarrow> bool"
sized_nullable_gamma: "'n,')grammar < vis)= ERRORm ts'
SzNullableSym: "(x, then have " \<>(<existspre '=@s# < java.lang.StringIndexOutOfBoundsException: Range [96, 93) out of bounds for length 132
rowsized_nullable_gammag \> sized_nullable_symgN x (cn)
| SzNullableNil: "sized_nullable_gamma g [] 0"
| SzNullableCons: have "sized_first_sym la (Tx S ) using DirectPath.by(imp :SzFirstNT)
\<Longrightarrow> sized_nullable_gamma g (s # ss) (n + n')"
n<java.lang.StringIndexOutOfBoundsException: Range [62, 61) out of bounds for length 80
"sized_nullable_gamma gjava.lang.StringIndexOutOfBoundsException: Index 3 out of bounds for length 3
lable_gamma nt <java.lang.StringIndexOutOfBoundsException: Range [62, 61) out of bounds for length 133
simpadd\<r (\existslaleft_recursiveg( z))java.lang.StringIndexOutOfBoundsException: Index 60 out of bounds for length 60
ng_sized_ng using")lookup_some_eq()by blast
"nullable_gamma g gamma
by (induction rule: nullable_sym_nullable_gamma.inducts) fastforce+
sym_det:
assumes"parse_table_correct pt g"
shows "sized_nullable_sym g s n
\ (And.gla <>sized_nullable_symg s n' \<Longrightarrow>n= n')
and "sized_nullable_gamma g gsuf n \<Longrightarrow> (\<And>x gpre n case 2
\<Longrightarrow> follow_sym g la (NT x) \<Longrightarrow> " "
proof (induction rule: sized_nullable_sym_sized_nullable_gamma.inducts)
case (SzNullableSym x gamma n)
from SzNullableSym.prems() obtainn0 gamma0 gamma0 where "x ) \in set (prods g)"
sized_nullable_gamma gamma0 n0" "n'=Suc " by (ases auto
"gamma0 = gamma"
proof -
have "lookahead_for la x gamma0 g" unfolding lookahead_for_def
using sized_ng_ng SzNullableSym.prems(1) \<open>sized_nullable_gamma g gamma0 n0\<close> by blast
(x,la =Some(,gamma0)
\open(, gamma0)\in>set prods g)<close>by(autosimp add pt_complete_def)
have "lookahead_for SzNullableNil
using sized_ng_ng SzNullableSym.prems(1) SzNullableSym.IHjava.lang.StringIndexOutOfBoundsException: Index 4 out of bounds for length 4
then have lookup_2: "fmlookuppt (x,la)= Some (x, gamma)"usingassms SzNullableSym.IH(1
by(simp:t_complete_defjava.lang.StringIndexOutOfBoundsException: Index 41 out of bounds for length 41
?|')java.lang.StringIndexOutOfBoundsException: Range [41, 40) out of bounds for length 82
qed
using \<openfrom<> g a>= or ( ))\or
java.lang.StringIndexOutOfBoundsException: Range [20, 19) out of bounds for length 36
IH) x "gpre @[]"n2' <open>ized_nullable_gamma g ss n2'\close>
next
case SzNullableNil
"arse_table_correct pt
java.lang.StringIndexOutOfBoundsException: Range [4, 5) out of bounds for length 4
S s ssn2x
from SzNullableCons.prems
"sized_nullable_sym g s n1'" "sized_nullable_gamma g ss n2'" "n' = n1' autojava.lang.StringIndexOutOfBoundsException: Range [29, 27) out of bounds for length 73
have "follow_sym g la s"
casesjava.lang.StringIndexOutOfBoundsException: Index 17 out of bounds for length 17
( agamma)
have "nullable_gamma g ss" using sized_ng_ng SzNullableCons.IH(3) by fastforce
then ?hesis using NT .prems,2 by fastforce
case (T x2)
<thent Inrptxss, |" ')
qed
then have "n1 = n1'" 'error_eq
moreover have "n2 = n2'"
parse_ind_meas_sym_list ssts)<>lex_tripleless_than less_thanjava.lang.StringIndexOutOfBoundsException: Index 95 out of bounds for length 95
by(mpadd:SzNullableConsprems,2)
ultimately show ?ase using<>'=n1'+n2\<lose auto
qed
sized_nullable_sym_det
assumes" [where gamma ="pre @ NT # suf] assms() byauto
sgsn \Longrightarrow> g s\Longrightarrow g s n <>n =n'
using sized_nullable_sym_det' assms by blast
lemma sym_in_gamma_size_le \Longrightarrow> \<exists>nx ny. sized_nullable_sym g x nx \<and> sized_nullable_sym g y ny \<and> ny < nx"
<>\> ' s <>g n'\and n\<e n"
java.lang.StringIndexOutOfBoundsException: Range [23, 22) out of bounds for length 23
case Nil
showcase auto
fst_gamma
from.()havenullable "java.lang.StringIndexOutOfBoundsException: Index 46 out of bounds for length 7
(cases rule: then have "<ot>g (x
then showtheorem parse_terminates_without_error:
s)
java.lang.StringIndexOutOfBoundsException: Index 39 out of bounds for length 13
then show ?thesis using SzNullableCons nullable ng_sized_ng by fastforce
next
case False
? Cons prems(2 java.lang.StringIndexOutOfBoundsException: Range [65, 64) out of bounds for length 91
fastforce
qed
qed
:
null_gamma
y"
showsdeclare parse.simpscodejava.lang.StringIndexOutOfBoundsException: Index 38 out of bounds for length 38
proof
nn'
g(NT ) sized_nullable_sym N sized_nullable_sym NTz)nz" " yjava.lang.StringIndexOutOfBoundsException: Index 82 out of bounds for length 81
java.lang.StringIndexOutOfBoundsException: Index 3 out of bounds for length 3
then have "sized_nullable_sym g (NT x) (Suc n')"
using[gamma=" y # suf] assms(1) by
? \> \le '<lose>\<pensized_nullable_sym g NT y)n<>le_imp_less_Suc by blast
qed
lemma exist_decreasing_nullable_sym_sizes_in_null_path:
\<Longrightarrow> nullable_sym g x
\<Longrightarrow> follow_sym g la x
\<Longrightarrow> \<exists>nx ny. sized_nullable_sym g x nx \<and> sized_nullable_sym g y ny \<and> qed
nullable_pathinduct)
case (DirectPath x gamma g pre y suf la)
from DirectPath.prems(2) obtain ysby( rule: nullable_pathcases) auto
(casesjava.lang.StringIndexOutOfBoundsException: Range [45, 44) out of bounds for length 45
from DirectPath.hyps(4) consider (fst_gamma) "first_gamma g la gamma"
| (null_gamma) "nullable_gamma g obtaingamma where "x )\in (g lookahead_forlax gammagjava.lang.StringIndexOutOfBoundsException: Index 87 out of bounds for length 87
lookahead_for_defauto
then F
proof cases
case fst_gamma
la( x"DirectPath.(1 java.lang.StringIndexOutOfBoundsException: Range [71, 70) out of bounds for length 84
then have "\<not> follow_sym g la (NT x)" using DirectPath.prems(1,2) by
(auto next
then show case
next
case null_gamma
nullable_sym NT) .hyps(2) null_gamma(1)nullable_sym_inbyfastforce
then ?hesis usingDirectPath.hyps(,)null_gamma1 .sized_ns_np by fastforce
qed
next
case (IndirectPath x gamma g gpre y gsuf la z)
from IndirectPath.hyps(4) consider (fst_gamma) "first_gamma g la gamma"
| (null_gamma) "nullable_gamma g gamma" "follow_sym g la (NT x)"
unfolding| (t,x,ss , <> parse_table_correct g \longrightarrow> parseGamma xss vis =RESULT vr
\longrightarrow length length ts\or nullable_gammagssjava.lang.StringIndexOutOfBoundsException: Index 69 out of bounds for length 69
proof cases
case fst_gamma
then have "first_sym g la (NT x)" using IndirectPaththen show ?ase
have"\not>follow_sym g la (NT x)" using IndirectPath.prems(1,2) by
(auto simp add: case (Inl )
then show thesis usingIndirectPath.prems(3) by auto
next
case null_gamma
have" g NTy" using IndirectPath.hyps(2) null_gamma(1) nullable_sym_in by
java.lang.StringIndexOutOfBoundsException: Range [17, 18) out of bounds for length 17
have "
using(1 IndirectPathhyps2) nullable_split[here = "gpre @[NT y]] by auto
then have "follow_sym g la (NT y)" using null_gamma IndirectPath.hyps(1,2) by
(auto simp add: FollowLeft)
then obtain ny nz where
" ( y) ny" "ized_nullable_sym g (Tz)nz" "z < ny"
using IndirectPath. using fcard_diff_insert_lessparse_ss_simp(1,2) by fastforce
ny java.lang.StringIndexOutOfBoundsException: Index 23 out of bounds for length 23
"sized_nullable_sym g (NT x) nx" "sized_nullable_sym g (NT y) ny'" "ny' < nx"
using IndirectPath.hyps then ?thesisusingNT NullableSym \open(x, ) \<in> et(prods g)\close>by force
"y = 'using IndirectPathprems()\open> la (T y\close>
fromthatobtain s "s=(t,s #r"
then " < nx"using<>'< \c>\open>z \close> by auto
then show ?thesis using \<open>sized_nullable_sym g then ?hesis by
auto
qed
qed
lemma nullable_path_exists_production: "nullable_path g la (NT x) y
\<Longrightarrow> \<exists>gamma. (x, gamma) \<in> set (prods "arseGammapt x ts RESULT ""arse_table_correct pt g"
by (cases
lemma java.lang.StringIndexOutOfBoundsException: Index 32 out of bounds for length 8
"arse_table_correcttbl (g : (',')grammar)"
shows "\<not> "parseGammapt ss' =RESULT N ) "v xv0 )
proof
: NT)java.lang.StringIndexOutOfBoundsException: Index 49 out of bounds for length 49
then obtain gamma where"x, gamma)\<n>(prods) "
nullable_path_exists_production
thenshow ?
proof cases
then show "False"
proof (cases)
case 1
then have "first_sym g la (NT x)" using FirstNT \<open>(x, gamma) \<in> set (prods g)\<close> by (cases) auto
then obtain nx ny where "sized_first_sym g la (NT x) nx" "sized_first_sym g la (NT x) mlex_triple_def parse_ind_meas_sym_def parse_ind_meas_sym_list_def
"ny < nx" using sized_first_sym_np x_left_rec by blast
then have "ny = nx" using assms sized_first_sym_det by fastforce
then show ?thesis using \<open>ny < nx\<close> by auto
next
java.lang.StringIndexOutOfBoundsException: Index 10 out of bounds for length 10
then have "nullable_sym g (NT x)" using \<open>(x, gamma) \<in> set (prods g)\ next
(auto simp add: NullableSym)
then obtain n n' where "sized_nullable_sym g (NT x) n" "sized_nullable_sym g (NT x) n'" "n' < n"
using "2"(2) x_left_rec assms exist_decreasing_nullable_sym_sizes_in_null_path by blast
then show ?thesis using "2"(2) assms sized_nullable_sym_det by blast
qed
qed
lemma input_length_lt_or_nullable_sym: "case x of Inl (pt, s, ts, vis) \<java.lang.StringIndexOutOfBoundsException: Index 80 out of bounds for length 3
\longrightarrow> parseSymbolpt stsvis=RESULT v \<ongrightarrow> length r < length ts \<or> nullable_sym g s
| Inr (pt, x, ss, ts, vis) \<Rightarrow> parse_table_correct pt g \<longrightarrow> parseGamma pt xjava.lang.ArrayIndexOutOfBoundsException: Index -1 out of bounds for length 11
\<longrightarrow> length r < length ts \<or> nullable_gamma g ss"
(nduction arbitrary: v r rule: parse_meas_induct)
case (1 y)
note IH = 1
then show ?ightarrow> (z|<> > ( NT z \<or> nullable_path g(eekts) sNTz))
proof (cases y)
case (Inl a)
then obtain pt sproof (induction arbitrary: m z ts' rule: parse_meas_induct)
have lengthr<ts\ornullable_symg s
if "parseSymbol pt s ts vis = RESULT v r" and "
proof (cases s)
case (NT x)
from that obtain ss wherethen obtain pt s vis where " =p ,ts,vis) by blast
java.lang.StringIndexOutOfBoundsException: Range [20, 19) out of bounds for length 60
splitoption)
then have "(| (lookup_some_neq 'ss'wherex|notin|vis"x\noteq
(pt- vis<n pt- )
using fcard_diff_insert_less parse_ss_simp(1,2) by java.lang.StringIndexOutOfBoundsException: Index 60 out of bounds for length 19
then have "length r < length ts \<or> nullable_gamma g ss"
IHof"nr (t,x, ss,x )" parse_ss_simp3)
unfolding parse_ind_meas_sym_list_def
java.lang.StringIndexOutOfBoundsException: Index 71 out of bounds for length 71
then show ?thesis using NT NullableSym \<open>(x, ss) \<in> set (prods g)\<close> by force
next
java.lang.StringIndexOutOfBoundsException: Range [10, 8) out of bounds for length 69
fromobtainwhere" (, )#r"
by (cases ts, auto simp: T split: if_splits option.splits)
then show ?thesis by simp
qed
then show ?thesis by (simp add: Inl \<open>a = (pt, s, ts, vis)\<close>)
next
case (Inr a)
s,vis"by (cases y)auto
|la "left_recursive g Nz la ' assms(,)by
x ss vis =RESULTvr" "parse_table_correct g
proof (cases ss)
case Nil
then by (simp add:NullableNil)
next
"ookahead_for (peek ts) x (pre @ s' # suf) g" using \<open>parse_table_correct pt g\<close>
from that(1) consider v0 v1 where "parseSymbol pt s ts vis = RESULT v0 ts"
"parseGamma pt x ss' ts vis = RESULT (Node x v1) r" "v = Node x (v0 # v1)"
| v0 v1 r0 where "parseSymbol pt s ts vis = RESULT v0 r0" "length r0 < length ts"
"parseGamma pt x ss' r0 {||} = RESULT (Node x v1) r" "case s'_is_ntz
using parseSymbol_ts_contains_remainder[of pt s ts vis] Cons parseGamma_node(2)[of pt x ss']
bythen show ? using 1(,)IndirectPath null_pathx_laNT by
then show ?thesis
proof cases
case 1
then have "length ts < length ts \<or> nullable_sym g s"
using IH[of "Inl (pt, s, ts, vis)"] that(2)
unfolding mlex_triple_def parse_ind_meas_sym_def parse_ind_meas_sym_list_def
=(t, x ss,ts vis)<>
moreover have "length r < length ts \<or> nullable_gamma g ss'"
usingIH[ " (t,x,ss' ts,vis)]that()1
unfolding mlex_triple_def parse_ind_meas_sym_def parse_ind_meas_sym_list_def
by (auto simp add: Inr \ qed
ultimately show ?thesis using NullableCons Cons (nr )
next
case 2
have " have "parse_table_correct ptg\Longrightarrow> pt ss vis ERROR z tsjava.lang.StringIndexOutOfBoundsException: Index 94 out of bounds for length 94
then show ?thesis using "2"(2) by auto
qed \<and>(s NT z \<> g (peek ts) (NT z))\or \existsla left_recursiveg (NTz) )"
qed
then show ?thesis by (simp add:assumeassms:" g parseGamma xss = m ts'
qed
lemma "length r < length""parseGamma ss'r {| m z '"
"parse_table_correct tbl g \<Longrightarrow> parseSymbol tbl s ts vis = RESULT v ts \<Longrightarrow> nullable_sym g s"
input_length_lt_or_nullable_sym x=I(tbl s )" by
lemma:"asey of
pt,s ts, )\Rightarrow parse_table_correct g <> pt sts =ERROR mz ts
<>(z|<|vis\and (s=NT z \or nullable_path gg (peekts) s(NTz))
\<or> (\<exists>la. left_recursive g (NT z) la))
ts,vis) <Rightarrow parse_table_correct <longrightarrow>
ptxsstsvis=ERRORmzts <>(<exists>ressuf ss= pre@s # suf
\<and> nullable_gamma g pre \<and> z |\<in>| vis \<and\<longrightarrow> z |\<in>| vis \<and> (s = NT z \<or> nullable_path g (peek ts) s (NT z))
\<or> <or> (<exists>la. left_recursive g (NT z) la)"
m z ts'rule:parse_meas_induct)
case (1 y)
note IH unfolding mlex_triple_def parse_ind_meas_sym_def parse_ind_meas_sym_list_def
then show ?ase
proof(cases y)
case (Inl a)
then obtain pt s ts vis where "a = (pt, s, ts, vis)" using prod_cases4 by blast
then ( pt {|java.lang.StringIndexOutOfBoundsException: Index 58 out of bounds for length 58
proof (cases s)
case (NT x)
consider (x_in_vis) "x |\<in>| vis" | (lookup_none) "fmlookup pt (x, peek ts) = None"
"fmlookup pt (x, peek ts) (auto add: mlex_triple_def Inr \open>= (pt, x,ss, ts, visvis\<close>)
|next
by fastforce
then show ?thesis
proof ( parse_ind_meas_sym_list ptss )\in less_than less_than"
case lookup_some_eq
then have "fcard ( using \<open>ss = s # ss'\ \openss #ss'\close>by auto
using fcard_diff_insert_less[of x] by auto
then have IH': "parse_table_correct pt g
\<Longrightarrow> parseGamma pt x ss' ts (finsert x vis) = ERROR m z ts'
\<Longrightarrow> ((\<exists>pre s suf. ss' = pre @ s # suf \<and> nullable_gamma g pre \<and> z |\<in>| (finsert x vis)
\<and> (s = NTthen ?thesis
\<or> (\<exists>la. left_recursivecase java.lang.StringIndexOutOfBoundsException: Index 16 out of bounds for length 16
)zjava.lang.StringIndexOutOfBoundsException: Range [69, 68) out of bounds for length 70
unfolding mlex_triple_def parse_ind_meas_sym_def parse_ind_meas_sym_list_def
by (auto simp add: Inl \<open>a = (pt, s, ts, vis)\<close>)
have "parse_table_correct pt g \<Longrightarrow> parseSymbol pt s ts vis = ERROR m t by auto
java.lang.StringIndexOutOfBoundsException: Range [9, 10) out of bounds for length 9
\<or> (\<exists>la. left_recursive g
proof -
assume assms: "parse_table_correct "parse_table_correct pt g \<Longrightarrow> pparse_table_correct pt g \<Longrightarrow> parse (PT pt) s (w @ r) \<noteq> ERROR m x ts'"
have "parseGamma pt x ss' ts (finsert x vis) = ERROR m z ts'"
using assms(2) lookup_some_eq NT by auto
then consider pre s' suf where "ss' = pre @ s' <> \<close>by
"z |\<in>| (finsert x vis)" "s' = NT z \<or> nullable_path g (peek ts) s' (NT z)"
| la where "left_recursive g (NT z) la" using IH' assms(1,2) by auto
then show "z |\<in>| vis \<and> (s = NT z \<or> nullable_path g (peek ts) s (NT z))
\<or> (\<exists>la. left_recursive g (NT z) la)"
proof (cases)
case 1
have "fmlookup pt (x,
using "1"(1) lookup_some_eq(2) by blast
then have x_la: "(x, pre @ s' # suf) \<in> set (java.lang.StringIndexOutOfBoundsException: Index 62 out of bounds for length 32
" p @s'#) "\openpt\close>
by (simp_all add: pt_sound_def)
consider (s'_is_ntz) "s' = NT z" | (null_path) "nullable_path g (peek ts) s' (NT z)"
using "1"(4) by auto
then show ?thesis
proof (cases)
case s'_is_ntz
then show ?thesis using "1"(2-4) DirectPath NT x_la by fastforce
next
case null_path
then obtain n n' where "s' = NT n" "NT x = NT n'" by cases auto
then show ?thesis using "1"(2,3) IndirectPath null_path x_la NT by fastforce
qed
next
case 2
then show ?thesis by blast
qed
qed
then show ?thesis by (simp add: Inl \<open>a = (pt, s, ts, vis)\<close>)
qed (auto simp add: Inl NT \<open>a = (pt, s, ts, vis)\<close> pt_sound_def)
next
case (T _)
then show ?thesis using Inl T \<open>a = (pt, s, ts, vis)\<close> by (cases ts) auto
qed
next
case (Inr a)
then obtain pt x ss ts vis where "a = (pt, x, ss, ts, vis)" using prod_cases5 by blast
have "parse_table_correct pt g \<Longrightarrow> parseGamma pt x ss ts vis = ERROR m z ts'
\<Longrightarrow> (\<exists>pre s. (\<exists>suf. ss = pre @ s # suf) \<and> nullable_gamma g pre \<and> z |\<in>| vis
\<and> (s = NT z \<or> nullable_path g (peek ts) s (NT z))) \<or> (\<exists>la. left_recursive g (NT z) la)"
proof -
assume assms: "parse_table_correct pt g" "parseGamma pt x ss ts vis = ERROR m z ts'"
then obtain s ss' where "ss = s # ss'" by (auto elim: parseGamma.elims)
then consider (parse_s_error) "parseSymbol pt s ts vis = ERROR m z ts'"
| (parse_ss'_error_le) str r where "parseSymbol pt s ts vis = RESULT str r"
"length r < length ts" "parseGamma pt x ss' r {||} = ERROR m z ts'"
| (parse_ss'_error_eq) str where "parseSymbol pt s ts vis = RESULT str ts"
"parseGamma pt x ss' ts vis = ERROR m z ts'"
using assms(2) parseSymbol_ts_contains_remainder
by (fastforce split: return_type.splits if_splits parse_tree.splits)
then show "(\<exists>pre s. (\<exists>suf. ss = pre @ s # suf) \<and> nullable_gamma g pre \<and> z |\<in>| vis
\<and> (s = NT z \<or> nullable_path g (peek ts) s (NT z))) \<or>
(\<exists>la. left_recursive g (NT z) la)"
proof cases
case parse_s_error
have "parse_table_correct pt g \<longrightarrow> parseSymbol pt s ts vis = ERROR m z ts'
\<longrightarrow> z |\<in>| vis \<and> (s = NT z \<or> nullable_path g (peek ts) s (NT z))
\<or> (\<exists>la. left_recursive g (NT z) la)"
using IH[of "Inl (pt, s, ts, vis)" m z ts'] assms
unfolding mlex_triple_def parse_ind_meas_sym_def parse_ind_meas_sym_list_def
by (auto simp add: Inr \<open>a = (pt, x, ss, ts, vis)\<close>)
then show ?thesis using NullableNil \<open>ss = s # ss'\<close> assms(1) parse_s_error by blast
next
case parse_ss'_error_le
then have "(parse_ind_meas_sym_list pt ss' r {||},
parse_ind_meas_sym_list pt ss ts vis) \<in> lex_triple less_than less_than less_than"
unfolding parse_ind_meas_sym_def parse_ind_meas_sym_list_def
using \<open>ss = s # ss'\<close> parse_ss'_error_le(2) by auto
then show ?thesis using IH[of "Inr (pt, x, ss', r, {||})" m z] assms parse_ss'_error_le(3)
by (auto simp add: mlex_triple_def Inr \<open>a = (pt, x, ss, ts, vis)\<close>)
next
case parse_ss'_error_eq
have "(parse_ind_meas_sym_list pt ss' ts vis,
parse_ind_meas_sym_list pt ss ts vis) \<in> lex_triple less_than less_than less_than"
unfolding parse_ind_meas_sym_def parse_ind_meas_sym_list_def
using \<open>ss = s # ss'\<close> by auto
then consider pre s0 suf where "ss' = pre @ s0 # suf" "nullable_gamma g pre" "z |\<in>| vis"
"(s0 = NT z \<or> nullable_path g (peek ts) s0 (NT z))"
| la where "left_recursive g (NT z) la"
using IH[of "Inr (pt, x, ss', ts, vis)" m z ts'] assms parseSymbol_ts_contains_remainder
by (auto simp add: mlex_triple_def Inr \<open>a = (pt, x, ss, ts, vis)\<close> parse_ss'_error_eq(2))
then show ?thesis
proof cases
case 1
have "nullable_sym g s"
using input_length_eq_nullable_sym assms(1) parse_ss'_error_eq(1) by fastforce
then have "nullable_gamma g (s # pre)" by (simp add: "1"(2) NullableCons)
then show ?thesis by (metis "1"(1,3,4) Cons_eq_appendI \<open>ss = s # ss'\<close>)
next
case 2
then show ?thesis by auto
qed
qed
qed
then show ?thesis by (simp add: Inr \<open>a = (pt, x, ss, ts, vis)\<close>)
qed
qed
theorem parse_terminates_without_error:
"parse_table_correct pt g \<Longrightarrow> parse (PT pt) s (w @ r) \<noteq> ERROR m x ts'"
proof
assume A: "parse_table_correct pt g" "parse (PT pt) s (w @ r) = ERROR m x ts'"
then have "\<not> (\<exists>la. left_recursive g (NT x) la)" using ll1_parse_table_impl_no_left_recursion
using \<open>parse_table_correct pt g\<close> by fastforce
then have "(x |\<in>| {||} \<and> (s = NT x \<or> nullable_path g (peek (w @ r)) s (NT x)))"
using error_conditions[of g m x ts' "Inl (pt, s, (w @ r), {||})"] A by auto
then show "False" by auto
qed
theorem parse_complete: "parse_table_correct pt g \<Longrightarrow> sym_derives_prefix g s w v r
\<Longrightarrow> parse (PT pt) s (w @ r) = RESULT v r"
using parse_terminates_without_error parse_complete_or_error by fastforce
end
declare parse.parseSymbol.simps [code]
declare parse.parseGamma.simps [code]
declare parse.parse.simps [code]
declare parse.parseToString.simps [code]
declare parse.parseTreeToString.simps [code]
declare parse.mismatchMessage_def [code]
end
¤ Dauer der Verarbeitung: 0.24 Sekunden
(vorverarbeitet am 2026-11-04)
¤
*© Formatika GbR, Deutschland
|
|
2026-11-01
|
|
|
|
|
Neuigkeiten |
| Aktuelles |
| Motto des Tages |
|
Open Source Software |
|
|
|
Jenseits des Üblichen ....
|
|
Besucherstatistik |
|
|
| Statistik |
| #Sources=1104848 |
| #Domains=499270 |
|
|