請根據下列文法畫出輸入字串abbddeffccg 所有可能的文法樹(亦稱文法剖析樹、剖析樹)。並請討論此文法的問題。(20分)
S → a X g
X → b X
X → b X c
X → b X c c
X → Y
Y → d Y
Y → d Y f
Y → d Y f f
Y → e
題型:申論題
難易度:尚未記錄
2.
請用下例說明在Java程式語言裡,dynamic dispatching的意義與運作方式。並且說明最後印出的報表為何?(20分)
import java.lang.*;
class test24 {
public static void main(String[] arg) {
B b = new C();
R r = new S();
System.out.println("r.m(b) = " + r.m(b) );
}
}
class A { }
class B extends A { }
class C extends B { }
class P {
int m(B x) { return 1; }
}
class Q extends P {
int m(A x) { return 2; }
}
class R extends Q {
int m(C x) { return 3; }
}
class S extends R {
int m(B x) { return 4; }
int m(C x) { return 5; }
}
題型:申論題
難易度:尚未記錄
3.
在C程式語言裡,我們可以使用union type。請舉例說明何謂union type。在物件導向程式語言裡,如Java,我們如何達成union type 相同的效果?請用你所提出的方法,改寫你所提出的union type 的範例。(20分)
題型:申論題
難易度:尚未記錄
4.
新的程式語言都會提供例外處理(exception handling)。請說明下列Java 程式做例外處理的可能流程。並且請說明finally clause 的執行過程。(20分)
public void writelist() throws ArrayIndexOutOfBoundsException {
PrintStream pStr = null;
try {
pStr = new PrintStream(
new BufferedOutputStream(
new FileOutputSteam("outfile")));
pStr.println("The 9th element is " +
victor.elementAt(9));
} catch (IOException e) {
System.err.println("i/o error");
} finally {
if (pStr != null) pStr.close();
}
}