Compilers and Interpreters. What's the difference? Computer programs are compiled or interpreted. Languages like Assembly Language, C, C++, Fortran, Pascal.

Slides:



Advertisements
Similar presentations
Operating-System Structures
Advertisements

GCSE Computing Lesson 5.
compilers and interpreters
Operating System Structures
Higher Computing Computer Systems S. McCrossan Higher Grade Computing Studies 7. Systems Software 1 System Software This software is used to provide the.
ICS103 Programming in C Lecture 1: Overview of Computers & Programming
Lecture 1: Overview of Computers & Programming
9.0 EMBEDDED SOFTWARE DEVELOPMENT TOOLS 9.1 Introduction Application programs are typically developed, compiled, and run on host system Embedded programs.
Programming Types of Testing.
Copyright © 2012 Pearson Education, Inc. Chapter 1: Introduction to Computers and Programming.
1 Lecture 1  Getting ready to program  Hardware Model  Software Model  Programming Languages  The C Language  Software Engineering  Programming.
About the Presentations The presentations cover the objectives found in the opening of each chapter. All chapter objectives are listed in the beginning.
1 CHAPTER 4 LANGUAGE/SOFTWARE Hardware Hardware is the machine itself and its various individual equipment. It includes all mechanical, electronic.
Compiled by Benjamin Muganzi 3.2 Functions and Purposes of Translators Computing 9691 Paper 3 1.
Systems Software Operating Systems.
Lesson 4 Computer Software
Computer Programming-1 CSC 111 Chapter 1 : Introduction.
Chapter Introduction to Computers and Programming 1.
CHAPTER 4: INTRODUCTION TO COMPUTER ORGANIZATION AND PROGRAMMING DESIGN Lec. Ghader Kurdi.
P51UST: Unix and Software Tools Unix and Software Tools (P51UST) Compilers, Interpreters and Debuggers Ruibin Bai (Room AB326) Division of Computer Science.
Operating Systems What do you have left on your computer after you strip away all of the games and application programs you bought and installed? Name.
Language Systems Chapter FourModern Programming Languages 1.
© Janice Regan, CMPT 128, Jan CMPT 128 Introduction to Computing Science for Engineering Students Creating a program.
How Java Programs Work MIS 3023 Business Programming Concepts II The University of Tulsa Professor: Akhilesh Bajaj All slides in this presentation ©Akhilesh.
Copyright © 2012 Pearson Education, Inc. Chapter 1: Introduction to Computers and Programming.
Chapter 1: Introduction to Computers and Programming.
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 1: Introduction to Computers and Programming.
CS 1308 Computer Literacy and the Internet. Introduction  Von Neumann computer  “Naked machine”  Hardware without any helpful user-oriented features.
1 Computing Software. Programming Style Programs that are not documented internally, while they may do what is requested, can be difficult to understand.
Chapter 10: Compilers and Language Translation Invitation to Computer Science, Java Version, Third Edition.
Systems Software Operating Systems. What is software? Software is the term that we use for all the programs and data that we use with a computer system.
Unit-1 Introduction Prepared by: Prof. Harish I Rathod
CE Operating Systems Lecture 3 Overview of OS functions and structure.
© Janice Regan, CMPT 300, May CMPT 300 Introduction to Operating Systems Memory: Relocation.
LANGUAGE SYSTEMS Chapter Four Modern Programming Languages 1.
1 Software. 2 What is software ► Software is the term that we use for all the programs and data on a computer system. ► Two types of software ► Program.
Chapter 1 Introduction. Chapter 1 -- Introduction2  Def: Compiler --  a program that translates a program written in a language like Pascal, C, PL/I,
Chapter 1 Computers, Compilers, & Unix. Overview u Computer hardware u Unix u Computer Languages u Compilers.
Chapter 1 : Overview of Computer and Programming By Suraya Alias
Computer Software Operating Systems – Programs. Computer Language - Review We learnt that computers are made up of millions of tiny switches that can.
Computer Systems. Bits Computers represent information as patterns of bits A bit (binary digit) is either 0 or 1 –binary  “two states” true and false,
Lecture on Central Process Unit (CPU)
HOW A COMPUTER PROCESSES DATA. What is hardware? Hardware is the electric, electronic and mechanical equipment that makes up a computer What is software?
Computer and Programming. Computer Basics: Outline Hardware and Memory Programs Programming Languages and Compilers.
Brief Version of Starting Out with C++ Chapter 1 Introduction to Computers and Programming.
Chapter 11  Getting ready to program  Hardware Model  Software Model  Programming Languages  Facts about C++  Program Development Process  The Hello-world.
1 Asstt. Prof Navjot Kaur Computer Dept PRESENTED BY.
Introduction to Computer Programming using Fortran 77.
Hello world !!! ASCII representation of hello.c.
OCR A Level F453: The function and purpose of translators Translators a. describe the need for, and use of, translators to convert source code.
Introduction to Computer Programming Concepts M. Uyguroğlu R. Uyguroğlu.
1 Chapter 2: Operating-System Structures Services Interface provided to users & programmers –System calls (programmer access) –User level access to system.
Introduction to Operating Systems Concepts
Computer Basics.
Topic 2: Hardware and Software
Lecture 1b- Introduction
Advanced Computer Systems
14 Compilers, Interpreters and Debuggers
Operating System Review
Chapter 1 Introduction.
Lecture 1: Introduction to JAVA
ICS103 Programming in C Lecture 1: Overview of Computers & Programming
Chapter 1 Introduction.
Operating System Review
Computer Programming (CS101) Lecture-04
Computers: Hardware and Software
Chapter 2: System Structures
Introduction CSC 111.
Chapter 1 Introduction.
Programming language translators
Presentation transcript:

