1 生物計算期末作業 暨南大學資訊工程系 2003/05/13. 2 compare f1 f2...
Post on 18-Dec-2015
222 views
TRANSCRIPT
2
compare f1 f2 只比較兩個檔案 f1 與 f2 ,比完後將結果輸出。
compare directory 以兩兩比對的方式,比對一個目錄下所有檔案的相似程度。
將相似度很高的檔案做成報表輸出,報表中至少要包含 被判定相似程度很高的檔名清單。 被認定相似的總比數。 將所有檔名排序,並列出與哪些檔案相似。
9
將 input file 切割成 tokens
運用 operators 、 punctuations 、與 white spaces ,將 input file 切成 tokens : x1 = wide * sin(angle);x1
=wide*sin(angle);
11
建立 symbol table
我們將切出來的 tokens 全部建立在一個 symbol table 中,然後將 table 中的 tokens 編號。
在建 table 時,有幾點要注意: 先在 table 中內建 keywords 、 operators 、 punct
uations ,這樣可使得被內建的這些 tokens 有固定的 ID 。
所有 C/C++ 標準內建函式庫需要先建在 table 裡。 Scope 的問題先不處理,但如果同學要處理也是做得到的。
12
處理 identifiers 會遇到的問題
同一檔案中名字相同,但卻表示不同的變數: scoping 、 operator overloading 、 function name
overload 兩個要比較的檔案中,名稱不同但實際上卻相同的兩個 identifier 。 User defined functions
兩個要比較的檔案中,名稱一樣,而實際上也是相同的兩個名稱: C/C++ library
16
所以我們處理的方式是採取先內建一些標準 C/C++ 的identifiers 、 keywords 、 operators 、 punctuation 在 symbol table 中。
對於 user defined 的 identifiers ,降低 match/mismatch 的分數。
17
Keywords 的分類 Data type :
整數: int 、 short 、 signed 、 unsigned 、 long 浮點: float 、 double 、 long double 字串: char 、 char*
Flow control : for 、 while 、 do
幾乎是可以忽略的 keywords : auto 、 const 、 extern 、 register 、 static 、 volatil
e
同類的 keywords 比對時給分要比較高。