0% found this document useful (0 votes)
111 views17 pages

CCCCCCCCCCCCCCCCC C C CC C

An algorithm is a computational procedure that takes input values and produces output values to solve a well-defined computational problem. A programming language is an artificial language designed to express algorithms on a computer through an unambiguous syntax and semantics. Reasons for studying programming language concepts include increased ability to express ideas, improved ability to choose appropriate languages for problems, and better understanding of language implementation tradeoffs.

Uploaded by

prateek3
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
111 views17 pages

CCCCCCCCCCCCCCCCC C C CC C

An algorithm is a computational procedure that takes input values and produces output values to solve a well-defined computational problem. A programming language is an artificial language designed to express algorithms on a computer through an unambiguous syntax and semantics. Reasons for studying programming language concepts include increased ability to express ideas, improved ability to choose appropriate languages for problems, and better understanding of language implementation tradeoffs.

Uploaded by

prateek3
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 17

What is an algorithm?

 An algorithmis a computational procedure that takes values as inputand produces values as output, in order to solve a well defined computational problem:  The statement of the problem specifies a desired relationship between the inputand the output.  The algorithm specifies how to achieve that input/outputrelationship.  A particular value of the inputcorresponds to an instance of the problem.

What is a programming language?

A programming language is an artificial language designed for expressing algorithms on a computer:  Need to expressan infinite number of algorithms (Turing complete).  Requires an unambiguous syntax, specified by a finitecontext free grammar  Should have a well defined compositional semanticsfor each syntactic construct: operational vs. axiomatic vs. denotation  Often requires a practical implementation i.e. pragmatics:  Implementation on a real machine vs. virtual machine  translation vs. compilation vs. interpretation.

Outline(things taught over the days)


       Reasons for Studying Concepts of Programming Languages Application Domains Criteria for Language Evaluation Influences on Language Design Language Paradigms Language Design Trade-Offs Implementation Methods

 

Reasons for studying concepts of PLs: Increased ability to express ideas/algorithmsNatural language: y The depth at which people can think is influenced by the expressive power of the language they use (also Sapir-Worf hypothesis).

Programming languages: y The complexity of the algorithms that people implement is influenced by the set of constructs available in the programming language. y Kenneth E. Iversion (inventor of APL programming language):Notation as a tool of thought (Turing award lecture).

Improved background for choosing appropriate languages:

y Many programmers use the language with which they are most familiar, even though poorly suited for the new project y Ideal: use the most appropriate language. y Features important for a given project are included already in the language design n, as opposed to being simulated => elegance & safety.

Better understanding of significance of implementation:

Example: a small subprogram that is called very frequently can be a highly inefficient design choice.   More details can be learned by studying compiler design. Better use of languages that are already known.

Overall advancement of computing: Algol 60 vs. Fortran.

 Application Domains
 Scientific applications: y Large numbers of floating point computations; extensive use of arrays y Fortran, Matlab Business applications: y Produce reports, use decimal numbers and characters

 y y

y COBOL Artificial intelligence: Symbols rather than numbers manipulated; use of linked listsLISP Lately, many AI applications (e.g. statistical or connectionist approaches) are written in Java, C++, Python.

 y y y  y y

Systems programming: Need efficiency because of continuous use. C (UNIX almost entirely written in C). Web Software:

Eclectic collection of languages: markup (e.g., XHTML). scripting for dynamic content: ------client side, using scripts embedded in the XHTML document. Examples: Javascript, PHP. ------ server side, using the Common Gateway Interface. Examples: JSP, ASP, PHP. y general-purpose, executed on Example: Java, C++,

Criteria for Language Evaluation


    Readability: the ease with which programs can be read and understood. Writability: the ease with which a language can be used to create Reliability: conformance to specifications (e.g. program correctness). Cost: the ultimate total cost associated with a PL.

programs.

Readibility:
  Overall simplicityA manageable set of basic features and constructs. Minimal feature multiplicity.Example: increment operators in C

Minimal operator overloading.Example: C++ vs. Java

OrthogonalityA relatively small set of primitive constructs that can be

combined in a relatively small number of ways.Example: addition in assembly on IBM mainframe vs. VAX minicomputers.  C. Every possible combination is legalExample: returning arrays & records in

Data types and structure: Adequate predefined data types and structuresExample: Booleanvs. Integer  The presence of adequate facilities for defining data structuresExample:

array of structs vs. collection of arrays (C).

Syntactic design:    Identifier forms (allow long names). Special words and methods of forming compound statements. Form and meaning: self-descriptive constructs, meaningful keywords.statickeyword in C has

context dependent meaning.

Writability:

Simplicity and orthogonality


 Few constructs, a small number of primitives, a consistent, small set of rules for combining them (avoid misuse or disuse of features).

Support for abstraction


   The ability to define and use complex structures or operations in ways Process Abstraction (e.g. sorting algorithm implemented as a subprogram) Data Abstraction (e.g. trees & lists in C++/Java vs. Fortran77). that allow details to be ignored

Expressivity
      A set of relatively convenient ways of specifying operations. Strength and number of operators and predefined functions. Examples: Increment operators in C. Short circuit operators in Ada. Counting loops with forvs. whilein Java.

Reliability:

Type checking:
 Testing for type errors at compile-time vs. run-time. Examples:(+) Ada, Java, C#, C++. () C.

Exception handling
  Intercept run-time errors, take corrective measures and continue. Examples:(+) Ada, C++, Java.

Aliasing
 Presence of two or more distinct referencing methods for the same memory location:Pointers in C, references in C++.

