Theory Parse_Table
section ‹Parse Table›
theory Parse_Table
imports Follow_Map
begin
text‹From the (correct) NULLABLE, FIRST, and FOLLOW sets we build a list of parse table entries.›
type_synonym ('n, 't) table_key = "('n × 't lookahead)"
type_synonym ('n, 't) parse_table = "(('n × 't lookahead), ('n, 't) prod) fmap"
definition firstKeysForProd ::
"('n, 't) prod ⇒ 'n set ⇒ ('n, 't) first_map ⇒ ('n, 't) table_key list" where
"firstKeysForProd ≡ (λ(x, gamma) nu fi. map (λla. (x, la)) (firstGamma gamma nu fi))"
definition followKeysForProd :: "('n, 't) prod ⇒ 'n set ⇒ ('n, 't) first_map
⇒ ('n, 't) follow_map ⇒ ('n, 't) table_key list" where
"followKeysForProd ≡ (λ(x, gamma) nu fi fo.
map (λla. (x, la)) (if nullableGamma gamma nu then findOrEmpty x fo else []))"
abbreviation keysForProd :: "'n set ⇒ ('n, 't) first_map ⇒ ('n, 't) follow_map ⇒ ('n, 't) prod
⇒ ('n, 't) table_key list" where
"keysForProd nu fi fo xp ≡ (firstKeysForProd xp nu fi) @ (followKeysForProd xp nu fi fo)"