0% found this document useful (0 votes)
6 views35 pages

Introduction

The document outlines the evolution, types, and implementation of programming languages, highlighting key topics such as compilation vs. interpretation, data types, and programming paradigms. It discusses factors that contribute to a programming language's success, including ease of use, expressive power, and backing by powerful sponsors. Additionally, it emphasizes the importance of studying programming languages to enhance language choice, learning, and effective usage.

Uploaded by

red441808
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)
6 views35 pages

Introduction

The document outlines the evolution, types, and implementation of programming languages, highlighting key topics such as compilation vs. interpretation, data types, and programming paradigms. It discusses factors that contribute to a programming language's success, including ease of use, expressive power, and backing by powerful sponsors. Additionally, it emphasizes the importance of studying programming languages to enhance language choice, learning, and effective usage.

Uploaded by

red441808
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

Introduction

Books
 Programming Languages Design and Implementation by
T. W. Prat, Pearson – Fourth Edition

 Programming Language Pragmatics – by Michael Scott,


Elsevier – Fourth Edition
Topics to be covered
• Evolution of Programming Languages
• Compilation and Interpretation
• Bootstrapping
• Data types and their implementation – Primitive and Composite
• Heap storage and heap storage management
• Garbage collection techniques
• Names - Binding, Lifetime, Scope
• Control Flow - Expression Evaluation, Assignment, Conditional,
Loop statements
• Function calls and their implementation
• Non-local variable access
• Exceptions and Exception Handling
• Modular Programming
• Object Oriented Programming and its implementation details
Introduction
 Why are there so many programming languages?
 Evolution
 We've learned better ways of doing things over
time
 Structured programming,” in which the goto-
based control flow of languages like Fortran,
Cobol, and Basic gave way to while loops, case
(switch) statements, and similar higher level
constructs
 Object-oriented structure of Smalltalk, C++, Eiffel,
and then, like Java and C#.
 Scripting languages like Python, Ruby, etc.
Introduction Cont..
– Orientation toward special purposes
– Languages were designed for a specific problem
domain
- The various Lisp dialects are good for
manipulating symbolic data and complex
data structures
- Icon and Awk are good for manipulating
character strings
- C is good for low-level systems programming.
- Prolog is good for reasoning about logical
relationships among data.
- Emphasis clearly on the specialty.
Introduction Cont..
Personal Preference
– Different people like different things.
– C -some people love the briefness of C; some do
not like it.
– Some people think recursively; others prefer
iteration.
– Some people like to work with pointers; others
prefer the implicit dereferencing of Lisp, Clu,
Java, and ML.
– No one is standard and universally acceptable
programming language.
Introduction Cont..
– Socio-economic factors: proprietary interests,
commercial advantage
– PL-I with IBM

– JAVA -SUN and later by Oracle

– C#/ [Link] languages of Microsoft.

– Objective-C for iPhone and iPad apps.

– Programmers would be so inclined to use the language


that the same would be used instead of introducing new
one.
What makes a language successful?
– Easy to use for the Novice (BASIC, Pascal, JAVA, etc.)

– Expressive Power: Language features which makes clear,


maintainable code, C++ vs Basic. Abstraction facilities of
C++ over Basic.

– Easy to implement (BASIC, Forth): Basic could be


implemented on tiny machines with limited resources.
Pascal was portable and free to the universities over the
world. Java and Python too.

– Excellent Compilers: possible to compile to very good


(fast/small) code (Fortran) -Excellent Compilers e.g.
pointers and recursion.
What makes a language successful?
– Backing of a powerful sponsor ( PL/1-IBM, Ada and
COBOL- US Defence,Visual Basic-Mirosoft)

– Wide dissemination at minimal cost (Pascal, Turing, Java)

– Open Source -C lang. -UNIX OS/LINUX OS


Why study programming languages?

• Help you choose a language.


– C vs. C++ vs. C# for systems programming

– Fortran vs. C for numerical computations

– PHP vs. Ruby for web-based applications

– Ada vs. C for embedded systems

– Common Lisp vs. Scheme vs. ML for symbolic data


manipulation

– Java vs. .NET for networked PC programs


Why study programming languages?
• Make it easier to learn new languages.
Some languages are similar; easy to walk down family tree.
– concepts have even more similarity; if you think in terms
of iteration, recursion, abstraction (for example), you will
find it easier to assimilate the syntax and semantic details
of a new language.

– Think of an analogy to human languages: good grasp of


grammar makes it easier to pick up new languages.
Why study programming languages?
• Help you make better use of whatever language
you use
– understand obscure features:
• In C, help you understand unions, arrays &
pointers, separate compilation, varargs (variable
number of arguments), catch and throw

• In Common Lisp, help you understand first-class


