Unit 1: 22Cs320 Theory and Design of Programming Languages
Unit 1: 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
• Sequential Programming
– Procedural Programming
– Object Oriented Programming
• Parallel Programming
– Concurrent Programming
Procedural Programming
• Types
– Logic programming paradigms
– Functional programming paradigms
– Database/Data driven programming approach
Logic Programming Paradigm
• 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
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
• 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
• 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