Reasons For Studying Concepts of Programming Languages
Reasons For Studying Concepts of Programming Languages
-1-
concepts by those in position to choose languages will help to make best languages widely
accepted. For example FORTRAN was chosen over ALGOL 60 because programmers
and software developer managers did not understand the conceptual design of ALGOL
60: they found its description difficult to read and understand, and did not appreciate the
benefits of block structure, recursion, and well-structured controlled statements of
ALGOL 60.
II Programming/Application Domains
The appropriate language to use often depends on the application domain for the problem to be
solved: problems to be solved by digital computers may be classified according to the features that
they require from programming languages. Examples of these features are basic and structured data
types, operations on data, and control structures. In general, these features are provided in a
programming language to allow programmers to efficiently write programs to solve problems in a
particular application domain. These application domains and their associated languages follow:
3) Artificial Intelligence:
AI problems (game playing, theorem proving, knowledge representation and reasoning,
natural language processing, . . . etc) require information to be represented in symbolic form
rather than numeric form. Symbolic data is conveniently represented using linked lists (for
names) and logical formulas (for facts and rules).
The most commonly used languages in this domain are LISP for list representation of
-2-
data and PROLOG for logical formula representation of data. Examples of LISP
structures and their internal representations are provided in page 52, and an example of
LISP function is provided in pages 52 and 53. Examples of Prolog statements are
provided in page 82.
4) Systems Programming:
Systems software consists of the operating system and all the programming support tools of a
computer system: compilers, assemblers, linkers, . . . etc.
These programs are mainly used for the operation of the computer system.
A language used to write software in this domain must provide low-level features that allow
software interfaces to external devices to be written: system calls or APIs. They must also
provide for fast execution.
C is the most commonly used system programming language.
5) Web Software
A web site consists of one or more web pages.
A web page is a document or file that may contain text, graphics, music, animation,
and video.
The content of a web document is specified by using a markup language such as
HTML (XHTML).
Markup languages are not programming languages: they are used to specify the
layout of information in Web documents. However, because of the need for dynamic
Web contents, computations are often specified in a web documents.
Computations are specified in one of the following ways:
o By embedding programming codes in an HTML (XHTML) document.
o By making requests (in a Web document) that separate programs or procedures
be executed either on the Web server or by the browser.
A Web application framework is a software framework that is designed to support
the development of dynamic websites, Web applications, and Web services.
Many frameworks provide libraries for database access, frameworks to create
templates, session management, and often promote code reuse.
The following are examples of Web application frameworks:
o (Active Server Page) ASP.NET
o Common Gateway Interface (CGI).
-3-
A Web programming languages either has an associated Web application
framework or provides features that can be used for the development of Web
application frameworks.
The following are examples of Web programming languages:
o JavaScript Java Script statements are embedded in Web documents and
are interpreted by the browser.
o Java Two types of Java programs reside on a Web server:
Applets are executed by the browser on the client computer.
Servlets are executed on the Web server.
o C# and VB.NET are the most popular languages used to create Web
applications using the ASP.NET platform. However, since ASP.NET is built
on the Common Language Runtime, any supported .NET language can be
used. Programs/procedures written in these languages are either embedded in
a Web document or located on the Web server and are executed on the Web
server.
o PHP is a server-side HTML/XHTML- embedded scripting language.
o Perl is the ideal language for the CGI programming. CGI programs
reside and are executed on the Web server.
Other Web programming languages are Python, Ruby, Lua, Common Lisp, and
Smalltalk.
-4-
Imperative Languages have the following major features:
a. variables are used to represent memory locations
b. assignment statements are used to store values in memory locations
c. use of iteration as major form of repetition
d. an algorithm is specified in great detail and the specific order of execution of the
instructions/statements must be included.
e. Examples of imperative languages are C, Pascal, PL/1, COBOL, FORTRAN
Visual Languages such as Visual Basic .Net form a subcategory of imperative languages.
These languages include capabilities for drag-and-drop generation of code segments.
They also provide a simple way to generate graphical user interfaces to programs.
For example, in VB.NET, the code to produce a display or a form control such as a button or a
text box can be created with a single keystroke.
These capabilities are also available in all the other four .NET languages: C#, JScript
(Microsoft’s version of JavaScript), J# (Microsoft version of Java) and managed C++.
-5-
Recursive definition of a function to compare two lists and return TRUE if both list are equal and
FALSE otherwise.
(DEFUN EQUAL_LIST (LIST1 LIST2)
(COND
((ATOM LIST1) (EQ LIST1 LIST2))
((ATOM LIST2) >NIL)
(T (AND (EQUAL_LIST (CAR LIST1) (CAR LIST2))
(EQUAL_LIST (CDR LIST1 (CDR LIST2))))))
-6-
Object-Oriented Programming Languages have the following characteristics:
a. Data abstraction and information hiding: A programmer may create a class and hide from
its clients the implementation of that class (information hiding) and a client of a class
need not know how a class is implemented in order to use its functionality. The
description of class functionality is independent of its implementation. For example, the
class stack (with the methods push and pop).
b. Inheritance: The definition of one class (derived class) can be derived from that of
another class (base class). For example, graduate student from student, . . . etc
c. Dynamic binding of the methods: a function call is bound to a function at execution time.
In object-oriented programming, a program is viewed as a collection of entities
interacting with each other.
An example of object-oriented programming language is Smalltalk.
Languages such as C++, Eiffel and Java combine imperative and object-oriented features. These
languages are said to support object-oriented programming and are considered as a subcategory
of imperative languages.
Example of class inheritance in C++:
class employee {
public:
employee(const char *, const char *); // constructor
void print() const; // print first and last name
~employee(): // destructor
private:
char *firstname;
char *lastname;
};
class hourlyworker : public employee {
public:
hourlyworker (const char * , const char *, double, double);
double getpay() const; // calculate and return salary
Void print() const; //overriden base-class print
private:
double wage;
double hours;
};
-7-
Special-Purpose Languages
RPG (Report Program Generator):
was introduced by IBM in the 1960s for the generation of reports.
It has a fixed coding structure with formats for:
a. input specification (files and data)
b. switch specification (Boolean)
c. calculation and process
d. output specification
Simulation Languages:
The simulation of discrete systems is done by modeling these systems with a series of state
changes.
For example, in the simulation of a soda machine system, the state of the system can be the amount
of coins received so far and the types of soda cans remaining with their quantities.
A simulation technique follows the system elements through their change of state and gathers
quantitative or factual information.
This information is then used to predict the properties of the system under hypothetical situations.
SIMULA
- is a language for system description and simulation with the concept of class
- A system in this case is viewed as a collection of independent entities (objects) interacting with
each other.
- For example, for the soda machine system, the entities could be the soda machine, the can
container, and the users.
- Systems are simulated by examining the life cycles of the entities of the system.
-8-
IV Influences on Language Design
The major influences on language design have been machine architecture and software design
methodologies.
• Machine architecture: imperative languages have been designed based on the von Neumann
architecture: CPU, main memory, and I/O systems. The program to be executed and its input
data are stored in the main memory
• Software design methodologies: programming languages have been designed to support either the
top down design and step-wise refinement (process-oriented) or the object-oriented programming
methodology.
V Language Implementation
A programming language is characterized by its lexical elements, its syntax, and its semantics.
-9-
expression is either a variable, a constant, or the addition of two arithmetic expressions. The
syntactic units of this programming language may be specified using CFG as follows:
-10-
o The intermediate code is then executed using an interpreter. Examples are Perl, Lisp,
and initial implementations of Java.
o Current implementation of Java and the .NET languages use Just-in time (JIT)
implementations: the intermediate code of a method is compiled into machine
language when it is called for the first time.
The lexical analyzer reads a source program character by character; groups those characters
into words (lexems), and classifies those words into tokens and comments.
The syntax analyzer takes as input the lexems produced by the lexical analyzer; and groups the
lexems into the syntactic structures of the program. In some cases, it also generates the parse tree
of each syntactic structure.
The semantic analyzer/intermediate code generator takes as input the parse trees of the
syntactic structures produced by the syntax analyzer. The semantic analyzer checks for errors
such as type errors on the syntactic structures, and the intermediate code generator generates
the intermediate (sometimes assembly language) codes that correspond to the syntactic structures.
The code generator takes as input the intermediate codes produced by the intermediate code
generator, and translates the intermediate codes into machine language.
Some compilers also have an optimization unit which takes as input a program in an
intermediate code and make it smaller and/or faster.
The symbol table is used in the compilation process to hold all identifiers (user-defined names)
of a program with their type and attribute information. This information is placed in the table by
the lexical analyzer and the syntax analyzer, and is used by the semantic analyzer and the code
generator.
Preprocessors
The preprocessor is a program that processes a program source module immediately before it is
compiled.
Examples of preprocessor directives in the C/C++ language are #include and #define.
-11-
Examples:
#include <iomanip>
#include “mylib.h”
#define MAX 50
#define average(A, B) (A + B) / 2
Review Questions:
Part 1: Pages 34 and 35:
Review questions 2, 3, 4, 5, 7, 12, 20, 22, 23, 25, 26, 27, 28, and 30.
Part 2:
1. You work in a company that wants to use only one programming language to implement all its
programming applications. What is the most appropriate language in each of the following situations?
a. All applications have a lot of floating-point arithmetic computations and require only arrays as the
major data structure.
b. All applications are used to compute payrolls and also to generate reports.
c. Some applications have a lot of floating-point arithmetic computations and require only arrays as the
major data structure, but others are used to compute payrolls and also to generate reports.
d. All applications are used for game playing with symbolic manipulations of data represented as linked
lists.
e. All applications are used for the operation of the computer.
f. All applications are embedded in HTLM documents, and are interpreted on the server before the
document is sent to a requesting browser.
g. All applications are embedded in HTML documents and are interpreted by a browser that displays the
document.
h. All applications are common Gateway Interface (CGI) programs for the World Wide Web.
2.
a. What are the major characteristics of each of the following programming
domains: Scientific and business applications.
b. What are the most commonly used languages in each of the above programming
domains.
c. Provide two special-purpose languages with their characteristics.
3.
a) Provide the characteristics of the following high-level programming language
categories: imperative languages; functional (applicative) languages; logic
programming languages; object-oriented programming languages.
b) Provide one or more examples of each of the above programming language
-12-
categories.
c) What are the major types of statements (with their meanings) of an imperative
language?
4.
a) What are the three things that characterize a programming language?
b) What are the lexical elements of a programming language?
c) Provide the two types of semantics (each with a brief description) of a
programming language
-13-