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-下、黃志銘、系統程式、期末考、考古題】

2007-06-13

電腦相關領域電子書

  無意間發現的網路好康-(電腦相關領域)電子書下載。
  Link:http://kickjava.com/books/

2007-06-12

Unix期末作業總整理

作業一:試找knight主機上非使用csh之帳號數
提示:使用grep 指令
輸出:僅有一個數字
限制:
1. 請以一行指令完成
2. 須排除錯誤訊息

> more /etc/passwd | grep -vc /csh
==================================================================================


作業二:試將資工94級學生帳號,複製到新主機。
使用vi編輯器
1. 將帳號前字元 d 改為 cs
2. 將HOME Directory由 /student/stu3/94/cs/dxxxxxx 路徑改為/student/94/csxxxxxx
3. 並將default shell: /bin/csh 改為 /bin/bash

> grep /stu3/94/cs/ /etc/passwd > homework.txt
:1,$ s/d/cs/g
:1,$ s/stu3\/
:1,$ s/csh/bash
==================================================================================


作業一:試找knight主機上學生目錄下core dump檔案數。
提示:使用find 指令
假設與限制:
1. 目標為 /student/stu3/94。
2. 判定方式以 “core”檔名為準。
3. 輸出僅有一個數字。
4. 請以一行指令完成並須排除錯誤訊息。

# find /student/stu3/94 -name core 2>/dev/null | wc -l
==================================================================================


作業二:試寫一shell script,能搜尋並取代所指定檔案中特定字串。
範例:./myreplace d cs file1 file2
假設與要求:共四個參數
1. d, cs 為所欲置換字串。
2. file1 為輸入檔名,以knight主機中密碼檔 (/etc/passwd) 部份內容。
3. file2 為輸出檔名。

#!/bin/bash

`sed -n 's/'$1'/'$2'/gp' $3> $4`
==================================================================================


作業:試寫一具功能選單之shell script。
Design a menu like as:
Current directory is "/student/stu4/93/cs"
1. Sum of online Users
2. List our Classmates
3. Broadcast a message to the idle Users
0. Quit
Enter choice [1]:
說明:
1. 列出目前線上使用者數目
2. 列出本班同學清單與總數
3. 廣播一警訊給idle 時間超過5 minutes的使用者
0. 離開


echo "Current directory is"$PWD

n=1

while [ "$n" -lt 10 ]
do
echo "1. Sum of online Users"
echo "2. List our Classmates"
echo "3. Broadcast a message to the idle Users"
echo "0. Quit"
echo "choice [0]:"
read choice
clear
case $choice in
0) break ;;
1)
echo "Total online number: " `who | wc -l`
;;
2)
echo "Show the online user of our classmates."
echo `who | grep pcroom`
echo "Number:"`who | grep pcroom | wc -l`;;
3) `uname > oo`
who -u | awk '{print $1, $6}' | grep -v [.] | grep -v '[0-4]:[0-9][0-9]' | awk '{print $1}' | awk '{print "`write",$1,"<> tt
`chmod 777 tt`
`./tt`
`rm tt oo`
;;
*) break ;;
esac
echo "========================================"
echo "++++++++++++++++++++++++++++++++++++++++"
echo "========================================"
echo
done

【關鍵字:Unix實務應用、劉嘉政、95-上、期末作業】

2007-06-10

Train Surfing

  Train Surfing(火車衝浪),這名詞似乎很神奇,火車跟衝浪兩個看似毫不相關的名詞怎麼可以這樣兜在一起?!不過這是南非青年的喜好運動之一。簡單來說,就是在火車車廂外頭作出各種危險的行為,像是站在火車車頂閃躲上方的高壓電線、將身體探出車廂外...等。

  Train Surfing近日在國內成為重點新聞,不過這行為應該已經行之有年了,沒記錯的話李家同教授某本著作中就提過這樣的問題。
  以下引述,「在南非城市索維托的郊區,這個「遊戲」在半大青年中的流行程度,超過你我的想像,當地人還給它起了非常浪漫的名字:「火車衝浪」(train surfing)。最初,當地年輕人攀上火車,確實是為扒竊車上搭載的貨物。慢慢地,扒竊高手成了飛車「大師」,越來越多年輕人加入到飛車族的行列,逐漸把它變成一種「運動」。大家發現,這種整天飛一樣遊走於死亡邊緣的「運動」,可以讓自己暫時忘卻眼前的窮困,以及毫無希望的未來。」(窮困讓我飛翔 作者:柏子

2007-06-04

Advanced Linux Programming

  上Unix時劉老介紹的網站,正確說法是強迫接受...很讚的東西。「Advanced Linux Programming」是一本書名,其內容名符其實就是介紹Linux上的程式(C/C++)寫作,這本書是一群作者合力完成的,這些作者也很讚...把這本書的所有內容都放上網路了,網頁上註明書本版權Open Publication License,也就是可以隨意拿去書局「拷貝」!

  Link:http://www.advancedlinuxprogramming.com/