0% found this document useful (0 votes)
12 views38 pages

Unit 1: 22Cs320 Theory and Design of Programming Languages

The document outlines the importance of studying programming languages, highlighting their role in understanding features, making informed choices, and utilizing technology effectively. It discusses various programming paradigms, including imperative and declarative styles, along with their characteristics and examples. Additionally, it covers compilation versus interpretation, implementation strategies, and the tools that support programming environments.

Uploaded by

tamilpandi469
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views38 pages

Unit 1: 22Cs320 Theory and Design of Programming Languages

The document outlines the importance of studying programming languages, highlighting their role in understanding features, making informed choices, and utilizing technology effectively. It discusses various programming paradigms, including imperative and declarative styles, along with their characteristics and examples. Additionally, it covers compilation versus interpretation, implementation strategies, and the tools that support programming environments.

Uploaded by

tamilpandi469
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 38

22CS320 THEORY AND DESIGN OF PROGRAMMING LANGUAGES

UNIT 1
Why study programming languages?
a) Understand Obscure features
b) Choose among alternatives way to express things
c) Make good use of debuggers, assemblers, linkers & related
tools
d) Simulate useful features in languages that lacks them
e) Make better use of technology wherever it appears
Programming Language

• It is Medium
• Natural - Human
• Formal-computer system for communication
• Notation- Alg+data
Introduction

What is Programming?
• Element/sentence/text with which alg and data
of the given task is represented.
• Basic building block
• Specification of computation
• Notation of writing programs
• Theory-Equally powerful/Practical- Not equally
easy to use
Need of Programming Language

• Evolution
• Special Purpose
• Personal Preference
• Expressive Power
• Ease of use of the novice
• Open source
• Excellent Compliers
• Economics
Characteristics
• Simplicity
• Write ability
• Readability
• Safety
• Robustness
• Clarity
• Unity
• Efficiency
• Compatibility
• Reliability
• Scalability
• Maintainability
• Modularity
• Portability
• Cost of use
• Programming Environment
• Flexible Program
• Verification
Basics of Programming Paradigms

Programming Paradigm

– Programming paradigms are a way to classify


programming languages based on their features.

– Programming paradigms are different ways or styles in


which a given program or programming language can
be organized.

– There are many programming languages. Each has its


own strategy (methodology) when it is implemented.
That strategy is what known as paradigms

– Programming paradigms are not languages or tools.


Basics of Programming Paradigms

Common programming paradigms


Imperative
Declarative
Imperative Programming Paradigm

• It is one of the oldest programming paradigm


• Close relation to machine architecture-based
on Von Neumann architecture
• An i m p e rati v e p ro g ram c o nsi sts o f
commands for the computer to perform.
I m p e ra t i v e p ro g ra m m i n g f o c u s e s o n
describing how a program operates step by
step, rather than on high-level descriptions of
its expected results.
• Statements or commands are used to change
the state
• Result can be achieved after executing
• Example
–C
– Fortran
– Basic
Imperative Paradigms

• Sequential Programming
– Procedural Programming
– Object Oriented Programming

• Parallel Programming
– Concurrent Programming
Procedural Programming

• Procedural programming is a programming


paradigm, derived from imperative
programming, based on the concept of the
procedure call. Procedures (a type of routine
or subroutine) simply contain a series of
computational steps to be carried out.
• It has the ability to reuse the code
Object Oriented Programming

• Object-Oriented Programming (OOP) is a


programming paradigm based on the concept
of "objects", which can contain data and code.
The data is in the form of fields (often known
as attributes or properties), and the code is in
the form of procedures (often known as
methods).
• Example C++,java,Python
Concurrent Programming

• Concurrent computing is a form of modular


programming. In its paradigm an overall
computation is factored into sub
computations that may be executed
concurrently instead of sequentially
• A parallel processing system posses many
numbers of processor with the objective of
running a program in less time by dividing
them.
• C c++ java python
Declarative programming paradigm

• that expresses the logic of a computation


without describing its control flow.
• The focus is on what needs to be done rather
how it should be done
• States the goal to be achieved explicitly
• The procedure of how to achieve is not given
explicitly
• therefore it considers programs as theories of
some logic (Mathematics / Data / Known
facts)
Declarative programming paradigm

• Types
– Logic programming paradigms
– Functional programming paradigms
– Database/Data driven programming approach
Logic Programming Paradigm

• In logic programming we have a knowledge


base which we know before and along with
the question and knowledge base which is
given to machine, it produces result.
Functional programming paradigms

• The central model for the abstraction is the


function which are meant for some specific
computation and not the data structure.
• Data are loosely coupled to functions.
• Function can be replaced with their values
without changing the meaning of the program.
• Example perl, javascript
Database/Data driven programming approach

• This programming methodology is based on


data and its movement
• file creation, data entry, update, query and
reporting functions.
• Example :SQL
Imperative languages

