Lesson 1 - Shawlands Academy

Download Report

Transcript Lesson 1 - Shawlands Academy

Computer
Systems
Nat 4/5 Computing Science
Translator Programs
Lesson Aims
 By
the end of this lesson:
 All pupils will be able to:





Describe and compare the following types of
languages:
Machine Code
High Level Languages
Describe why High Level Languages require
translation.
Describe how interpreters and compilers
function.
Nat 4/5
Types Of Languages
 Machine
symbols.

Code is made up of only 2
1 and 0 (On and Off)
 High
Level Languages such as Visual Basic
are written using some English words.

They are not written IN english!
Nat 4/5
High Level Languages
General
Purpose
Artificial
Intelligence
Education
Operating
Systems
• Pascal, C, C++ and COMAL
• ALGOL (Initially used for Mainframes)
• PROLOG (PROgramming in LOGic)
• LISP (Probably 2nd oldest language still in use - 1958)
• Pascal
• COMAL
• BASIC
•C
• C++,C#
Nat 4/5
Why do we need them?
 The
source code you write is instructions for
the computer

They are in a High Level Language
 The
computer needs these instructions
translated into machine code

It’s the only language it understands!
Nat 4/5
Types of Translators
 These
programs convert High Level
Language Source code into machine code
(binary)

Interpreter
 Translates

Compiler
 Translates
and executes one line at a time
Think complete!
and executes the entire program at
once
 This program can then be ran repeatedly
Nat 4/5
Interpreter
 Functions
like a spoken language
interpreter.

Translates and executes a single line at a time

The interpreter is ALWAYS loaded in memory

Error feedback is provided line by line
 Like

in Smallbasic
Interpreted programs have to be reinterpreted every single execution
Nat 4/5
How an interpreter works
Original Source Code
Pctoutput.isible = true
Pctoutput.print “Hello”
Interpreter
1001 1000 1100 1110 0011
Syntax Error
Nat 4/5
How the compiler works
Original Source Code
Can be saved and
ran later
Pctoutput.isible = true
Pctoutput.print “Hello”
Object Code
Compiler
1001 1000 1100 1110 0011
1010 1010 1010 0111 0011
Syntax Error
Nat 4/5
Summary
 Compilers
translate source code once into
an executable program


Only has to be translated once!
Cannot see the source code in a compiled
program
 Interpreters
line


translate source code line by
Always has to be re-interpreted
Spots errors line by line