Tuesday, January 17, 2012

Compiler හඳුනා ගනිමු.

Computers වල ඇති Complexity එක නිසා සාපේක්ෂව සරළ Commands භාවිතා කළ හැකි පරිදි Computers designing and building කරනු ලැබේ.Computer Program එකක් එම සරළ Commands එකතු කර සාදනු ලැබේ. මෙම Computer Programs execute කිරීමට සරළ Commands --> machine language එකට පරිවර්තනය කළ යුතුය. ඒ සඳහා Compilers භාවිතා කෙරේ.

Phases of a Compiler.

Lexical Analysis : Program text එක tokens වලට බෙදනු ලැබේ. eg: variable name, keyword

Syntax Analysis : Lexical Analysis වලින් ලැබෙන tokens මේ සඳහා input ලෙස භාවිතා වේ. මෙම tokens වලින් tree structure (syntax tree)bඑකක් සාදයි. මෙම ක්‍රියාවලිය parsing ලෙස හදුන්වයි.

Type Checking : Syntax tree එක Analyse කරනු ලැබේ. මෙහිදී consistency requirements කඩ වී ඇතිදැයි පරීක්ෂා කරනු ලැබේ. eg: variable එකක් නොසාදා use කිරීම.

Intermediate Code Generation : Program එක machine independent අතරමැදි language එකකට පරිවර්තනය කරනු ලැබේ.

Register Allocation : Intermediate code එකෙහි භාවිතා කර ඇති සෑම symbolic variable name එකක්ම target machine code එකෙහි ඇති register එකකට අනුරූප number එකකට පරිවර්තනය කරනු ලැබේ.

Machine Code Generation : Intermediate language එක machine එක සඳහා specific Assembly language  (Textual representation of machine code) එකට පරිවර්තනය කරනු ලැබේ.

Assembly and Linking : Assembly language code එක binary representation එකට පරිවර්තනය කරනු ලැබේ. මෙහිදී variables සහ functions වල addresses තීරණය කිරීමද සිදුවේ.

පළමු phases තුන "front end" of the compiler ලෙස හැදින්වේ. අවසාන phases තුන "backend" ලෙස හැදින්වේ. Assembly and linking කොටස සාමාන්‍යයෙන් OS vendor programs  කරනු ලැබේ. එම නිසා compiler එකක් තුළ මෙම phase එක නොමැත.

No comments:

Post a Comment