• Group languages as
– Imperative (performance)
• von Neumann (Fortran, Pascal, Basic, C)
• object-oriented (Smalltalk, Eiffel, C++?)
• scripting languages (Perl, Python,
JavaScript, PHP)
– Declarative (higher level) (programmer point )
• functional (Scheme, ML, pure Lisp, FP)
• Data flow (id and val)
• logic, constraint-based (Prolog, VisiCalc, RPG)
Declarative languages
a)Functional Languages:
• Employ a computational model based on the recursive definition
of functions.
• They take inspiration from the lamda calculus a formal
computational model
• Eg LISP,ML
b)Data flow Languages:
• They form the model computation as the f lo w of information
among primitive functional nodes
• Eg; id and val
Declarative languages

c)Logic or constrained based Languages:


• They model computation as an attempt to find
values
• They specify a certain relationship using a list of
logic rule
• Eg: prolog ,XSLT
Imperative languages

a) Von-nueman Languages:
• They are most familiar and successful
• They are based on statements
• The basic means of computation is modification of
variables
Eg:Fotran,ADA83,C
b)Scripting languages:
• There are subset of von-nueman languages
• Several scripting languages were developed for a purpose
• Eg:csh,bsh,awk
Imperative languages

C)Object Oriented languages:


• Most are closely related to von numen languages
• They have a more structured and distributed model of memory
and computation
• It has interactions on semi independent objects
Eg:Small talk,C++,Java
Compilation vs. Interpretation
• Compilation vs. interpretation
– not opposites
– not a clear-cut distinction
• Pure Compilation
– The compiler translates the high-level
source program into an equivalent target
program (typically in machine language),
and then goes away:
Compilation vs. Interpretation

• Pure Interpretation
– Interpreter stays around for the execution
of the program
– Interpreter is the focus of control during
execution
Compilation vs. Interpretation

• Interpretation:
– Greater flexibility
– Better diagnostics (error messages)

• Compilation
– Better performance
Compilation vs. Interpretation
• Common case is compilation or simple
pre-processing, followed by
interpretation
• Most language implementations
include a mixture of both compilation
and interpretation
Compilation vs. Interpretation

• Many compiled languages have


interpreted pieces, e.g., formats in Fortran
or C
• Some compilers produce nothing but
virtual instructions, e.g., Pascal P-code,
Java byte code, Microsoft COM+
Compilation vs. Interpretation

• Implementation strategies:
– Preprocessor
• Removes comments and white space
• Groups characters into tokens (keywords,
identifiers, numbers, symbols)
• Expands abbreviations in the style of a macro
assembler
• Identifies higher-level syntactic structures
(loops, subroutines)
Compilation vs. Interpretation
• Implementation strategies:
– Library of Routines and Linking
• Compiler uses a linker program to merge the
appropriate library of subroutines (e.g., math
functions such as sin, cos, log, etc.) into the final
program:
Compilation vs. Interpretation
• Implementation strategies:
– Post-compilation Assembly
• Facilitates debugging (assembly language
easier for people to read)
• Isolates the compiler from changes in the
format of machine language files (only
assembler must be changed, is shared by many
compilers)
Compilation vs. Interpretation

• Implementation strategies:
– The C Preprocessor (conditional
compilation)
• Preprocessor deletes portions of code, which
allows several versions of a program to be built
from the same source
Compilation vs. Interpretation

• Implementation strategies:
– Source-to-Source Translation (C++)
• C++ implementations based on the early AT&T
compiler generated an intermediate program in
C, instead of an assembly language:
Compilation vs. Interpretation
• Implementation strategies:
– Bootstrapping
– A techinique to compile the compiler for
the first place one need to start with a
simple implementation of a interpreter
– Uses it to build the more sophistated
versions
Compilation vs. Interpretation
• Implementation strategies:
– Dynamic and Just-in-Time Compilation
• In some cases a programming system may
deliberately delay compilation until the last
possible moment.
– The Java language definition defines a machine-
independent intermediate form known as byte code.
Byte code is the standard format for distribution of
Java programs.
– The main C# compiler produces .NET Common
Intermediate Language (CIL), which is then translated
into machine code immediately prior to execution.
Compilation vs. Interpretation

• Implementation strategies:
– Microcode
• Assembly-level instruction set is not
implemented in hardware; it runs on an
interpreter.
• Interpreter is written in low-level instructions
(microcode or firmware), which are stored in
read-only memory and executed by the
hardware.
Programming Environment Tools

• Compilers and Interpreters does not exist in isolation


• In older programmers all these tools may be executed
individually
• Most recent environments provide much more integrated
tools with an ide
• Programmers are assisted in their work by a host of other
tools
• Assembler, Debuggers, linkers,editors
• Pretty printer(formatting convention)
• Style checkers(syntax and semantics)
• Configuration management tools
• Profilers and other performance analysis tools

You might also like