【正文】
– 注:在內(nèi)存許可情況下,還是遍數(shù)盡可能少些為好。 一個編譯系統(tǒng)可以看成是一個變換系統(tǒng),進(jìn)行一系列的變換,即 (SL, L1), (L1, L2),….( Lk, TL) 其中 SL為源語言, TL為目標(biāo)語言 2020/6/28 55 Number of Passes: Single Preferred Multiple Easier, but less efficient Tradeoffs …….. 遍 (pass) ? 多遍掃描的好處 – 節(jié)省內(nèi)存空間,提高目標(biāo)代碼質(zhì)量,使編譯的邏輯結(jié)構(gòu)清晰。 – 注:在內(nèi)存許可情況下,還是遍數(shù)盡可能少些為好。 ? 多遍掃描的好處 – 節(jié)省內(nèi)存空間,提高目標(biāo)代碼質(zhì)量,使編譯的邏輯結(jié)構(gòu)清晰。 2020/6/28 53 遍 (pass) ? 遍:指對源程序或源程序的中間結(jié)果從頭到尾掃描一次,并做有關(guān)的加工處理,生成新的中間結(jié)果或目標(biāo)代碼的過程。典型的編譯程序一般遍數(shù)在二至三遍。所謂一遍是指,編譯程序以一種表示形式為輸入,經(jīng)過處理產(chǎn)生下一種表示形式的過程。主要包括代碼優(yōu)化、代碼生成等。 后端 包括依賴于目標(biāo)機(jī)器的階段。 2020/6/28 40 錯誤處理 單詞錯 語法錯 語義錯 (如多重定義、類型不匹配) 環(huán)境錯 (如數(shù)組太大、名字太長) 溢出 外設(shè)錯誤 ( I/O錯) 訪問內(nèi)存越界 編譯 錯誤 運(yùn)行錯誤 邏輯錯誤 錯誤分類 2020/6/28 41 Compiler Cousins ? Preprocessors : Provide Input to Compilers – Macro Processing – File Inclusion – Rational Preprocessors – Language Extensions for a Database System ? Assemblers ? Loaders and LinkEditors 2020/6/28 42 define in C: does text substitution before piling define X 3 define Y A*B+C define Z getchar() Macro Processing 2020/6/28 43 File Inclusion include in C bring in another file before piling ////// ////// ////// include “” … … … … … … … … … ////// ////// ////// … … … … … … … … … 2020/6/28 44 Rational Preprocessors ? Augment ―Old‖ Languages With Modern Constructs ? Add Macros for If Then, While, Etc. ? Define Can Make C Code More Pascallike define begin { define end } define then 2020/6/28 45 Language Extensions for a Database System EQUEL Database query language embedded in C Retrieve (DN=) where = ?Research? is Preprocessed into: ingres_system(“Retr…..Research?”,____,____)。 2020/6/28 39 符號表管理 ? 符號表存放與單詞有關(guān)的信息,如標(biāo)識符的類型、地址,常數(shù)的值等等。 ? 代碼生成:生成等價的匯編或機(jī)器語言程序。