Program Translation: Compilers, Interpreters and Linkers – Grade 13 A/L ICT Notes 9.5

© 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

Prints all tabs in the language you are reading. Use “Save as PDF” in the print window to keep a copy.ඔබ කියවන භාෂාවෙන් සියලු tabs මුද්‍රණය වේ. පිටපතක් තියාගන්න print window එකේ “Save as PDF” තෝරන්න.
🎬Video coming soon in this language. Switch language to watch the other video.මේ භාෂාවෙන් වීඩියෝව ඉක්මනින් එනවා. අනෙක් වීඩියෝව බලන්න භාෂාව මාරු කරන්න.

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 සාදයි.
Source programObject programTranslatorCompilerInterpreterHybrid approachBytecode

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. පරිවර්තක

Program translatorsSource programCompilerObject programLinker →executableSource programInterpreterRuns lineby lineHybrid (Python, Java): compile to bytecode, then a virtual machine interprets it.
Compiler, interpreter, linker and hybridCompiler, interpreter, linker සහ මිශ්‍ර
Featureලක්ෂණයCompilerCompilerInterpreterInterpreter
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
🧮 Worked exampleවිසඳූ උදාහරණය Why does the bad program never run, while the division error appears only when running?bad වැඩසටහන කිසි විටෙක ධාවනය නොවන්නේ ඇයි?
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 ව්‍යාකරණ අතින් නිවැරදි නිසා පරිවර්තනය වේ; නමුත් ධාවන කාලයේ අසාර්ථක වේ.
💡 Source program = what you write; object program = translated machine code.මූලාශ්‍ර = ඔබ ලියන දේ; object = පරිවර්තිත යන්ත්‍ර කේතය.
🚀 Beyond the syllabus (2026 update)🚀 විෂය නිර්දේශයෙන් ඔබ්බට (2026 යාවත්කාලීනය) Not required for the exam – read for interest.විභාගයට අවශ්‍ය නැත – දැනුම සඳහා කියවන්න. In 2026 JavaScript engines and Python 3.13+ use just-in-time (JIT) compilation to speed up hot code while it runs.2026 දී JavaScript engines සහ Python 3.13+ ධාවනය අතරතුර JIT compilation භාවිත කරයි.

Key Wordsප්‍රධාන පද

Source programමූලාශ්‍ර වැඩසටහන
Program written by a programmer in a high-level language.ඉහළ මට්ටමේ භාෂාවෙන් ලියූ වැඩසටහන.
Object programObject වැඩසටහන
Machine code produced by translating source code.මූලාශ්‍ර කේතය පරිවර්තනයෙන් ලැබෙන යන්ත්‍ර කේතය.
Translatorපරිවර්තකය
Program that converts source code into machine code.මූලාශ්‍ර කේතය යන්ත්‍ර කේතයට හරවන වැඩසටහන.
CompilerCompiler
Translates the whole program before running.ධාවනයට පෙර සම්පූර්ණ වැඩසටහන පරිවර්තනය කරයි.
InterpreterInterpreter
Translates and runs one statement at a time.වරකට එක් ප්‍රකාශයක් පරිවර්තනය කර ධාවනය කරයි.
Hybrid approachමිශ්‍ර ක්‍රමය
Compile to bytecode then interpret it on a virtual machine.bytecode වෙත compile කර VM මත interpret කිරීම.
BytecodeBytecode
Intermediate code run by a virtual machine.virtual machine එකක් ධාවනය කරන අතරමැදි කේතය.
LinkerLinker
Joins object files and libraries into one executable.object ගොනු සහ libraries එක් executable එකක් කරයි.
AssemblerAssembler
Translates assembly language into machine code.assembly භාෂාව යන්ත්‍ර කේතයට හරවයි.
Syntax errorSyntax දෝෂය
Error in the grammar of the language found during translation.පරිවර්තනයේදී සොයාගන්නා භාෂා ව්‍යාකරණ දෝෂය.
Runtime errorධාවන කාල දෝෂය
Error that happens while the program is running.වැඩසටහන ධාවනය වන අතරතුර ඇතිවන දෝෂය.
Executable fileExecutable ගොනුව
File that the operating system can run directly.මෙහෙයුම් පද්ධතියට සෘජුව ධාවනය කළ හැකි ගොනුව.

Sample Q&Aආදර්ශ ප්‍රශ්න සහ පිළිතුරු

1Why is translation needed?පරිවර්තනය අවශ්‍ය ඇයි?

Answerපිළිතුර: The CPU understands only machine code.CPU යන්ත්‍ර කේතය පමණක් තේරුම් ගනී.

2Compiler vs interpreter?Compiler සහ interpreter?

Answerපිළිතුර: Compiler translates all first; interpreter one statement at a time.සම්පූර්ණයෙන්; එකින් එක.

3What is the hybrid approach?මිශ්‍ර ක්‍රමය?

Answerපිළිතුර: Compile to bytecode, then a virtual machine interprets it (Python, Java).bytecode; VM.

4What does a linker do?Linker කරන්නේ?

