Running & Testing Programs :: Translators

Slides:



Advertisements
Similar presentations
Lab6 – Debug Assembly Language Lab
Advertisements

CMP 131 Introduction to Computer Programming Violetta Cavalli-Sforza Week 1, Lab.
SOFTWARE SYSTEMS SOFTWARE APPLICATIONS SOFTWARE PROGRAMMING LANGUAGES.
Activity 1 - WBs 5 mins Go online and spend a moment trying to find out the difference between: HIGH LEVEL programming languages and LOW LEVEL programming.
1 Chapter-01 Introduction to Computers and C++ Programming.
CHAPTER 4: INTRODUCTION TO COMPUTER ORGANIZATION AND PROGRAMMING DESIGN Lec. Ghader Kurdi.
Introduction to Python
Higher Grade Computing Studies 2. Languages and Environments Higher Computing Software Development S. McCrossan 1 Classification of Languages 1. Procedural.
Levels of Architecture & Language CHAPTER 1 © copyright Bobby Hoggard / material may not be redistributed without permission.
Fall 2006Slides adapted from Java Concepts companion slides1 Introduction Advanced Programming ICOM 4015 Lecture 1 Reading: Java Concepts Chapter 1.
C o n f i d e n t i a l 1 Course: BCA Semester: III Subject Code : BC 0042 Subject Name: Operating Systems Unit number : 1 Unit Title: Overview of Operating.
Introduction to Python Dr. José M. Reyes Álamo. 2 Three Rules of Programming Rule 1: Think before you program Rule 2: A program is a human-readable set.
LOW vs. HIGH Level Languages
By: Cheryl Mok & Sarah Tan. Java is partially interpreted. 1. Programmer writes a program in textual form 2. Runs the compiler, which converts the textual.
Compilers and Interpreters
Representation of Data - Instructions Start of the lesson: Open this PowerPoint from the A451 page – Representation of Data/ Instructions How confident.
OCR A Level F453: The function and purpose of translators Translators a. describe the need for, and use of, translators to convert source code.
Some of the utilities associated with the development of programs. These program development tools allow users to write and construct programs that the.
Software Engineering Algorithms, Compilers, & Lifecycle.
Programming Languages Salihu Ibrahim Dasuki (PhD) CSC102 INTRODUCTION TO COMPUTER SCIENCE.
Computer Systems Nat 5 Computing Science
Installing Java on a Home machine
Why don’t programmers have to program in machine code?
Development Environment
Component 1.6.
Visit for more Learning Resources
High or Low Level Programming Language? Justify your decision.
Topic: Programming Languages and their Evolution + Intro to Scratch
High and low level languages
Introduction to programming
CSCI-235 Micro-Computer Applications
CMSC201 Computer Science I for Majors Lecture 22 – Binary (and More)
Key Ideas from day 1 slides
Computer Systems Nat 5 Computing Science
CS101 Introduction to Computing Lecture 19 Programming Languages
Variables, Expressions, and IO
CNIT 133 Interactive Web Pags – JavaScript and AJAX
Choice of Programming Language
Teaching Computing to GCSE
Unit# 8: Introduction to Computer Programming
TRANSLATORS AND IDEs Key Revision Points.
Teaching Computing to GCSE
Translators & Facilities of Languages
Assembler, Compiler, Interpreter
Installing Java on a Home machine
Chapter 10 Programming Fundamentals with JavaScript
High Level Programming Languages
Lesson 2 Programming constructs – Algorithms – Scratch – Variables Intro.
Lesson Objectives Aims Key Words Compiler, interpreter, assembler
Translators & Types of Languages
CMP 131 Introduction to Computer Programming
Assembler, Compiler, Interpreter
MARIE: An Introduction to a Simple Computer
ICT Programming Lesson 1:
Tonga Institute of Higher Education IT 141: Information Systems
Tonga Institute of Higher Education IT 141: Information Systems
1.3.7 High- and low-level languages and their translators
WJEC GCSE Computer Science
Programming Techniques :: Records
Programming Techniques :: File Handling
Programming Techniques :: String Manipulation
Programming Techniques :: Flow Diagrams and Pseudocode
Data Representation :: Binary & Hexadecimal
Running & Testing :: IDEs
Programming Techniques :: Logic & Truth Tables
Programming Techniques :: Data Types and Variables
Networks :: Wireless Networks
Data Representation :: Compression
Programming Techniques :: Arithmetic & Boolean Operators
Programming Techniques :: Computational Thinking
Presentation transcript:

Running & Testing Programs :: Translators jamie@drfrostmaths.com www.drfrostmaths.com @DrFrostMaths Last modified: 26th August 2019

www.drfrostmaths.com ? Everything is completely free. Why not register? Registering on the DrFrostMaths platform allows you to save all the code and progress in the various Computer Science mini-tasks. It also gives you access to the maths platform allowing you to practise GCSE and A Level questions from Edexcel, OCR and AQA. With Computer Science questions by: Your code on any mini-tasks will be preserved. Note: The Tiffin/DFM Computer Science course uses JavaScript as its core language. Most code examples are therefore in JavaScript. Using these slides: Green question boxes can be clicked while in Presentation mode to reveal. Slides are intentionally designed to double up as revision notes for students, while being optimised for classroom usage. The Mini-Tasks on the DFM platform are purposely ordered to correspond to these slides, giving your flexibility over your lesson structure. ?

Learning Objectives Directly from the OCR GCSE specification: This stuff

Overview of High vs Low Level Languages You write some code… How does it wind up being run by the CPU? Assembly code instructions Line: 1 2 3 4 5 6 7 8 … ASSIGN i  1 PUT i ON STACK GO TO LINE 78 REMOVE TOP OF STACK, MAKE t OUTPUT t ASSIGN i  i + 1 IF NOT(i<= n) GO TO LINE 9 GO TO LINE 2 Original code: function factorial(n) { var a = 1; for(var i=1; i<=n; i++) { a*= i; } return a; // MAIN CODE for(var i=1; i<=10; i++) { console.log(factorial(i)); ... Your code is often converted to finer-grained ‘low level’ instructions by a compiler/interpreter. Machine code run on CPU An assembler then converts the assembly code instruction into binary code (known as machine code) that the CPU can understand. Earlier in the course we saw how the Control Unit of the CPU works, which ‘customises’ the CPU circuit in such a way that allows the instruction to be run.

Overview of High vs Low Level Languages High Level Language Low Level Language function factorial(n) { var a = 1; for(var i=1; i<=n; i++) { a*= i; } return a; // MAIN CODE for(var i=1; i<=10; i++) { console.log(factorial(i)); ... ASSIGN i  1 PUT i ON STACK GO TO LINE 78 REMOVE TOP OF STACK, MAKE t OUTPUT t ASSIGN i  i + 1 IF NOT(i<= n) GO TO LINE 9 GO TO LINE 2 Examples: Java, JavaScript, C++, Python Each line of code could end up as multiple low level instructions. While the low level language might be specific to a particular CPU architecture, we can write the same code, which will be converted appropriately by the specific ‘translator’. It abstracts away specific details of how parts of the code operates: we can store variables without needing to know the machine’s memory structure. The drawback of this is that we don’t have as much control over the CPU in some languages, so some programs may be less efficient. Must be translated/interpreted before it can be run. One assembly code construction becomes one line of machine code, doing one specific action. Some languages (e.g. ‘BASIC’) allow the programmer to write these low-level instructions themselves. But often assembly code is an ‘intermediate’ language outputted by compilers. Assembly code instructions specific to a particular machine/CPU. Programmer needs to know about specific operations of the CPU, e.g. how memory is managed. Difficult to manage, read or update code. Can be executed directly without needing to translate/interpret. More control, therefore can be more efficient.

Test Your Understanding So Far ? It’s helpful to know what is not accepted as part of your answer.

Different types of translator We’ve seen that a compiler/interpreter converts a high-level language (e.g. Java or Python) into assembly code instructions, which can be more readily turned into machine instructions that a CPU can understand. Compilers and interpreters are examples of translators, which in general change instructions from one language to another. Translator Assembler Compiler Interpreter Turns assembly language into machine code. ADD $3, $2, $1 Both turn high-level languages into low-level ones (assembly languages), or sometimes directly into machine code. We’ll see the differences on the next slide… 1001001010100… As machine code is specific to particular CPU architectures, the assembler is also CPU specific.

Compilers vs translators Turns source code into a file that can be executed (e.g. an .exe file, or .class in the case of Java files). No executable file created. All code translated at the same time when compiling. Translates and runs source code one instruction at a time. Compiling only has to be done once (until source code modified), saving time when the program is run. Program must be translated every time it is run. The compiler can identify some problems with the code (‘compiler errors’), potentially identifying problems before program is run. Since no compilation, there are no ‘compiler errors’, only ‘runtime errors’. Is a separate file produced? ? When is code translated? ? ? How often do we have to translate code? ? How are code errors handled? In summary, with compilers we ‘compile’ the program prior to running it, producing a separate ‘compiled’ file. This saves us the time of converting the program to machine instructions each time the program is run.

Examples of interpreters JavaScript is an ‘interpreted’ language – the browser runs JavaScript code within a webpage without needing to compile it first.

Examples of interpreters During my PhD I wrote my own interpreter for an invented language called ‘HURDLE’ which was used for coding behaviour in robots, to enable it to converse with humans and interact with the robot’s functionality. The code was translated to Java. So it should be noted that not all interpreters turn high-level languages to low-level ones (or machine code), but sometimes high-level to high-level!

(not in the GCSE syllabus) Why writing compilers/interpreters is difficult… (not in the GCSE syllabus) Writing the ‘grammar’ rules that allow the compiler to read the language. 1 In maths you may be familiar with the idea of ‘order of operations’ (sometimes known as ‘BIDMAS’). Compilers/interpreters must also be able to understand this idea of precedence, but this also extends from mathematical operators to other programming constructs. var x = i > 0 ? 1 + 1 * 2 : 3

function factorial(n) { var a = 1; for(var i=1; i<=n; i++) { a*= i; } return a; // MAIN CODE for(var i=1; i<=10; i++) { console.log(factorial(i)); ... Line: 1 2 3 4 5 6 7 8 … 78 79 80 81 82 83 84 ASSIGN i  1 PUT I ON STACK GO TO LINE 78 REMOVE TOP OF STACK, MAKE t OUTPUT t ASSIGN i  i + 1 IF NOT(i<= n) GO TO LINE 9 GO TO LINE 2 Working out program flow with if, while and for constructs as well as procedures/functions. 2 Machine instructions are read sequentially one after another, but instructions can ask the CPU to ‘skip’ to another line of code. This enables us for example to accommodate calls to functions, as we need the CPU to move to the part of the code needed to execute the function that was called. REMOVE TOP OF STACK, MAKE n ASSIGN a  1 ASSIGN i  1 ASSIGN a  a × I ASSIGN i  i + 1 IF NOT(i <= N) PUT a ON STACK, GO BACK TO SOURCE GO TO LINE 79

(not in the GCSE syllabus) Why writing compilers/interpreters is difficult… (not in the GCSE syllabus) 3 ‘Tokenising’ In English, before we use our ‘grammar’ rules to understand the structure of a sentence, the assumption is that we’ve already split the sequence of characters into distinct ‘words’. This is easy in English because words are separated by spaces. In compiling/interpreting, this process of identifying the ‘words’ in code (which might be construct words such as ‘if’, characters like {, numbers like -3.27 or strings such as “bob”) is known as tokenising. if(i > 3.5) { print “hello” } Tokenise if, (, i, >, 3.5, ), {, print, “hello”

Test Your Understanding ?