functions/closures, streams, catch and throw,
symbol internals
Why study programming languages?

• Choose among alternative ways to express things based on


the implementation costs.

• In C++, for example, programmers may need to avoid


unnecessary temporary variables, and use copy constructors
whenever possible, to minimize the cost of initialization.

• Pointers for array traversal in C.


Why study programming languages?
• Help you make better use of whatever language
you use
– figure out how to do things in languages that
don't support them explicitly:
• lack of suitable control structures in Fortran
• use comments and programmer discipline for
control structures
• lack of recursion in Fortran
• lack of named constants and enumerations in
Fortran
• use variables that are initialized once, then never
changed
• lack of modules in C and Pascal
Language types
• Imperative languages where focus is on how the
computer should do the things - more detailed

• Particularly the von Neumann languages, object-oriented


and scripting.

• In declarative languages, the focus is on what the


computer is to do -abstracted.

• Particularly the logic or constraint-based, and functional.


Language Types
• Group languages as
– imperative
• von Neumann (Fortran, Pascal, Basic, C)
• object-oriented (Smalltalk, Eiffel, C++)
• scripting languages (Perl, Python, JavaScript, PHP)
– declarative
• functional (Scheme, ML, pure Lisp, FP)
• logic or constraint-based (Prolog, VisiCalc, RPG)
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: Ex. gcc/g++
Compilation vs. Interpretation

• Pure Interpretation
– Interpreter stays around for the execution of
the program
– Interpreter is the locus of control during
execution
– Ex. Bourne Again SHell (BASH), python, perl
Compilation vs. Interpretation

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

• Compilation
– Better performance
– Everything done before run time
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

• Note that compilation does NOT have to produce machine


language for some sort of hardware.

• Compilation is translation from one language into another,


with full analysis of the meaning of the input.

• Compilation entails semantic understanding of what is being


processed; pre-processing does not.

• A pre-processor will often let errors through.


Compilation vs. Interpretation

• Many compiled languages have interpreted pieces, e.g.,


formats in Fortran or C

• Programs can compute their own formats on the fly.


• E.g. %f for float

• 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
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
• The source code is read from the file and given to the
preprocessor where it is translated into a modified source
code file which is then given to the compiler for translation
to machine language.
• The transformations performed by the preprocessor are
directed by lines in the original source file called compiler
directives.
• All such lines begin with the # character as the first non-
white space character on the line and are of one of three
types of directives:
• Macro definitions
• File inclusion
• Conditional compilation
Compilation vs. Interpretation
• Macro- Syntax:
#define
• This macro defines constant value and can be any of
the basic data types.
• Header file inclusion- Syntax: #include <file_name>
• The source code of the file “file_name” is included in
the main program at the specified place.
• Conditional compilation-
• Syntax: #ifdef, #endif, #if, #else, #ifndef
• Set of commands are included or excluded in source
program before compilation with respect to the
condition.
• Other directives -Syntax: #undef
• #undef is used to undefine a defined macro variable.
Compilation vs. Interpretation
//Demonstration of C preprocessor capabilities

//include directive, macros and #undef x


conditional compilation #define x 20
#include<stdio.h> d = d + x;
#define x 10 #ifdef DEBUG
//#define DEBUG 1 printf("debug:c = %d, d= %d\n", c, d);
int a, b, c, d; #endif
main()
printf("The sum is %d \n ", d);
{
}
printf("Welcome to DPPL sessions\n");
printf("Enter any two numbers \n");
scanf("%d%d",&a, &b);
c = a + b;
c = c + x;
printf("The sum of two numbers is %d \n ", c);
Compilation vs. Interpretation
//Demonstration of C preprocessor capabilities

//include directive, macros and #undef x


conditional compilation #define x 20
#include<stdio.h> d = d + x;
#define x 10 #ifdef DEBUG
#define DEBUG 1 printf("debug:c = %d, d= %d\n", c, d);
int a, b, c, d; #endif
main()
printf("The sum is %d \n ", d);
{
}
printf("Welcome to DPPL sessions\n");
printf("Enter any two numbers \n");
scanf("%d%d",&a, &b);
c = a + b;
c = c + x;
printf("The sum of two numbers is %d \n ", c);
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:
– 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:
– 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:
– Dynamic and Just-in-Time Compilation
• In some cases a programming system may
deliberately delay compilation until the last
possible moment.
– Lisp or Prolog invoke the compiler on the fly, to
translate newly created source into machine language,
or to optimize the code for a particular input set.
– 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.
Just-in-Time Compilation Example
Compilation vs. Interpretation

• Implementation strategies:
– Bootstrapping
References

• Programming Language Pragmatics - By


Michael Scott Elsevier -Third Edition

You might also like