Você está na página 1de 42

Nawroz University College Computer Science Department of Computer Science Stage Second

Programming Languages
Lecture 2

Topic
Review Compilation and Interpretation Phase of compilations Compilation Passes virtual machine (VM) Summary

Review

Reasons for Studying Concepts of Programming Languages


Increased ability to express ideas Improved background for choosing appropriate languages Increased ability to learn new languages

Reasons for Studying Concepts of Programming Languages


Better understanding of significance of implementation
Better use of languages that are already known Overall advancement of computing

Programming paradigm
programming paradigm can be defined as a pattern or model used within a software programming language to create software applications.

Programming Domains
Scientific applications
Fortran

Business applications
COBOL

Artificial intelligence
LISP, Prolog

Systems programming
C

Web Software
HTML, PHP

Language Evaluation Criteria


Readability: the ease with which programs can be read and understood Writability: the ease with which a language can be used to create programs Reliability: conformance to specifications (i.e., performs to its specifications) Cost: the ultimate total cost

Influences on Language Design


Computer Architecture Programming Methodologies

Language Categories
Imperative(c, c++) Functional (LISP)

Logic (Prolog) Markup/programming hybrid (PHP, Html)

Programming Environments
A collection of tools used in software development UNIX Microsoft Visual Studio.NET

Compilation and Interpretation

Overview of Compilation
program gcd(input, output); var i, j: integer; begin

read(i, j);
while i <> j do if i > j then i := i j; else j := j i; writeln(i) end.

Compilation

Compilation
Compilers: Translate a source (human-writable) program to an executable (machine-readable) program

Interpretation
Interpreters: Convert a source program and execute it at the same time.

Linking
Libraries of subroutines

Assembly language
Assembly language instead of machine language

Intermediate source
Intermediate source code

Programming Environments
Much more than compilers and interpreters
Assemblers, debuggers, preprocessors and linkers Editors Pretty printers Style Checkers Version management Profilers

Integrated environments

Phase of compilations

20

Compiler Structure
Lexical, syntax and semantic analyses are the front-end of a compiler
These phases serve to figure out the meaning of the program

The rest of the phases are considered part of the back-end of a compiler
They are responsible for the generation of the target program

Compiler vs. Interpreter


Most languages are usually thought of as using either one or the other:
Compilers: FORTRAN, COBOL, C, C++, Pascal Interpreters: Lisp, scheme, BASIC, APL, Perl, Python, Smalltalk

virtual machine

System Architecture

virtual machine (VM)


A virtual machine (VM) is an environment, usually a program or operating system. which does not physically exist but is created within another environment.

virtual machine (VM)


In this context, a VM is called a "guest" while the environment it runs within is called a "host. Virtual machines are often created to execute an instruction set different than that of the host environment.

virtual machine (VM)


One host environment can often run multiple VMs at once.

Because VMs are separated from the physical resources they use, the host environment is often able to dynamically assign those resources among them.

virtual machine (VM)


a machine that doesn't exist as a matter of actual physical reality. A virtual machine (VM) is a software implementation of a machine (i.e. a computer) that executes programs like a physical machine. The virtual machine idea is itself one of the most elegant in the history of technology and is a step in the evolution of ideas about software.

virtual machine categories


Virtual machines are separated into two major categories, based on their use and degree of correspondence to any real machine.
1. system virtual machine. 2. process virtual machine.

virtual machine categories


A system virtual machine provides a complete system platform which supports the execution of a complete operating system (OS). In contrast, a process virtual machine is designed to run a single program, which means that it supports a single process.

System virtual machines


multiple OS environments can co-exist on the same computer, in strong isolation from each other the virtual machine can provide an instruction set architecture (ISA) that is somewhat different from that of the real machine

The main disadvantages of SVM


a virtual machine is less efficient than a real machine when it accesses the hardware indirectly when multiple VMs are concurrently running on the same physical host, each VM may exhibit a varying and unstable performance (Speed of Execution, and not results), which highly depends on the workload imposed on the system by other VMs, unless proper techniques are used for temporal isolation among virtual machines.

System virtual machines


multiple OS environments can co-exist on the same computer, in strong isolation from each other the virtual machine can provide an instruction set architecture (ISA) that is somewhat different from that of the real machine

Process virtual machines


A process VM, sometimes called an application virtual machine, runs as a normal application inside a host OS and supports a single process. It is created when that process is started and destroyed when it exits.

Process virtual machines


Its purpose is to provide a platformindependent programming environment that abstracts away details of the underlying hardware or operating system, and allows a program to execute in the same way on any platform.

Process virtual machines


A process VM provides a high-level abstraction that of a high-level programming language (compared to the low-level ISA abstraction of the system VM). Process VMs are implemented using an interpreter; performance comparable to compiled programming languages is achieved by the use of just-in-time compilation.

Process virtual machines


This type of VM has become popular with the Java programming language, which is implemented using the Java virtual machine. NET Framework, which runs on a VM called the Common Language Runtime (CLR).

Java Virtual Machine (JVM)


The phrase "virtual machine" is commonly used to describe Java runtime environment, the Java Virtual Machine (JVM), in which Javaspecific commands are interpreted. The JVM is a virtual machine in that it executes code compiled specifically for it known as bytecode and abstracts use of resources for this bytecode.

Java Virtual Machine (JVM)


The Java programming language does not rely on platform specific instruction sets, such as APIs specific to any one operating system, to display output or access resources such as files.

Instead, the JVM creates virtualized resources which the bytecode accesses. These actions are then passed on to the machine's actual resources.

Summary
We have considered: A virtual machine (VM) is an environment, usually a program or operating system. Virtual machines have two major categories: 1. system virtual machine. 2. process virtual machine.

Summary The JVM is a virtual machine in that it executes code compiled specifically for it known as bytecode and abstracts use of resources for this bytecode.