【文章內(nèi)容簡介】
非二義的 R R | R R R a b R R a R * b R R R a R * R | R b R R b a … E E | T T F T T F F a b F F * b a 2022/8/28 12 ? 下面的條件語句文法 ?stmtif expr then stmt | matched_stmt ?matched_stmt if expr then matched_stmt else stmt | other 試圖消除懸空 else的二義性。請證明此文法仍是二義的。 2022/8/28 13 (續(xù) ) ? 由于 matched_stmt不能保證 then和 else的配對,因而存在二義性 ? 句型 if expr then if expr then matched_stmt else if expr then matched_stmt else stmt存在兩個不同的最左推導(dǎo) ? 期望的是: if expr then if expr then matched_stmt else if expr then matched_stmt else stmt 2022/8/28 14 (續(xù) ) ? 一種推導(dǎo),和期望的不一樣 ? stmt = matched_stmt = if expr then matched_stmt else stmt = if expr then if expr then matched_stmt else stmt else stmt = if expr then if expr then matched_stmt else if expr then stmt else stmt = if expr then if expr then matched_stmt else if expr then matched_stmt else stmt ? if expr then if expr then matched_stmt else if expr then matched_stmt else stmt 2022/8/28 15 (續(xù) ) ? 另一種推導(dǎo) ? stmt = if expr then stmt = if expr then matched_stmt = if expr then if expr then matched_stmt else stmt = if expr then if expr then matched_stmt else matched_stm