© 2026 schoolict.net (Ruwan Mangala Suraweera)
9.5 Program Translation: Compilers, Interpreters and Linkersවැඩසටහන් පරිවර්තනය: Compilers, Interpreters සහ Linkers
Grade 13 A/L ICT · Lesson 913 ශ්රේණිය A/L ICT · පාඩම 9
In this videoමේ වීඩියෝවේ
- Source code must be translated to machine code.මූලාශ්ර කේතය යන්ත්ර කේතයට හැරවිය යුතුය.
- Compilers translate the whole program.Compiler සම්පූර්ණ වැඩසටහන හරවයි.
- Interpreters translate statement by statement.Interpreter ප්රකාශයෙන් ප්රකාශය හරවයි.
- Python is hybrid: bytecode + virtual machine.Python මිශ්රයි: bytecode + VM.
- Linkers build the final executable.Linker අවසන් executable සාදයි.
Notesසටහන්
Syllabus 9.5. A CPU understands only machine code, so a source program written in a high-level language must be translated. Compilers translate the whole program into an object program; interpreters translate and run one statement at a time; the hybrid approach compiles to bytecode that a virtual machine interprets. Linkers join object code and libraries into one executable.විෂය නිර්දේශය 9.5. CPU තේරුම් ගන්නේ යන්ත්ර කේතය පමණක් නිසා ඉහළ මට්ටමේ මූලාශ්ර වැඩසටහනක් පරිවර්තනය කළ යුතුය. Compiler සම්පූර්ණ වැඩසටහන object program එකක් බවට හරවයි; interpreter වරකට එක් ප්රකාශයක් පරිවර්තනය කර ධාවනය කරයි; මිශ්ර ක්රමය bytecode බවට compile කර virtual machine මගින් interpret කරයි. Linker object කේත සහ libraries එක් executable එකක් කරයි.
1. Translators1. පරිවර්තක
| Featureලක්ෂණය | CompilerCompiler | InterpreterInterpreter |
|---|---|---|
| Translatesපරිවර්තනය | Whole program at onceසම්පූර්ණ වැඩසටහනම එකවර | One statement at a timeවරකට එක් ප්රකාශයක් |
| Outputප්රතිදානය | Object/executable fileObject/executable ගොනුව | No separate fileවෙනම ගොනුවක් නැත |
| Speed of runningධාවන වේගය | Fast after compilingcompile පසු වේගවත් | Slowerමන්දගාමී |
| Errorsදෝෂ | Listed after translationපරිවර්තනයෙන් පසු ලැයිස්තුව | Stops at the first errorපළමු දෝෂයේ නවතී |
| Examplesඋදාහරණ | C, C++C, C++ | JavaScript (classic), BASICJavaScript, BASIC |
2. Python uses the hybrid approach2. Python මිශ්ර ක්රමය භාවිත කරයි
🐍 Syntax error found before running vs runtime errorධාවනයට පෙර syntax දෝෂය සහ ධාවන දෝෂය
good = "x = 10\nprint(x * 2)" bad = "print(10 +)" code = compile(good, "good.py", "exec") # translate to bytecode exec(code) try: compile(bad, "bad.py", "exec") except SyntaxError: print("Syntax error: not translated") try: print(10 / 0) except ZeroDivisionError: print("Runtime error: division by zero")
▶ Outputප්රතිදානය
20 Syntax error: not translated Runtime error: division by zero
compile() translates source to bytecode first. “print(10 +)” breaks the grammar, so translation fails with a syntax error and nothing runs. 10 / 0 is grammatically correct, so it is translated, but fails at run time.compile() මුලින් bytecode බවට පරිවර්තනය කරයි. “print(10 +)” ව්යාකරණ දෝෂයක් නිසා syntax error එකක් ඇති වී කිසිවක් ධාවනය නොවේ. 10 / 0 ව්යාකරණ අතින් නිවැරදි නිසා පරිවර්තනය වේ; නමුත් ධාවන කාලයේ අසාර්ථක වේ.
Key Wordsප්රධාන පද
Sample Q&Aආදර්ශ ප්රශ්න සහ පිළිතුරු
1Why is translation needed?පරිවර්තනය අවශ්ය ඇයි?
2Compiler vs interpreter?Compiler සහ interpreter?
3What is the hybrid approach?මිශ්ර ක්රමය?
4What does a linker do?Linker කරන්නේ?
5Which line of the translate program is never run?ධාවනය නොවන්නේ?
6Source vs object program?මූලාශ්ර සහ object?
MCQබහුවරණ ප්රශ්න
Choose the correct answer for each question.සෑම ප්රශ්නයකටම නිවැරදි පිළිතුර තෝරන්න.
1A translator that converts the whole program before running is aසම්පූර්ණ
✔ Correct!නිවැරදියි!✘ Not quite.වැරදියි. Correct answerනිවැරදි පිළිතුර: A
Compiler.Compiler.
2A translator that runs one statement at a time is anඑකින් එක
✔ Correct!නිවැරදියි!✘ Not quite.වැරදියි. Correct answerනිවැරදි පිළිතුර: A
Interpreter.Interpreter.
3Joining object code with libraries is done by alibraries
✔ Correct!නිවැරදියි!✘ Not quite.වැරදියි. Correct answerනිවැරදි පිළිතුර: B
Linker.Linker.
4Python and Java translate to bytecode first; this is thebytecode
✔ Correct!නිවැරදියි!✘ Not quite.වැරදියි. Correct answerනිවැරදි පිළිතුර: E
Hybrid.මිශ්ර.
5print(10 +) produces aprint(10 +)
✔ Correct!නිවැරදියි!✘ Not quite.වැරදියි. Correct answerනිවැරදි පිළිතුර: B
Grammar.ව්යාකරණ.
610 / 0 in Python produces a10 / 0
✔ Correct!නිවැරදියි!✘ Not quite.වැරදියි. Correct answerනිවැරදි පිළිතුර: A
At run time.ධාවන කාලය.
7The program written by the programmer is theලියූ
✔ Correct!නිවැරදියි!✘ Not quite.වැරදියි. Correct answerනිවැරදි පිළිතුර: B
Source.මූලාශ්ර.
8Assembly language is translated by anassembly
✔ Correct!නිවැරදියි!✘ Not quite.වැරදියි. Correct answerනිවැරදි පිළිතුර: C
Assembler.Assembler.
9Which term means: “Program written by a programmer in a high-level language”?“ඉහළ මට්ටමේ භාෂාවෙන් ලියූ වැඩසටහන” යන්නෙන් අදහස් වන පදය කුමක්ද?
✔ Correct!නිවැරදියි!✘ Not quite.වැරදියි. Correct answerනිවැරදි පිළිතුර: D
Source program – Program written by a programmer in a high-level language.මූලාශ්ර වැඩසටහන – ඉහළ මට්ටමේ භාෂාවෙන් ලියූ වැඩසටහන.
10Which term means: “Machine code produced by translating source code”?“මූලාශ්ර කේතය පරිවර්තනයෙන් ලැබෙන යන්ත්ර කේතය” යන්නෙන් අදහස් වන පදය කුමක්ද?
✔ Correct!නිවැරදියි!✘ Not quite.වැරදියි. Correct answerනිවැරදි පිළිතුර: C
Object program – Machine code produced by translating source code.Object වැඩසටහන – මූලාශ්ර කේතය පරිවර්තනයෙන් ලැබෙන යන්ත්ර කේතය.
11Which term means: “Program that converts source code into machine code”?“මූලාශ්ර කේතය යන්ත්ර කේතයට හරවන වැඩසටහන” යන්නෙන් අදහස් වන පදය කුමක්ද?
✔ Correct!නිවැරදියි!✘ Not quite.වැරදියි. Correct answerනිවැරදි පිළිතුර: D
Translator – Program that converts source code into machine code.පරිවර්තකය – මූලාශ්ර කේතය යන්ත්ර කේතයට හරවන වැඩසටහන.
12Which term means: “Translates the whole program before running”?“ධාවනයට පෙර සම්පූර්ණ වැඩසටහන පරිවර්තනය කරයි” යන්නෙන් අදහස් වන පදය කුමක්ද?
✔ Correct!නිවැරදියි!✘ Not quite.වැරදියි. Correct answerනිවැරදි පිළිතුර: B
Compiler – Translates the whole program before running.Compiler – ධාවනයට පෙර සම්පූර්ණ වැඩසටහන පරිවර්තනය කරයි.
13Which term means: “Translates and runs one statement at a time”?“වරකට එක් ප්රකාශයක් පරිවර්තනය කර ධාවනය කරයි” යන්නෙන් අදහස් වන පදය කුමක්ද?
✔ Correct!නිවැරදියි!✘ Not quite.වැරදියි. Correct answerනිවැරදි පිළිතුර: D
Interpreter – Translates and runs one statement at a time.Interpreter – වරකට එක් ප්රකාශයක් පරිවර්තනය කර ධාවනය කරයි.
14Which term means: “Compile to bytecode then interpret it on a virtual machine”?“bytecode වෙත compile කර VM මත interpret කිරීම” යන්නෙන් අදහස් වන පදය කුමක්ද?
✔ Correct!නිවැරදියි!✘ Not quite.වැරදියි. Correct answerනිවැරදි පිළිතුර: E
Hybrid approach – Compile to bytecode then interpret it on a virtual machine.මිශ්ර ක්රමය – bytecode වෙත compile කර VM මත interpret කිරීම.
15Which term means: “Intermediate code run by a virtual machine”?“virtual machine එකක් ධාවනය කරන අතරමැදි කේතය” යන්නෙන් අදහස් වන පදය කුමක්ද?
✔ Correct!නිවැරදියි!✘ Not quite.වැරදියි. Correct answerනිවැරදි පිළිතුර: C
Bytecode – Intermediate code run by a virtual machine.Bytecode – virtual machine එකක් ධාවනය කරන අතරමැදි කේතය.
16Which term means: “Joins object files and libraries into one executable”?“object ගොනු සහ libraries එක් executable එකක් කරයි” යන්නෙන් අදහස් වන පදය කුමක්ද?
✔ Correct!නිවැරදියි!✘ Not quite.වැරදියි. Correct answerනිවැරදි පිළිතුර: C
Linker – Joins object files and libraries into one executable.Linker – object ගොනු සහ libraries එක් executable එකක් කරයි.
17Which term means: “Translates assembly language into machine code”?“assembly භාෂාව යන්ත්ර කේතයට හරවයි” යන්නෙන් අදහස් වන පදය කුමක්ද?
✔ Correct!නිවැරදියි!✘ Not quite.වැරදියි. Correct answerනිවැරදි පිළිතුර: E
Assembler – Translates assembly language into machine code.Assembler – assembly භාෂාව යන්ත්ර කේතයට හරවයි.
18Which term means: “Error in the grammar of the language found during translation”?“පරිවර්තනයේදී සොයාගන්නා භාෂා ව්යාකරණ දෝෂය” යන්නෙන් අදහස් වන පදය කුමක්ද?
✔ Correct!නිවැරදියි!✘ Not quite.වැරදියි. Correct answerනිවැරදි පිළිතුර: A
Syntax error – Error in the grammar of the language found during translation.Syntax දෝෂය – පරිවර්තනයේදී සොයාගන්නා භාෂා ව්යාකරණ දෝෂය.
19Which term means: “Error that happens while the program is running”?“වැඩසටහන ධාවනය වන අතරතුර ඇතිවන දෝෂය” යන්නෙන් අදහස් වන පදය කුමක්ද?
✔ Correct!නිවැරදියි!✘ Not quite.වැරදියි. Correct answerනිවැරදි පිළිතුර: E
Runtime error – Error that happens while the program is running.ධාවන කාල දෝෂය – වැඩසටහන ධාවනය වන අතරතුර ඇතිවන දෝෂය.
20Which term means: “File that the operating system can run directly”?“මෙහෙයුම් පද්ධතියට සෘජුව ධාවනය කළ හැකි ගොනුව” යන්නෙන් අදහස් වන පදය කුමක්ද?
✔ Correct!නිවැරදියි!✘ Not quite.වැරදියි. Correct answerනිවැරදි පිළිතුර: D
Executable file – File that the operating system can run directly.Executable ගොනුව – මෙහෙයුම් පද්ධතියට සෘජුව ධාවනය කළ හැකි ගොනුව.
MCQ answer keyMCQ පිළිතුරු
- A – Compiler.Compiler.
- A – Interpreter.Interpreter.
- B – Linker.Linker.
- E – Hybrid.මිශ්ර.
- B – Grammar.ව්යාකරණ.
- A – At run time.ධාවන කාලය.
- B – Source.මූලාශ්ර.
- C – Assembler.Assembler.
- D – Source program – Program written by a programmer in a high-level language.මූලාශ්ර වැඩසටහන – ඉහළ මට්ටමේ භාෂාවෙන් ලියූ වැඩසටහන.
- C – Object program – Machine code produced by translating source code.Object වැඩසටහන – මූලාශ්ර කේතය පරිවර්තනයෙන් ලැබෙන යන්ත්ර කේතය.
- D – Translator – Program that converts source code into machine code.පරිවර්තකය – මූලාශ්ර කේතය යන්ත්ර කේතයට හරවන වැඩසටහන.
- B – Compiler – Translates the whole program before running.Compiler – ධාවනයට පෙර සම්පූර්ණ වැඩසටහන පරිවර්තනය කරයි.
- D – Interpreter – Translates and runs one statement at a time.Interpreter – වරකට එක් ප්රකාශයක් පරිවර්තනය කර ධාවනය කරයි.
- E – Hybrid approach – Compile to bytecode then interpret it on a virtual machine.මිශ්ර ක්රමය – bytecode වෙත compile කර VM මත interpret කිරීම.
- C – Bytecode – Intermediate code run by a virtual machine.Bytecode – virtual machine එකක් ධාවනය කරන අතරමැදි කේතය.
- C – Linker – Joins object files and libraries into one executable.Linker – object ගොනු සහ libraries එක් executable එකක් කරයි.
- E – Assembler – Translates assembly language into machine code.Assembler – assembly භාෂාව යන්ත්ර කේතයට හරවයි.
- A – Syntax error – Error in the grammar of the language found during translation.Syntax දෝෂය – පරිවර්තනයේදී සොයාගන්නා භාෂා ව්යාකරණ දෝෂය.
- E – Runtime error – Error that happens while the program is running.ධාවන කාල දෝෂය – වැඩසටහන ධාවනය වන අතරතුර ඇතිවන දෝෂය.
- D – Executable file – File that the operating system can run directly.Executable ගොනුව – මෙහෙයුම් පද්ධතියට සෘජුව ධාවනය කළ හැකි ගොනුව.
Structured Questionsව්යුහගත ප්රශ්න
1Explain why program translation is needed.පරිවර්තනයේ අවශ්යතාව. (2 marksලකුණු 2)
Show model answerආදර්ශ පිළිතුර පෙන්වන්න
2Compare compilers and interpreters (three points).Compiler සහ interpreter. (3 marksලකුණු 3)
Show model answerආදර්ශ පිළිතුර පෙන්වන්න
3Describe the hybrid approach used by Python.මිශ්ර ක්රමය. (3 marksලකුණු 3)
Show model answerආදර්ශ පිළිතුර පෙන්වන්න
4Explain the function of a linker.Linker ශ්රිතය. (3 marksලකුණු 3)
Show model answerආදර්ශ පිළිතුර පෙන්වන්න
5Distinguish syntax and runtime errors with Python examples.Syntax සහ runtime. (2 marksලකුණු 2)
Show model answerආදර්ශ පිළිතුර පෙන්වන්න
🎮 Game🎮 ක්රීඩා
Summary & Downloadsසාරාංශය සහ බාගත කිරීම්
Key pointsප්රධාන කරුණු
- Source code must be translated to machine code.මූලාශ්ර කේතය යන්ත්ර කේතයට හැරවිය යුතුය.
- Compilers translate the whole program.Compiler සම්පූර්ණ වැඩසටහන හරවයි.
- Interpreters translate statement by statement.Interpreter ප්රකාශයෙන් ප්රකාශය හරවයි.
- Python is hybrid: bytecode + virtual machine.Python මිශ්රයි: bytecode + VM.
- Linkers build the final executable.Linker අවසන් executable සාදයි.
Downloadsබාගත කිරීම්
Resource Book Lesson Note Download Questions Syllabus Sinhala LMS Simulator Tool
