2007-06-16

【9X-下】黃志銘-系統程式(期末考)

感謝宗沂大大在國軍Online數饅頭的閒暇之虞把考古題內容一字一字的Key完。
不過這份考古年份久遠...效用不知道好不好就是了XD

1. What is the most important difference between a macro and a subroutine? How should a programmer decide whether to use a macro or a subroutine to accomplish a given logical function? (10%)


2. Draw a state diagram for a finite automation to recognize the following tokens: (20%)
(a )Signed integer (e.g. +123 or 6789 0r -15): This integer may begin with a sign (+ or -) or not; however, they may not begin with the digit 0 (except for the integer that consists of a single 0)
(b )Real constant (e.g. -0.38 or 123.50): This real constant may begin with a sign (+ or -) or not; and consists of a string of digits that contains a decimal point. There must be at least one degit before the decimal point.


3. Consider the following grammar: ::= id := ; ::= id * | id * ::= id + | () | id Assume that the scanner will report token type id when it sees a valid Pascal identifier. Which of the following strings is a valid sentence (i.e. ) in the language generated by this grammar?(10%)
(1)ALBERT := B + C;
(2)D := B * C;
(3)X := B + (C * D + E);
(4)A := B + (C * D);
(5)P := B + (C * D) + E;
Please give a BNF gramma for such statements, providing for default right-to-left precedence and parentheses. (20%)


4. In APL all expressions are evaluated from right to left with no precedence associated with any of the operators. Parenthese may be use to change this difault precedence. In the following "toy" version, suppose that + and * are the only legal operators. Thus, A <- 3 * 3 + 4 would put the result of 3 * 7 into A. A <- (3 * 3) + 4 would add 3 * 3 to 4 and put the result into A.
Please give a BNF gramma for such statements, providing for default right-to-left precedence and parentheses. (20%)


5. Apply an expand the following two macro invocation statements to the following macro defination: (20%)
(1) RDBUFF F1, BUFFER, LENGTH, (04, 12)
(2) LABEL RDBUFF F1, BUFFER, LENGTH, 00
Macro defination:
25 RDBUFF MACRO &INDEV, &amp;BUFADR, &RECLTH, &EOR
27 &EORCT SET %NITEMS(&amp;EOR)
30 CLEAR X
35 CLEAR A
45 +LDT #4096
50 $LOOP TD =X'&INDEV'
55 JEQ $LOOP
60 RD =X'&INDEV'
63 &CLR SET 1
64 WHILE (&amp;CLR LE &EORCT)
65 COMP =X'0000&EOR[&CTR]'
70 JEQ $EXIT
71 &CTR SET &CTR+1
73 ENDW
75 STCH &BUFADR, X
80 TIXR T
85 JLT $LOOP
90 EXIT STX &RECLTH
100 MEND


6. Suppose that the following macro definitions appeared at the beginning of a SIC/XE program. (20%)
(1)Show the contents of NAMTAB and DEFTAB just after this code is scanned by the macro processor. (Pointer values are given as line number into DEFTAB)
(2)Now suppose that right after these definitions, the macro processor scans a line that says: MACROS Show the contents of NAMTAB and DEFTAB now.
1 MACROS MACRO
2 RDBUFF MACRO &amp;INDEV, &BUFADR, &RECLTH
3 LDS &BUFADR
4 MEND
5 WRBUFF MACRO &amp;OUTDEV, &BUFADR, &RECLTH
6 LDS &BUFADR
7 MEND
8 MEND
9 MACROX MACRO
10 RDBUFF MACRO &amp;INDEV, &BUFADR, &RECLTH
11 LDT &BUFADR
12 MEND
13 WRBUFF MACRO &OUTDEV, &BUFADR, &RECLTH
14 LDT &BUFADR
15 MEND
16 MEND

【關鍵字:9X-下、黃志銘、系統程式、期末考、考古題】

沒有留言: