P51UST: Unix and Software Tools Unix and Software Tools (P51UST) Compilers, Interpreters and Debuggers Ruibin Bai (Room AB326) Division of Computer Science.

Slides:



Advertisements
Similar presentations
GCSE Computing Lesson 5.
Advertisements

compilers and interpreters
Programming Types of Testing.
Software Language Levels Machine Language (Binary) Assembly Language –Assembler converts Assembly into machine High Level Languages (C, Perl, Shell)
COMP205 Comparative Programming Languages Part 1: Introduction to programming languages Lecture 3: Managing and reducing complexity, program processing.
Reference Book: Modern Compiler Design by Grune, Bal, Jacobs and Langendoen Wiley 2000.
Programming Introduction November 9 Unit 7. What is Programming? Besides being a huge industry? Programming is the process used to write computer programs.
CMP 131 Introduction to Computer Programming Violetta Cavalli-Sforza Week 1, Lab.
Compilers and Interpreters. Translation to machine language Every high level language needs to be translated to machine code There are different ways.
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.
1.3 Executing Programs. How is Computer Code Transformed into an Executable? Interpreters Compilers Hybrid systems.
Systems Software Operating Systems.
C++ Crash Course Class 1 What is programming?. What’s this course about? Goal: Be able to design, write and run simple programs in C++ on a UNIX machine.
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.
Computer Programming-1 CSC 111 Chapter 1 : Introduction.
1 Chapter-01 Introduction to Computers and C++ Programming.
Introduction to High-Level Language Programming
Introduction to Programming Prof. Rommel Anthony Palomino Department of Computer Science and Information Technology Spring 2011.
Introduction to Java Tonga Institute of Higher Education.
Parts of a Computer Why Use Binary Numbers? Source Code - Assembly - Machine Code.
Introduction to Programming Lecture Number:. What is Programming Programming is to instruct the computer on what it has to do in a language that the computer.
© Janice Regan, CMPT 128, Jan CMPT 128 Introduction to Computing Science for Engineering Students Creating a program.
High level & Low level language High level programming languages are more structured, are closer to spoken language and are more intuitive than low level.
Slide 1 Standard Grade Computing Studies Systems Software.
Computer Programming I An Introduction to the art and science of programming with C++
Computer Programming A program is a set of instructions a computer follows in order to perform a task. solve a problem Collectively, these instructions.
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.
What is Programming? A program is a list of instructions that is executed by a computer to accomplish a particular task. Creating those instructions is.
What am I?. Translators Translators – Module Knowledge Areas Types of translators and their use Lexical analysis Syntax analysis Code generation and.
Chapter 1 Introduction. Chapter 1 - Introduction 2 The Goal of Chapter 1 Introduce different forms of language translators Give a high level overview.
Debuggers in Python. The Debugger Every programming IDE has a tool called a debugger. This application does NOT locate or fix your bugs for you! It slows.
1 3. Computing System Fundamentals 3.1 Language Translators.
A compiler is a computer program that translate written code (source code) into another computer language Associated with high level languages A well.
Chapter 4 Software. Chapter 4: Software Generations of Languages Each computer is wired to perform certain operations in response to an instruction. An.
Compilers and Interpreters. HARDWARE Machine LanguageAssembly Language High Level Language C++ Visual Basic JAVA Humans.
Concurrency Properties. Correctness In sequential programs, rerunning a program with the same input will always give the same result, so it makes sense.
Programming and Languages Dept. of Computer and Information Science IUPUI.
Introduction to OOP CPS235: Introduction.
The single most important skill for a computer programmer is problem solving Problem solving means the ability to formulate problems, think creatively.
Lesson 1 1 LESSON 1 l Background information l Introduction to Java Introduction and a Taste of Java.
Chapter 1: Introduction to Visual Basic.NET: Background and Perspective Visual Basic.NET Programming: From Problem Analysis to Program Design.
ICS312 Introduction to Compilers Set 23. What is a Compiler? A compiler is software (a program) that translates a high-level programming language to machine.
Compilers and Interpreters
OCR A Level F453: The function and purpose of translators Translators a. describe the need for, and use of, translators to convert source code.
Programming 2 Intro to Java Machine code Assembly languages Fortran Basic Pascal Scheme CC++ Java LISP Smalltalk Smalltalk-80.
Introduction to Computer Programming Concepts M. Uyguroğlu R. Uyguroğlu.
Introduction to Computer Programming By: Mr. Baha Hanene Chapter 1.
Some of the utilities associated with the development of programs. These program development tools allow users to write and construct programs that the.
THE SOFTWARE Computers need clear-cut instructions to tell them what to do, how to do, and when to do. A set of instructions to carry out these functions.
Introduction To Software Development Environment.
Evolution and History of Programming Languages
Why don’t programmers have to program in machine code?
Lecture 1b- Introduction
Component 1.6.
Assembler, Compiler, MIPS simulator
Programming and Debugging with the Dragon and JTAG
Visit for more Learning Resources
14 Compilers, Interpreters and Debuggers
Component 1.6.
Introduction to programming
Microprocessor and Assembly Language
A451 Theory – 7 Programming 7A, B - Algorithms.
TRANSLATORS AND IDEs Key Revision Points.
Translators & Facilities of Languages
CMP 131 Introduction to Computer Programming
1.3.7 High- and low-level languages and their translators
WJEC GCSE Computer Science
Programming language translators
Presentation transcript:

P51UST: Unix and Software Tools Unix and Software Tools (P51UST) Compilers, Interpreters and Debuggers Ruibin Bai (Room AB326) Division of Computer Science The University of Nottingham Ningbo, China

Introduction The role of language translators Compilers and Interpreters The Java Virtual Machine Debugging –Using print statements to debug a program –Basic functions performed by a debugger

The role of language translators Programming languages have evolved to make programming easier for humans Computers still execute machine code Language translators are required to translate between the two A new translator is required for each combination of programming language and machine-code

Translation involves several tasks –translating high level program statements into combinations of machine code instructions –translating high level data structures into combinations of memory locations –linking to existing code (libraries, modules, objects, system calls) to form a final program Two broad approaches to translation – compilation and interpretation The role of language translators (2)

Compilers A compiler translates text written in a computer language (the source language) into another computer language (the target language). Is primarily used for programs that translate source code from a high-level programming language to a lower level language (e.g., assembly language or machine language). A compiler is likely to perform many or all of the following operations: –lexical analysis, –preprocessing, –parsing/semantic analysis, –code generation, and –code optimization.

Interpreters One statement is translated and then executed at a time Start at the beginning of the program REPEAT translate next program statement if no translation error occurred then execute the statement UNTIL the end of the program or an error occurs

Compilers: Pros and Cons Pros: –Enable programmers to write human-readable code with a richer set of instructions –Program execution is fast –Compiled programs can be run more than once without re-compilation –Programs can be compiled for different platforms Cons: –To run on a different platform, code has to be recompiled

Interpreters: Pros and Cons Pros: –No need to compile before running the program; program can just be run straight away –Program can be run on different platforms without recompiling (provided an interpreter is available for that platform) Cons: –Program execution is slower than with compiled code

Java Virtual Machine Until the advent of Java, the trend for programming was moving away from interpreted languages and towards compiled languages –Software interpreters are complex and so run slowly Java takes a new approach…

Java Virtual Machine (2) Java is compiled into a standard machine language called Bytecode This standard machine language is then interpreted by a software interpreter, the Java Virtual Machine (JVM) –JVM takes Bytecode and executes it –Bytecode is not the standard machine language for any specific hardware processor –Any machine which has a JVM can run the compiled Java program

Advantages of JVM Because Java is compiled before being interpreted it runs more quickly than standard interpreted languages BUT, Java is also portable because the platform it is compiled for is available for lots of different machine architectures –Java therefore does not need to be recompiled to run on different types of machine

Debugging

A program fails a test case (or a bug is reported). A programmer is given the test case and the associated source code and “debugs” the program until the fault has been corrected. The program, having been fixed, no longer exhibits the failure. The hard part is locating the problem!!

Bridging the Gap One problem with faults is that they are not necessarily located “near” their associated failure. We need to “bring the failure close to the fault”. The simplest way to do this is with print statements.

Using print Statements Your program has compiled but crashes when it runs. What should you do? –Sprinkle print statements throughout your program and see how many are executed. Your program runs but is printing the wrong answer. What should you do? –Use print statements to print out the values of your internal variables. See which give you the right answer and which give you the wrong answer.

A Buggy awk Program x = 10 while (x > 5) { x++ } print $x

Program with print Statements x = 10 print "Got past initialisation\n" while (x > 5) { print "Entered while loop\n" x++ print "incremented x\n" } print "Exited while loop\n" print $x

Output of Buggy Program $ awkInfinite.sh Got past initialisation Entered while Loop incremented x Entered while Loop incremented x Entered while Loop incremented x Entered while Loop incremented x

More Print Statements x = 10 print "Got past initialisation\n" while (x > 5) { print "Entered while Loop\n" print $x ”\n" x++ print "incremented x\n“ print $x ”\n” } print "Exited while loop\n" print $x

More Output $ awkInfinite.sh Got past initialisation Entered while Loop 10 incremented x 11 Entered while Loop 11 incremented x 12

Debugging Tools A debugger allows a programmer to monitor the internal state of a program while it is executing (saves putting in and taking out print statements). Two types of debugger –Interpretive –Direct Execution

Types of Debuggers Interpretive Debuggers –work by reading a program and simulating its execution one line at a time. Direct Execution Debuggers –work by running the actual program in a special mode where the debugger can read and write the program’s memory.

Interpretive Vs. Direct Execution Debuggers Interpretive Debuggers –Easier to program –Safer, a program cannot crash the machine (just the debugger). Direct Execution –Faster –More accurate, the actual program instructions are being executed

Two Styles of Use Line-at-a-time –A programmer loads the program into the debugger and “steps” through the program one line at a time. –The debugger stops the program after each line and gives the programmer a chance to check the program’s variables to see if it is operating correctly.

Two Styles of Use (2) Breakpoints –A Programmer loads a program into the debugger and specifies “breakpoints” at various locations in the program. –The program runs until it hits a breakpoint.

How are Breakpoints Useful? If you think you have function that might have a fault. –Set a breakpoint at the beginning of the function. –Set another breakpoint at the end of the function. –If a program’s data is correct at the beginning of the function but incorrect at the end, then there is a fault in the function. –They also allow you to skip over “init” code and debugged code quickly; letting the programmer focus on finding the fault.

Editing Variables Debuggers let the programmer explore “what-if” scenarios: –You can execute a program to a certain point, and then alter the values of the program’s variables. –So you can explore unusual cases. –Plus, if a bug occurs, you can correct an incorrect value and see how far the program goes before it encounters another fault.

Summary Using a debugger is more flexible than print statements. Debuggers can be used to step through code or to run until some breakpoint. They also let you view the values of variables. They take a bit of getting used to but are usually well worth the time invested.