Module Title: Informtics 2A Exm Diet (Dec/April/Aug): Aug 2015 Brief notes on nswers: 1. () Lexing: The input is progrm text [1].The output is strem of lexemes pired with their lexicl clsses [1]. For exmple the expression xyz 22 would result two lexeme strem xyz, 22 with lexicl clsses VAR of vribles nd INT of integer literls respectively [1]. Prsing: The input is strem of lexicl clsses (lexemes good enough) [1]. The output is syntx tree [1]. For exmple, VAR INT might produce tree such s (EXP (FUN (VAR)) (ARGS (ARG INT) (ARGS ɛ))) expressing the syntx of n expression formed s (possibly iterted) function ppliction [1]. Type-checking. The input is syntx tree [1]. The output is yes/no response s to whether the progrm type-checks, together with dignostic error messges if not [1]. In the exmple bove it would be checked tht the vrible xyz hs type of the form Integer -> τ, for some τ, llowing the function ppliction to be formed. [Only miniml detils re required. The exmples need to be fithful the ide of lexing/prsing/type-checking, not necessrily fithful to ny prticulr lnguge.] (b) E.g., Compiltion(/interprettion/evlution/execution) [1]. 2. () Let M 1 = (Q 1, s 1, F 1, δ 1 ) nd M 2 = (Q 2, s 2, F 2, δ 2 ). The desired DFA hs Q = Q 1 Q 2 s = (s 1, s 2 ) F = F 1 (Q 2 F 2 ) nd (q 1, q 2 ) (q 1, q 2) whenever q 1 for ech component] (b) The resulting DFA: q 1 in δ 1 nd q 2 q 2 in δ 2. [4: 1 mrk [4 mrks: deduct 1 per mistke] (c) No it is not possible: context-free lnguges re not closed under complement [1]. An exmple is Σ {xx x Σ } which is context free but its complement not [1]. [The first mrk needs more context thn just the nswer no ] [The counterexmple is bookwork] i
3. () The PDA execution: [8 mrks: in principle 1 per step] (b) The lnguge is: stte stck unred input q1 b q1 b q1 b q1 b q2 q2 ɛ q2 ɛ q2 ɛ ɛ { n b m 1 n, 0 m n} [2 mrks: wrd 1 if ide right but some error in detil] 4. () Zipf s lw is n empiricl lw stting tht in typicl corpus of text, the number of occurrences of given word type is (pproximtely) inversely proportionl to its frequency rnk. [Up to 2 mrks] (b) Suppose k is constnt such tht the word with frequency rnk r occurs round k/r times. We re given tht k + k/2 + k/3 + k/4 = (25/12)k = 2500, whence k = 1200. To resonble pproximtion, 1/21 + + 1/30 = 10/25 = 2/5, so the required number of tokens is round 2k/5 = 480. [Up to 3 mrks.] (c) To compute the trnsition probbility from the POS X to the POS Y, look t ll occurrences in the corpus of tokens tgged s X, nd clculte wht proportion of these re followed by token tgged s Y. To compute the emission probbility for POS X s word w, look t ll occurrences of tokens tgged s X, nd clculte wht proportion of these re the word w. [1 mrk for ech of these; 1 further mrk for clrity of explntion.] (d) We would expect higher proportionl ccurcy for the infrequent word types. This is becuse most infrequent words hve only one possible POS tg, wheres severl of the most frequent words re grmmticl function words with severl possible tgs. [2 mrks. Any other logiclly resonble point will be ccepted here.] 5. The CYK prse chrt is: bot mn wtches fish bot NP 1 NP 1 NP 2, S 1 NP 5, S 2 mn NP 1, V 1 NP 1, VP 1 NP 2, VP 1, S 1 wtches NP 1, V 1 NP 1, VP 1 fish NP 1, V 1 Up to 7 mrks for the non-terminl entries; up to 3 mrks for the numbers. 6. () The production S S b is left recursive [1]. ii
(b) For exmple S S1 T S1 ( S S ) T ɛ b T [5 mrks: in proportion] (c) First(S) = {, ( } First(S1) = {, ( } First(T) = {ɛ, b} [3: in principle 1 mrk ech] (d) [3: in principle 1 mrk ech] (e) Prse tble: [6 mrks: deduct 1 per mistke] (f) Algorithm execution: [7 mrks: in proportion] Follow(S) = {, (, ), $ } Follow(S1) = {, b, (, ) } Follow(T) = {, (, ), $ } b ( ) $ S S1 T S1 T S1 ( S S ) T ɛ b T ɛ ɛ ɛ ction unred input stck ( ) $ S S S1 T ( ) $ S1 T S1 ( S S ) ( ) $ ( S S ) T mtch ( ) $ S S ) T S S1 T ) $ S1 T S ) T S1 ) $ T S ) T mtch ) $ T S ) T T ɛ ) $ S ) T S S1 T ) $ S1 T ) T S1 ) $ T ) T mtch ) $ T ) T T ɛ ) $ ) T mtch ) $ T T ɛ $ ɛ iii
7. () The following trnsducer does the job. Here V stnds for ny of the letters,e,i,o,u, nd C stnds for ny letter except,e,i,o,u,y. A single symbol (without colon) denotes trnsition with the sme input nd output. [6 mrks for evidence of understnding, 6 mrks for the detils. Only deduct 1 or 2 mrks if ny or ll of the following trnsitions re missing or incorrect: 3 0, 3 1, 4 1, nd the trnsition 4 0 lbelled with C:ysC.] (b) he# prses s he# plies# prses s plies#, plie s#, ply s# trdes# prses s trdes#, trde s# [Up to 4 mrks; deduct 1 mrk per mistke.] (c) he: PRN plies: NPL, V3S trdes: NPL, V3S [1 mrk for ech word.] (d) The Viterbi mtrix is s follows. Cells tht re not consistent with the possibilities listed in prt (c) re left empty. he plies trdes PRN 0.4 NPL 0.4x0.1=0.04 0.16x0.5=0.08 V3S 0.4x0.4=0.16 0.04x0.1=0.004 So the most probble tg sequence is PRN V3S NPL. [4 mrks for the numbers, 1 mrk for the bcktrce pointers, 1 mrk for the correct tgging. Minor clericl errors will not be hevily penlized.] 8. () The complete grmmr with semntic ttchments is s follows: iv
S Nme is NP {NP.Sem(Nme.Sem)} NP Nme {λx. x = Nme.Sem} NP NP s Rel {λx. y. NP.Sem(y) & Rel.Sem(x, y)} Rel Rel1 {Rel1.Sem} Rel1 fther {λxy. Fther(x, y)} Rel1 dughter {λxy. Femle(x) & (Fther(y, x) Mother(y, x))} Rel1 brother {λxy. Mle(x) & (x = y) & ( z.fther(z, x) Fther(z, y)) & ( w.mother(w, x) Mother(w, y))} Rel1 grndchild {λxy. z. (Fther(y, z) Mother(y, z)) & (Fther(z, x) Mother(z, x))} Nme Alice {Alice}, etc. [3 mrks ech for the cluses for brother nd grndchild ; 2 mrks for the cluse for NP s Rel; roughly 1 mrk ech for the remining cluses. Other solutions re eqully cceptble for some of these cluses.] (b) The root node of the tree will be nnotted with (λx. y.(λx.x = Alice)(y) & (λxy.fther(x, y))(x, y))(brin) nd the other nodes will be nnotted with subexpressions of this in the evident wy. [Roughly 1 mrk per node.] (c) The bove λ-expression β-reduces in three steps (which my be done in vrious orders) to y. y = Alice & Fther(Brin, y) [1 mrk per reduction step.] (d) We my define This suggests the semntic cluse R(x, y) R(x, y) & w. R(w, y) w = x Rel only Rel1 {λxy. Rel.Sem(x, y) & w. Rel.Sem(w, y) w = x} [1 mrk for the formul for R, 2 mrks for the semntic cluse.] v