Presentation is loading. Please wait.

Presentation is loading. Please wait.

Component 1.6.

Similar presentations


Presentation on theme: "Component 1.6."— Presentation transcript:

1 Component 1.6

2 Starter: Entry Ticket Complete the Entry Ticket on Program Construction. Extension: Research the 5 stages of the compilation process and explain what they do (Lexical Analysis, Syntax Analysis, Semantic Analysis, Code Generation, and Optimisation).

3 Learning Intentions and Outcomes
To develop an understanding of how computer programs are constructed including the errors that may occur during construction. Grade 4 Explain the purpose and use of Compilers, Interpreters, and Assemblers Define the 5 compilation processes (Lexical Analysis, Syntax Analysis, Semantic Analysis, Code Generation, and Optimisation). Describe different types of Program Construction Error Grade 5-6 Describe different program errors and how they are caused Explain the difference between Syntax and Logic Errors, providing examples for each Grade 7 Explain what errors may occur at different stages of compilation Explain the difference between translators and their benefits / drawbacks

4 Assessment Outcomes Describe the purpose and give examples of the use of compilers, interpreters and assemblers Explain the principal stages involved in the compilation process: lexical analysis, symbol table construction, syntax analysis, semantic analysis, code generation and optimisation Describe and give examples of programing errors

5 Starter Discussion The purpose of a translator is to translate Higher Levels of code into Lower Levels.

6 Starter Discussion Assemblers Translate from Assembly Code to Machine Code Compilers Translate from High Level Code to Machine Code (the whole program at once). Interpreters Translate from High Level Code to Machine Code (one line at a time).

7 Translators A translator changes (translates) a program written in one language into an equivalent program written in a different language. For example, a program written using the PASCAL programming language may be translated into a program written in one of the C programming languages using a translator

8 Assemblers An assembler is a program which coverts the low level assembly programming language into machine code. The assembler does this by converting the one-word assembly instructions into an opcode, e.g. converting AND to It also allocates memory to variables, often resulting in an operand.

9 Translating High Level Code into Low Level
Compiler Interpreter Translates the whole program to produce the Translates and executes one line at a time. executable object code. The object code is the version that the computer The source code is the version that the computer runs. Faster run time because the program is translated Slower run time because the program is translated once, object code is run after that. every time it is run. Customers cannot see the actual code you wrote If you distributed source code with an interpreter when you distribute the program. then customers would have your actual code. Used for distributed software. Used in development. A compiler translates a high level programming language into machine code – it compiles every line of code at the same time. An Interpreter translates a high level programming language into machine code – it translates each line of code separately. This helps programmers to debug their program and see which parts work and which do not!

10 Interpreters and compilers
Good for developing programs as you can execute parts of the program Have to correct all the syntax errors before you can run the program Slower execution as every line is translated before it is executed Fast execution of object code A user has to have the programming language and interpreter on their computer Once the object code is produced, it can be installed and run on any computer A user who has purchased your program can make changes and sell it on A user who has purchased your program cannot see the source code

11 Compilation: There are 4 stages to Compiling a Program:
lexical analysis syntax analysis semantic analysis code generation

12 Lexical Analysis Comments and unneeded spaces are removed.
Keywords, constants and identifiers are replaced by 'tokens'. A symbol table is created which holds the addresses of variables, labels and subroutines

13 Syntax Analysis Tokens are checked to see if they match the spelling and grammar expected, using standard language definitions. This is done by parsing each token to determine if it uses the correct syntax for the programming language. If syntax errors are found, error messages are produced

14 Semantic Analysis Variables are checked to ensure that they have been properly declared and used. Variables are checked to ensure that they are of the correct data type, e.g. real values are not being assigned to integers. Operations are checked to ensure that they are legal for the type of variable being used, e.g. you would not try to store the result of a division operation as an integer

15 Code Generation Machine code is generated.
Code optimisation may be employed to make it more efficient/faster/less resource intense

16 Grade 4 Exercises: Translating Code
Put the subheading “Translating Code into your book” Explain what the following Translators do, provide pros and cons for each: Compiler Interpreter Assembler Define the following compilation processes: Lexical Analysis Syntax Analysis Semantic Analysis Code Generation Optimisation

17 Program Errors Error Description Example Syntax An error that occurs when a command does not follow the expected syntax of the language, e.g. when a keyword is incorrectly spelt Incorrect: IF A ADN B Then Correct: IF A AND B Then Runtime/ executio n An error that only occurs when the program is running and is difficult to foresee before a program is compiled and run Program requests more memory when none is available, so the program crashes Logical An error that causes a program to output an incorrect answer (that does not necessarily crash the program) An algorithm that calculates a person’s age from their date of birth, but ends up giving negative numbers Error Description Example Linking An error that occurs when a programmer calls a function within a program and the correct library has not been linked to that program When the square root function is used and the library that calculates the square root has not been linked to the program Rounding Rounding is when a number is approximated to nearest whole number/tenth/hundredth, etc. 34.5 rounded to nearest whole number is 35, an error of +0.5 Truncation Truncating is when a number is approximated to a whole number/tenth/hundredth, etc. nearer zero 34.9 truncated to whole number is 34, an error of -0.9

18 Grade 4 Exercises: Errors
Put the sub-heading “Errors” into your book Define the following types of error: Syntax Logic Run-Time Linking Rounding Truncation Explain the difference between a Syntax and a Logic Error Extension Move on to the exam questions – these need to be self assessed by the end of the lesson!

19 Grade 5-7 Exam Questions Complete them Self Assess them Stick them in
Bring them to me

20 Grade 8 Extension Go into the A-Level Extension folder and have a go at the Grade D A Level Exercises!

21 Exit Ticket Complete the Exit Ticket and Stick it in your books.

22 Homework Graded Exercises
Complete up to your year 11 target grade in the graded exercises Pre-Reading Make notes on Pages This is a lot so focus on these topics: Flow Charts Shapes Decision Loops Pseudocode Bubble Sort Merge Sort Searching


Download ppt "Component 1.6."

Similar presentations


Ads by Google