0% found this document useful (0 votes)
6 views

Elements of Programming Languages Lessonsummarised Vs

Uploaded by

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

Elements of Programming Languages Lessonsummarised Vs

Uploaded by

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

Programming language history

• Pseudocodes (195X) – Many


• Fortran (195X) – IBM, Backus
• Lisp (196x) – McCarthy
• Algol (1958) – Committee (led to Pascal, Ada)
• Cobol (196X) – Hopper
• Functional programming – FP, Scheme, Haskell, ML
• Logic programming – Prolog
• Object oriented programming – Smalltalk, C++, Python, Java
• Aspect oriented programming – AspectJ, AspectC++
• Parallel / non-deterministic programming
Programming Paradigms
Definitions
• Programming Language
– notation for specifying programs/computations
– consists of words, symbols, and rules for writing a
program
• Programming Paradigm
– programming “technique”
– way of thinking about programming
– view of a program
Where Do Paradigms Come From?
• Paradigms emerge as the result of social processes in
which people develop ideas
and create principles and practices that embody
those ideas
– Thomas Kuhn. “The Structure of Scientific Revolutions.”
• Programming paradigms are the result of people’s
ideas about how programs should be constructed
– … and formal linguistic mechanisms for expressing them
– … and software engineering principles and practices for
using the resulting programming language to solve
problems
slide 4
Programming Paradigms
• Imperative/Procedural Programming
– program as a collection of statements and procedures
affecting data (variables)
• Functional Programming
– program as a collection of (math) functions
• Event Driven
- Execution is dependent on the initiation of an event
• Object-Oriented Programming
– program as a collection of classes for interacting objects
Some Languages by Paradigm
• Imperative (also called Structured or
Procedural) Programming
– FORTRAN, BASIC, COBOL, Pascal, C
• Object-Oriented Programming
– Python, SmallTalk, C++, Java
• Functional Programming
– LISP, ML, Haskell
• Event Driven - VB
Paradigm Change

• For example, from Procedural to Object-Oriented


Programming
• Arises from problems encountered in one paradigm
but addressed in another
• Case study: from C to C++ to Python
– Evolution from procedural, to modular, to object-based, to
object-oriented programming
Elements of Programming
Languages
What Do They Have in Common?
• Lexical structure and analysis
– Tokens: keywords, operators, symbols, variables
– Regular expressions and finite automata
• Syntactic structure and analysis
– Parsing, context-free grammars
• Pragmatic issues
– Scoping, block structure, local variables
– Procedures, parameter passing, iteration, recursion
– Type checking, data structures
• Semantics
– What do programs mean and are they correct slide 9
Variables and Constants
Variables: Named data storage. Variables are terms which can change or
vary over time. Its value does not remain constant, unlike constants.
For example, the height and weight of a person do not always remain
constant, and hence they are variables.
In an algebraic equation, x+y = 8, x and y are the variables whose
values can be changed.

Constant: A constant can be defined as a fixed value variable, which is


used in algebraic expressions and equations.
A constant does not change over time and has a fixed value.
e.g pi in calculating area of a circle.
Operators +, -
Expressions a=a+z
Control Structures
• A way to specify flow of control in programs. Any
algorithm or program can be more clear and
understood if they use self-contained modules called
as logic or control structures.
• It basically analyzes and chooses in which direction a
program flows based on certain parameters or
conditions.
• There are three basic types of logic, or flow of control,
known as:
1. Sequence logic, or sequential flow
2. Selection logic, or conditional flow
3. Iteration logic, or repetitive flow
Sequential Logic
Follows a serial or sequential flow in which the
flow depends on the series of instructions
given to the computer.
Unless new instructions are given, the modules
are executed in the obvious sequence.
Selection Logic
Involves a number of conditions or parameters
which decides one out of several written
modules.
The structures which use these type of logic are
known as Conditional Structures. These
structures can be of three types:
• Single alternative
• Double alternative
• Multiple alternatives
Single Alternative

This structure has the form:


If (condition)
[Statements]
[End of If structure]
Double Alternative

This structure has the form:


If (Condition)
[Statement A] Else:
[Statement B]
[End if structure]
Multiple Alternatives
This structure has the form:
If (condition A)
[Statement A]
Else if (Condition B)
[Statement B]
.. ..
Else if (condition N)
[Statement N]
[End If structure]
Iteration Logic (Repetitive Flow
The Iteration logic employs a loop which involves
a repeat statement followed by statements
known as the body of a loop.
The two types of these structures are:
For Loop Structure
This structure has the form:
for i = A to N by I:
[Statements]
[End of loop]
While loop
It also uses a condition to control the loop. This
structure has the form:
while (condition)
[Statements]
[End of Loop]
To do
To look at the Do..while.
Draw flowcharts of all the loops
Python - Functions
• A function is a block of organized, reusable code that is
used to perform a single, related action.
• Functions provides better modularity for your
application and a high degree of code reusing.

• Python gives you many built-in functions like print()


etc.
but you can also create your own functions.

These functions are called user-defined functions.


Defining a Function
• Function blocks begin with the keyword def followed
by the function name and parentheses ( ( ) ).
• Any input parameters or arguments should be
placed within these parentheses. You can also define
parameters inside these parentheses.
• The code block within every function starts with a
colon (:) and is indented.
• The statement return [expression] exits a function,
optionally passing back an expression to the caller. A
return statement with no arguments is the same as
return None.
• Syntax:
def functionname( parameters ):
return [expression]

By default, parameters have a positional behavior, and


you need to inform them in the same order that
they were defined.
• Example:

• def prime():
a=1
print(a)
prime()
Practice Questions
Write a program using functions and other program
constructs that allows a tollgate cashier to input the
customer vehicle number, vehicle type and amount.
The program should also be able to restrict valid data to
be captured and compute the following:
a) Total amount obtained each day.
b) Average amount obtained each hour.

Using functions write a code snippet:


a) To count the number of days in a year.
b) To get the dates of yesterday, today and tomorrow.

You might also like