Compilers and Interpreters

What's the difference? Computer programs are compiled or interpreted. Languages like Assembly Language, C, C++, Fortran, Pascal were almost always compiled into machine code. Languages like Basic,VbScript and JavaScript were usually interpreted.compiled interpretedAssembly LanguageCC++machine code So what is the difference between a compiled program and an Interpreted one?

Compiling To write a program takes these steps: 1.Edit the Program 2.Compile the program into Machine code files. 3.Link the Machine code files into a runnable program (also known as an exe).exe 4.Debug or Run the Program With some languages like Turbo Pascal and Delphi steps 2 and 3 are combined

Machine code files are self-contained modules of machine code that require linking together to build the final program. The reason for having separate machine code files is efficiency; compilers only have to recompile source code that have changed. The machine code files from the unchanged modules are reused. This is known as Making the application. If you wish to recompile and rebuild all source code then that is known as a Build.Machine code linkingsource codeMaking

Linking is a technically complicated process where all the function calls between different modules are hooked together, memory locations are allocated for variables and all the code is laid out in memory, then written to disk as a complete program. This is often a slower step than compiling as all the machine code files must be read into memory and linked together.variables

Interpreting The steps to run a program via an interpreter are : 1. Edit the Program 2. Debug or Run the ProgramDebug 3. This is a far faster process and it helps novice programmers edit and test their code quicker than using a compiler. The disadvantage is that interpreted programs run much slower than compiled programs. As much as 5-10 times slower as every line of code has to be re-read, then re- processed.

Java and C# Both of these languages are semi-compiled. They generate an intermediate code that is optimized for interpretation. This intermediate language is independant of the underlying hardware and this makes it easier to port programs written in either to other processors, so long as an interpreter has been written for that hardware. Java when compiled produces bytecode that is interpreted at runtime by a Java Virtual Machine (JVM). Many JVMs use a Just-In-Time compiler that converts bytecode to native machine code and then runs that code to increases the interpretation speed. In effect the Java source code is compiled in a two-stage process.JavabytecodeVirtual Machine

What is a Compiler? A compiler is a program that translates human readable source code into computer executable machine code. To do this successfully the human readable code must comply with the syntax rules of whichever programming language it is written in. The compiler is only a program and cannot fix your programs for you. If you make a mistake, you have to correct the syntax or it won't compile.compilerprogramsource code machine codesyntax What happens When You Compile Code?: A compiler's complexity depends on the syntax of the language and how much abstraction that programming language provides. A C compiler is much simpler thanC C++ Compiler or a C# Compiler.C++C#

