作者rod13824 (猛矮)
看板NTU-Exam
标题[试题] 100下 编译程式设计 陈俊良 期末考
时间Thu Jun 21 20:25:17 2012
课程名称︰编译程式设计
课程性质︰系必修
课程教师︰陈俊良
开课学院:电资学院
开课系所︰资讯工程系
考试日期(年月日)︰2012/6/21
考试时限(分钟):120min
是否需发放奖励金:是的,感谢
(如未明确表示,则不予发放)
试题 :
Please write your answer of question 1(a) in page 1 lines 01~10.
question 1(b) in page 1 lines 11~25.
question 1(c) in page 2 lines 01~15.
question 2(a) in page 2 lines 16~20.
question 2(b) in page 2 lines 21~25.
question 2(c) in page 2 lines 26~30.
1.The conditional operator ?: has three operand expressions; ? appears between
the first and second expressions, and : appears between the second and thrid
expressions. At run time, the first operand expression is evaluated first.
It it is true, then the second operand expression is chosen. If it is false,
then the third operand expression is chosen. The conditional operator is
syntactically right-associative, so that a?b:c?d:e?f:g means the same as
a?b:(C?d:(e?f:g)). The following is a set of possible grammar rules with
conditional expressions:
S -> id = E;
E -> P ? E : E
E -> P
P -> id
P -> ( E )
(a) Draw derivation trees for the following sentences.(3*5%)
a = b ? c : d ? e : f;
a = b ? c ? d : e : f;
a = (b ? c : d) ? e : f;
(b) Use the following IR instructions:
Assign rhs-data lhs-data
Label label
IfTrueGoto target-data label
IfFalseGoto target-data label
Goto label
to express the above 3 sentences. (3*5%)
(c) Give an L-attributed SDT to generate required IR.(30%)
2.C language allows the following function definitions:
void func1(int a[5][6]) {...}
void func2(int a[ ][6]) {...}
but doesn't allow the following ones:
void func3(int a[5][ ]) {...}
void func4(int a[ ][ ]) {...}
Furthermore, for func1, the size of the first dimension, i.e., 5, is not
required. It will be ignored by the compiler.
(a) Explain your reason for the above description. (10%)
(b) What are the differences between the allocation of a and b arrays in the
following C function.
Note that passing arrays to functions is call-by-reference for C language.
(20%)
void func1(int a[5][6]) {
int b[5][6];
...
}
(c) Is it legal for the following C language function call? Explain your reason
(10%)
int c[3][6];
func1(c);
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 140.112.30.42