Readability and writability:


 A language that does not support natural ways of expressing an algorithm will require the use of unnatural approaches (less safe), and hence reduced reliability.

Cost:
Training programmers to use the language. Writing programs (closeness to particular applications). Compiling programs: --Tradeoff between compile vs. execution time through optimization. Executing programs: Example: many run-time type checks slow the execution (Java). Language implementation system: Availability of free compilers. Reliability: poor reliability leads to high costs. Maintaining programs: Corrections & adding new functionality.

Other Criteria:
Portability

The ease with which programs can be moved from one implementation to another (helped by standardization). Generality The applicability to a wide range of applications. Well-definedness The completeness and precision of the languages official definition.

Trade-offs in Language Design:


Reliability vs. cost of execution Example: Java demands all references to array elements be checked for proper indexing, which leads to increased execution costs Readability vs. writability Example: APL provides many powerful operators (and a large number of new symbols), allowing complex computations to be written in a compact program but at the cost of poor readability. Writability (flexibility) vs. reliability Example: C++ pointers are powerfull and very flexible,but unreliable.

Influences on Language Design:


Computer Architecture: Languages are developed around the prevalent computer architecture, known as the von Neumannarchitecture. Programming Methodologies: New software development methodologies (e.g., object-oriented software development) led to new programming paradigms and by extension, to new programming languages.

Influences: Computer Architecture:


Most prevalent computer architecture: Von Neumann

Imperative languages, most dominant, because of von Neumann computers: ~Data and programs stored in memory Memory is separate from CPU Instructions and data are piped from memory to CPU Basis for imperative languages: Variables model memory cells Assignment statements model piping Iteration is efficient

Von Neumann Architecture:

Fetch-execute-cycle (on a von Neumann architecture

computer) initialize the program counter: repeat forever fetch the instruction pointed by the counter increment the counter decode the instruction execute the instruction end repeat Von Neumann Bottleneck:~ Connection speed between a computers memory and its processor determines the speed of a computer. Program instructions often can be executed much faster than the speed of the connection; the connection speed thus results in a bottleneck. Known as the von Neumann bottleneck; it is the primary limiting factor in the speed of computers

Influences: Programming Methodologies:


1950s and early 1960s: Simple applications; worry about machine efficiency Late 1960s: People efficiency became important; readability, better control structures structured programming top-down design and step-wise refinement Late 1970s: Process-oriented to data-oriented design abstract data types (Simula 67) Middle 1980s: Object-oriented programming

data abstraction + inheritance + polymorphism Smaltalk, Ada 95, C++, Java, CLOS, Prolog++

Language Paradigms:
Imperative:Designed around the von Neumann architecture. ~Computation is performed through statements that change a programs state. Central features are variables, assignment statements, and iteration; sequencing of commands, explicit state update via assignment. May include : OO programming languages, scripting languages, visual languages. Examples: Fortran, Algol ,Pascal, C/C++, Java, Perl, JavaScript, Visual BASIC .NET Functional :Main means of making computations is by applying functions to given parameters. Examples: LISP, Scheme, ML, Haskell May include OO concepts. Logic :Rule-based (rules are specified in no particular order). Computations are made through a logical inference process. Example: Prolog, CLIPS. May include OO concepts.

Implementation Methods:
Compilation: Programs are translated into machine language & system calls. Interpretation: Programs are interpreted by another program an interpreter. Hybrid: Programs are translated into an intermediate language that allows easy interpretation. Just-in-Time: Hybird + compile subprograms code the first time they are called.

Compilation:
Translate high-level program (source language) into machine code (machine language). Slow translation, fast execution. Compilation process has several phases: lexical analysis: converts characters in the source program into lexical units (e.g. identifiers, operators, keywords). syntactic analysis: transforms lexical units into parse trees which represent the syntactic structure of program. semantics analysis: check for errors hard to detect during syntactic analysis; generate intermediate code. code generation: machine code is generated.

Linking: the process of collecting system program units and other user libraries and linking them to a user program. Load module(executable image): the user and system code together.

Interpretation
Interpreter usually implemented as a read-eval-printloop: -read expression in the input language (usually translating it in some internal form) evaluates the internal form of the expression print the result of the evaluation loops and reads the next input expression until exit. Interpreter acts as a virtual machine for the source language: fetch-executecycle replaced by the read-eval-printloop. usually has a core component, called the interpretter run-time , that is a compiled program running on the native machine.

The Interpretation Process:

Interpretation:
Easier implementation of programs (run-time errors can easily and immediately be displayed). Slower execution (10 to 100 times slower than compiled programs). Often requires more memory space. Now rare for traditional high-level languages. Significant comeback with some Web scripting languages (e.g., JavaScript, PHP)

Hybrid Implementation:
A compromise between compilers and pure interpreters. A high-level language program is translated to an intermediate language that allows easy interpretation. Faster than pure interpretation. Examples: Perl programs are partially compiled to detect errors before interpretation. Initial implementations of Java were hybrid: the intermediate form, byte code, provides portability to any machine that has a byte code interpreter and a run-time system (together, these are called Java Virtual Machine)

The Hybrid Implementation Process:

Just-in-Time Implementation

Initially translate programs to an intermediate language. Then compile the intermediate language of the subprograms into machine code when they are called. Machine code version is kept for subsequent calls. JIT systems are widely used for Java programs. .NET languages are implemented with a JIT system.

Preprocessors:
Preprocessor is run before compiler, as a macro expander. Macros are commonly used to: specify that code from another file is to be included; define simple expressions/functions. A well-known example: C preprocessor expands #include, #define, and similar macros.

Layered Interface of Virtual Computers

You might also like