[試題] 98下 陳俊良 編譯程式設計 期末考

看板NTU-Exam作者 (KC)時間13年前 (2011/06/23 22:39), 編輯推噓0(001)
留言1則, 1人參與, 最新討論串1/1
課程名稱:編譯程式設計 課程性質:必修 課程老師:陳俊良 開課學院:電資學院 開課系所:資工系 考試日期(年月日):2010.06.22 考試時限(分鐘):120分鐘 是否需發放獎勵金:是 (如未明確表示,則不予發放) 試題: 1. The followings are the production rules with semantic actions for assi -gnment, if and while statements. P → {S.next = newLabel();} S {gen(Label S.next);} S → assign {gen(Assign...);} S → {S1.next = newLabel();} S {gen(Label S1.next);S2.next = S.next;} S S → if( {B.true = newLabel();B.false = newLabel();} B) {gen(Label B.true);S5.next = S.next;} S {gen(Label B.false)} S → if( {B.true = newLabel();B.flase = newLabel();} B) {gen(Label B.true);S5.next = S.next;} S else {gen(GotoS.next);gen(LabelB.false);S7.nextS.next;} S S → while( {B.true = newLabel();B.false = S.next; S5.next = newLabel();gen(Label S5.next);} B) {gen(Label B.true);} s {gen(Goto S5.next);} Now, you are asked to add a new statement, break statement, as follow: S → break; A break statement ends a shile loop and moves control to the next statement outside the loop. Within nested statements, the break statement ends only the smallest enclosing while statement. (a) Modify/add the semantic actions to implement this new statement. [20%, at most 15 lines] (b) When a break statement isn't enclosed by any while statement, it is illegal. How does your compiler detect this illegality? [10%, at most 3 lines] 2. (a) What is the purpose of a maker nonterminal in a bottom-up parser? [ 5%, at most 3 lines] (b) What is the purpose of a synthesized record in a top-down parser? [ 5%, at most 3 lines] 3. How to compile a field access of a struct? [20%, at most 10 lines] 4. How to do automatic garbaage collections? [20%, at most 10 lines] 5. What's a compiler? Assume that the audiences are CS freshmen. No 全牛 answer. [20%, at most 10 lines] -- 將竭盡心力所追求的 握緊在手掌之間 入世的那刻早已注定 -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 218.167.75.162

06/24 00:54, , 1F
已收錄至資訊系精華區!!
06/24 00:54, 1F
文章代碼(AID): #1E0r0aEc (NTU-Exam)