Answerපිළිතුර: Joins object files and libraries into an executable.object සහ libraries එකතු කරයි.

5Which line of the translate program is never run?ධාවනය නොවන්නේ?

Answerපිළිතුර: print(10 +) – it has a syntax error.print(10 +).

6Source vs object program?මූලාශ්‍ර සහ object?

Answerපිළිතුර: Source is written by people; object is translated machine code.ලියූ; පරිවර්තිත.

MCQබහුවරණ ප්‍රශ්න

Choose the correct answer for each question.සෑම ප්‍රශ්නයකටම නිවැරදි පිළිතුර තෝරන්න.

Scoreලකුණු: 0 / 20

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 පිළිතුරු

  1. A – Compiler.Compiler.
  2. A – Interpreter.Interpreter.
  3. B – Linker.Linker.
  4. E – Hybrid.මිශ්‍ර.
  5. B – Grammar.ව්‍යාකරණ.
  6. A – At run time.ධාවන කාලය.
  7. B – Source.මූලාශ්‍ර.
  8. C – Assembler.Assembler.
  9. D – Source program – Program written by a programmer in a high-level language.මූලාශ්‍ර වැඩසටහන – ඉහළ මට්ටමේ භාෂාවෙන් ලියූ වැඩසටහන.
  10. C – Object program – Machine code produced by translating source code.Object වැඩසටහන – මූලාශ්‍ර කේතය පරිවර්තනයෙන් ලැබෙන යන්ත්‍ර කේතය.
  11. D – Translator – Program that converts source code into machine code.පරිවර්තකය – මූලාශ්‍ර කේතය යන්ත්‍ර කේතයට හරවන වැඩසටහන.
  12. B – Compiler – Translates the whole program before running.Compiler – ධාවනයට පෙර සම්පූර්ණ වැඩසටහන පරිවර්තනය කරයි.
  13. D – Interpreter – Translates and runs one statement at a time.Interpreter – වරකට එක් ප්‍රකාශයක් පරිවර්තනය කර ධාවනය කරයි.
  14. E – Hybrid approach – Compile to bytecode then interpret it on a virtual machine.මිශ්‍ර ක්‍රමය – bytecode වෙත compile කර VM මත interpret කිරීම.
  15. C – Bytecode – Intermediate code run by a virtual machine.Bytecode – virtual machine එකක් ධාවනය කරන අතරමැදි කේතය.
  16. C – Linker – Joins object files and libraries into one executable.Linker – object ගොනු සහ libraries එක් executable එකක් කරයි.
  17. E – Assembler – Translates assembly language into machine code.Assembler – assembly භාෂාව යන්ත්‍ර කේතයට හරවයි.
  18. A – Syntax error – Error in the grammar of the language found during translation.Syntax දෝෂය – පරිවර්තනයේදී සොයාගන්නා භාෂා ව්‍යාකරණ දෝෂය.
  19. E – Runtime error – Error that happens while the program is running.ධාවන කාල දෝෂය – වැඩසටහන ධාවනය වන අතරතුර ඇතිවන දෝෂය.
  20. 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ආදර්ශ පිළිතුර පෙන්වන්න
CPU understands machine code only; high-level code must be converted.යන්ත්‍ර කේතය පමණි; හැරවිය යුතුය.

2Compare compilers and interpreters (three points).Compiler සහ interpreter. (3 marksලකුණු 3)

Show model answerආදර්ශ පිළිතුර පෙන්වන්න
Whole vs line; object file vs none; error reporting/speed.සම්පූර්ණ/එකින්; ගොනුව; වේගය.

3Describe the hybrid approach used by Python.මිශ්‍ර ක්‍රමය. (3 marksලකුණු 3)

Show model answerආදර්ශ පිළිතුර පෙන්වන්න
Source to bytecode; virtual machine interprets; portable.bytecode; VM; ගෙන යා හැකි.

4Explain the function of a linker.Linker ශ්‍රිතය. (3 marksලකුණු 3)

Show model answerආදර්ශ පිළිතුර පෙන්වන්න
Combines object modules and libraries; resolves calls; makes executable.එකතු කිරීම; executable.

5Distinguish syntax and runtime errors with Python examples.Syntax සහ runtime. (2 marksලකුණු 2)

Show model answerආදර්ශ පිළිතුර පෙන්වන්න
print(10 +) syntax; 10 / 0 runtime.print(10 +); 10 / 0.

🎮 Game🎮 ක්‍රීඩා

Pick a game. Each one uses words from this lesson.ක්‍රීඩාවක් තෝරන්න. හැම එකක්ම මේ පාඩමේ වචන පාවිච්චි කරනවා.

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බාගත කිරීම්

Full Lesson 9 PDFසම්පූර්ණ පාඩම 9 PDF: English · සිංහල

Next noteඊළඟ සටහන 9.6 →

© 2026 schoolict.net (Ruwan Mangala Suraweera). All rights reserved.සියලු හිමිකම් ඇවිරිණි.

Resource Book Lesson Note Download Questions Syllabus Sinhala LMS Simulator Tool