作者peter850130 (KC)
看板NTU-Exam
標題[試題] 98下 陳俊良 編譯程式設計 期末考
時間Thu Jun 23 22:39:22 2011
課程名稱:編譯程式設計
課程性質:必修
課程老師:陳俊良
開課學院:電資學院
開課系所:資工系
考試日期(年月日):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
1F:→ andy74139 :已收錄至資訊系!! 06/24 00:54