Presentation is loading. Please wait.

Presentation is loading. Please wait.

What am I?. Translators Translators – Module Knowledge Areas Types of translators and their use Lexical analysis Syntax analysis Code generation and.

Similar presentations


Presentation on theme: "What am I?. Translators Translators – Module Knowledge Areas Types of translators and their use Lexical analysis Syntax analysis Code generation and."— Presentation transcript:

1 What am I?

2 Translators

3 Translators – Module Knowledge Areas Types of translators and their use Lexical analysis Syntax analysis Code generation and optimisation Library routines

4 Translators – Module Learning Objectives describe the need for, and use of, translators to convert source code to object code understand the relationship between assembly language and machine code describe the use of an assembler in producing machine code describe the difference between interpretation and compilation describe the purpose of intermediate code in a virtual machine describe what happens during lexical analysis describe what happens during syntax analysis, explaining how errors are handled explain the code generation phase and understand the need for optimisation describe the use of library routines

5 Translators Describe the need for, and use of, translators to convert source code to object code What is source code? Source code is the program instructions you as a programmer create eg print(“The Game of Jones”) is the source code for a Python program As this is written in a high level language it is meaningless to a computer – it must be translated into object code So, what is object code?

6 Translators – Example Try this: import dis def objectMe() num1 = 8 num2 = 9 print(num1 * num2) Run it and at the chevron input dis.dis(objectMe)

7 Translators – Object Code Output Notice the use of mnemonics to call modules eg LOAD_CONST The numbers just before the mnemonics refer to byte offset

8 Translators – Process Congratulations, you have created object code The process was: Create source code – the Python script Run – compiles the code (we used the dis module to disassemble the bytecode) The bytecode/object code (compiled code) is executed by the Python virtual machine Bytecode is converted to machine code Simple View Actual View

9 Translators – Why? TASK – WHY OBJECT CODE? Why do we need object code? Using your disassembled code, what is being shown? What is the relationship between source code, object code and a virtual machine? Complete in “Why object code?” in Moodle

10 Translators – Debugging Try this: import dis a = 4 b = b + 4 After the chevron input: dis.distb() What has happended?

11 Translators – Debugging What is the red text telling you? How can we use the object code view to assist with debugging?

12 Translators – Module Learning Objectives So, why translators? We have already seen that Python source code is assembled into byte code / object code The object code separates the source code into a series of instructions. Object code is also referred to as intermediate code. Intermediate because it sits between High Level source code and machine code. The assembler translates the object code into machine code Object code instructions are readable by the virtual machine The virtual machine is independent of hardware (eg 32/64 bit machines, Windows/IOS, RISC/CISC) The translation into object code is an opportunity for the syntax to be verified. Python has an IDE that will flag syntax errors. This is an example of translator diagnostics (the problem is diagnosed) Once object code is compiled and deemed free of syntax errors it is then translated into machine code by the assembler

13 Translators – What is a Translator? Explain what a translator is with reference to the source code and object code stage Why is not a good idea to compile source code straight into machine code? What problems might be encountered?


Download ppt "What am I?. Translators Translators – Module Knowledge Areas Types of translators and their use Lexical analysis Syntax analysis Code generation and."

Similar presentations


Ads by Google