Here is what happens when you compile code. Lexical Analysis: This is the first process where the compiler reads a stream of characters (usually from a source code file) and generates a stream of lexical tokens. For example the C++ codestream Next is Syntactical Analysis: This output from Lexical Analyzer goes to the Syntactical Analyzer part of the compiler. This uses the rules of grammar to decide whether the input is valid or not. Unless variables A and B had been previously declared and were in scope, the compiler might say variables scope 'A' : undeclared identifier. Had they been declared but not initialized. the compiler would issue a warning local variable 'A' used without been initialized. You should never ignore compiler warnings. They can break your code in weird and unexpected ways. Always fix compiler warnings!

One Pass Or Two?: Some languages have been written so that a compiler can get away with reading the source code once and generating the machine code. Pascal is one such language. Many compilers require at least two passes. Why is this?Pascal Sometimes it is because of - Forward Declarations of functions or classes.functions classes - How much optimization you require of the compiler.

Assuming that the compiler has successfully completed these stages - Lexical Analysis. - Syntactical Analysis. The final stage is generating machine code. This can be an extremely complicated process, especially with modern CPUs. The speed of the compiled executable should be as fast as possible and can vary enormously according toexecutable The quality of the generated code. How much optimization has been requested. Most compilers let you specify the amount of optimization. Typically none for debugging (quicker compiles!) and full optimization for the released code. Code Generation Is Challenging!:

The compiler writer faces challenges when writing a code generator. Many processors speed up processing by using Instruction Pipelining. Internal caches.caches If all of the instructions within a loop can be held in the CPU cache then that loop will run much faster than if the CPU has to fetch instructions from main RAM. The CPU cache is a block of memory built into the CPU chip that is accessed much faster than data in the main RAM.loopCPURAM

Caches And Queues: Most CPUs have a prefetch queue where the CPU reads in instructions into the cache prior to executing them. If a conditional branch happens then the CPU has to reload the queue. So code should be generated to minimize this. Many CPUs have separate parts for - Integer Arithmetic - Floating Point Arithmetic So these operations can often run in parallel to increase the speed. Compilers typically generate code into object files which are then linked together by a Linker program.object fileslinked

An introduction to Operating Systems

What is an Operating System? An Operating system is a software that controls a computer. This is not the same as the applications that you create - those are usually only run when you want them. An OS runs almost as soon as the computer is turned on. Windows is an Operating System, as is Linux and the Apple Mac OS X.

Switching On -When a computer is powered up, the CPU starts running immediately. But what does it run? On most PCs, whether Linux, Windows or Mac, there is a boot program stored permanently in the ROM of the PC.CPUbootROM Booting Up - Each PC motherboard manufacturer writes a boot program for their motherboard.boot - This boot program is not an Operating System (OS), it is there to load the OS. Its first job is the Power On Start-Up Test (aka POST). This is a system test, first checking the memory and flagging any errors. It will stop the system if something is wrong. Next it resets and initializes any devices plugged into the PC. This should result in the OS being loaded from whichever device has been configured as the boot device, be it Flash RAM, CD-Rom or hard disk. Having successfully loaded the OS, the boot program hands over control and the OS takes charge.Operating System

Managing the computer The job of an OS is to manage all the resources in a computer. When user input is received from mouse and keyboard it has to be handled in a timely fashion. When you create or copy a file, the OS takes care of it all behind the scenes. It may store a file in a hundred different places on disk but it keeps you well away from that level of detail. You'll just see one file entry in a directory listing.resources An OS is just a very complex collection of programs and nowadays takes hundreds or thousands of man hours to develop. We've come along way since Dos 6.22 which fitted on a 720 Kb floppy and Vista promises to be very large- 9 or 10 Gigabytes

Protection and Security Modern CPUs have all sorts of tricks built into their hardware - for example CPUs only permit trusted programs to run with access to all of the hardware facilities. This provides extra safety. In Ring 0 protection on Intel/AMD CPUs, the code at the heart of the OS, usually called the Kernel code, is protected against corruption or overwriting by non Kernel applications - the kind you and I write. Nowadays it is rare for a user written program to crash a computer. The CPU will stop any attempt to overwrite Kernel CodeKernel

Also, the CPU has several privileged instructions that can only be run by Kernel Code. This enhances the robustness of the OS and reduces the number of fatal crashes, such as the infamous Windows Blue Screen of death.privileged instructions The language C was developed to write Operating Systems code and it is still popular in this role mainly for Linux and Unix systems. The Kernel part of Linux is written in C.CLinux Unix The operating system is arguably the most important piece of software on your PC.