作者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