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