UNIT-1 Language Evaluation Criteria:: (1) Readability

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 11

UNIT-1

Language Evaluation Criteria:


The design and evaluation of programming languages is a challenging area because - as we shall see - there is no such
thing as a "best" language. Instead, existing languages are strong by some criteria and
weak by the others, so that the choice of a language for a particular purpose is tied to a decision as to which criteria
are most important. B. We will now consider a number of criteria which can be used in developing a language design,
or evaluating an existing one.

The most important criteria for judging a programming language are

1. Readability
2. Writability
3. Reliability
4. Cost
(1)Readability

The ease with which programs can be read and understood is called readability. The following describe characteristics that
contribute to the readability of a PL

a) Simplicity- The language that has large no. of basic components is more difficult is more difficult to learn than one with a
small no of basic components. The language should not have multiplicity of commands. For eg. I = I + 1 ; I + = 1 ;I + + ; + + I .
The language should not have operator overloading in which a single operator symbol has more than one meaning

b) Orthogonal – It means that a relatively small number of primitive constructs can be combined in a number of ways to build
the program. Orthogonal language is independent of the context of its appearance in the program.

c) Control Statements- A program that can be read from top to bottom is much easier to understand than a program that
requires the reader to jump from one statement to some other non adjacent statement.

d) Data Types and Structures – The presence of adequate facilities for defining data types and data structures in a language is
another significant aid to readability. There should be provision for data types, for record type of data types(representing an
array of employee records)

e)Syntax considerations – Syntax is the form of elements of language. There are 3 types of syntactic design choices that affect
readability. Different forms of identifiers,
special keywords (reserve words),
Form & meaning – constructs that are similar in appearance but different
meaning is not readable.

(2) Writability

The measure of how easily a language can be used to create programs for a chosen problem domain. The features that affect
the readability of a also affect the writability apart from them, the factors that influence writability are

( I ) Support for abstraction – process & data abstraction both


( II ) Expressivity- The great deal of computation must be accomplished with a very small program

(3) Reliability

A program is said to be reliable if it performs to its specifications under all conditions. Along with all the features that affect
readability and writability there are several other features that affect reliability

a)Type checking – It is the testing for type errors in a given program either by compiler or during program execution.
Runtime checking is expensive. Examples of failures of type checking

(i) Countless loops


(ii) Formal and actual parameter being of different types
(iii) Array out of bounds
b) Exception Handling

The ability of a program to intercept run-time errors, take corrective measures and then continue is a great aid to
reliability. ADA, C++, Java include this capability whereas C, FORTRAN don’t.

(4) Cost

The ultimate cost of a programming language is a function of many of its characteristics

a) The cost of training programmers


b) The cost of writing programs
c) The cost of compiling programs
d) The cost of executing programs
e) The cost of Language implementation System
f) The cost of poor reliability
g) The cost of maintaining programs

Influences on Language design:

Language categories:

Programming Paradigms:-

1) Imperative:

In computer science, imperative programming is a programming paradigm that describes computation in terms


of statements that change a program state. In much the same way that imperative mood in natural
languages expresses commands to take action; imperative programs define sequences of commands for the
computer to perform.

In contrast to functional programming, in which you calculate a value by applying a function to its arguments without
caring how the operations are carried out, imperative programming is closer to the machine representation, as it
introduces memory state which the execution of the program’s actions will modify. We call these actions of
programs instructions, and an imperative program is a list, or sequence, of instructions. The execution of each
operation can alter the memory state. We consider input-output actions to be modifications of memory, video
memory, or files.
The imperative programming paradigm is an abstraction of real computers which in turn are based on the Turing
machine and the Von Neumann machine with its registers and store (memory). At the heart of these machines is the
concept of a modifiable store. Variables and assignments are the programming language analog of the modifiable
store. The store is the object that is manipulated by the program. Imperative programming languages provide a
variety of commands to provide structure to code and to manipulate the store. Each imperative programming
language defines a particular view of hardware. These views are so distinct that it is common to speak of a Pascal
machine, C machine or a Java machine. A compiler implements the virtual machine defined by the programming
language in the language supported by the actual hardware and operating system.

In imperative programming, a name may be assigned to a value and later reassigned to another value. The collection
of names and the associated values and the location of control in the program constitute thestate. The state is a
logical model of storage which is an association between memory locations and values. A program in execution
generates a sequence of states (See Figure N.1). The transition from one state to the next is determined by
assignment operations and sequencing commands.

2) Object Oriented:

Object-oriented programming (OOP) is a programming language model organized around "objects" rather
than "actions" and data rather than logic. Historically, a program has been viewed as a logical procedure that
takes input data, processes it, and produces output data.
A type of programming in which programmers define not only the data type of a data structure, but also the
types of operations (functions) that can be applied to the= data structure. In this way, the data structure
becomes an object that includes both data and functions. In addition, programmers can create relationships
between one object and another. For example, objects can inherit characteristics from other objects
The object-oriented paradigm was first conceived in the 1960's and implemented in languages such as
SIMULA-67. One of the initial concerns with early object-oriented languages was their efficiency. Programs
written using structured languages, such as Pascal and C, executed faster than programs written using early
object-oriented languages. Although programs which used the object-oriented programming were more
extensible and easier to maintain from a programmer's point of view

Object-oriented programming is a method of implementation in which programs are organized as


cooperative collections of objects, each of which represents an instance of some class, and whose classes are
all members of a hierarchy of classes united via inheritance relationships.''

From this definition, one can infer that object-oriented programming consists of instantiating a number of
objects which communicate with one another so as to achieve some desired behaviour. This paradigm is
natural with how humans see the world; as a series of cause-effect relationships, where an action performed
on one object has effects on the objects with which it communicates.

Object-Oriented Programming (OOP), in computer science, type of high-level computer language that uses
self-contained, modular instruction sets for defining and manipulating aspects of a computer program.
These discrete, predefined instruction sets are called objects and they may be used to define variables, data
structures, and procedures for executing data operations.

Functional Programming:

In computer science, functional programming is a programming paradigm that treats computation as the evaluation


of functions and avoids state and mutable data. It emphasizes the application of functions, in contrast to
the imperative programming style, which emphasizes changes in state.[1] Functional programming has its roots in
the lambda calculus, a formal system developed in the 1930s to investigate function definition, function application,
and recursion. Many functional programming languages can be viewed as elaborations on the lambda calculus.

Functional programming should not be confused with imperative (or procedural) programming. Neither is it like
object oriented programming. It is something different. Not radically so, since the concepts that we will be
exploring are familiar programming concepts, just expressed in a different way. The philosophy behind how these
concepts are applied to solving problems is also a little different.

Functional programming is all about expressions. In fact another way to describe FP might be to term it expression
oriented programming since in FP everything reduces to an expression. You should recall that an expression is a
collection of operations and variables that results in a single value. Thus x == 5 is a boolean expression. 5 + (7-Y) is
an arithmetic expression. And "Hello world".uppercase() is a string expression. The latter is also a function call (Or
more strictly a method call) on the string object "Hello world" and, as we shall see, functions are very important in
FP (You might already have guessed that from the name!). Functions are used as objects in FP. That is they are
often passed around within a program in much the same way as other variables.

In practice, the difference between a mathematical function and the notion of a "function" used in imperative
programming is that imperative functions can have side effects, changing the value of already calculated
computations.

Programming in a functional style can also be accomplished in languages that aren't specifically designed for
functional programming. For example, the imperative Perl programming language has been the subject of a book
describing how to apply functional programming concepts.[20] Javascript, one of the most widely employed languages
today, incorporates functional programming capabilities.

Logic Programming:

Logic programming is, in its broadest sense, the use of mathematical logic for computer programming. Logic is used
as a purely declarative representation language, and a theorem-prover or model-generator is used as the problem-solver. The
problem-solving task is split between the programmers, who are responsible only for ensuring the truth of programs expressed in
logical form, and the theorem-prover or model-generator, which is responsible for solving problems efficiently.

A logic program consists of a set of axioms and a goal statement. The rules of inference are applied to determine
whether the axioms are sufficient to ensure the truth of the goal statement. The execution of a logic program
corresponds to the construction of a proof of the goal statement from the axioms.

In the logic programming model the programmer is responsible for specifying the basic logical relationships and does
not specify the manner in which the inference rules are applied. Thus

Logic + Control = Algorithms

Logic programming is based on tuples. Predicates are abstractions and generalization of the data type of tuples.
Recall, a tuple is an element of

S0 × S1 × ... × Sn

The squaring function for natural numbers may be written as a set of tuples as follows:

{(0,0), (1,1), (2,4) ...}


Such a set of tuples is called a relation and in this case the tuples define the squaring relation.

sqr = {(0,0), (1,1), (2,4) ...}

Abstracting to the name sqr and generalizing an individual tuple we can define the squaring relation as:

sqr = (x,x2)

Logic programming has many application areas:

 Relational Data Bases


 Natural Language Interfaces
 Expert Systems
 Symbolic Equation solving
 Planning
 Prototyping
 Simulation
 Programming Language Implementation

Language Implementation:

A language implementation system cannot be the only software on a computer. Also require a large collection of
programs, called an operating system, which provides high level primitives then those of the machine language.
These primitives provide system resources management, input and output operations, and a variety of other
commonly needed functions. Because language implementations system needed many of the operating system
facilities, they interface to the os rather than directly to the processor.

The os and the language implementations are layered over the machine language interface of a computer. Thee layer
can be though as a virtual computer. Provide interface to the user at a higher level.
A programming language implementation is a system for executing programs written in a programming language.

There are two general approaches to programming language implementation:

 Interpretation: An interpreter takes as input a program in some language, and performs the actions written in that
language on some machine. This technique called pure interpretation or simply interpretation has the advantage of allowing
easy implementation of many source level debugging operations. On the other hand, this method has serious disadvantage
that execution is 10 to 100 times slower than in complied systems. Another disadvantage of pure interpretations is that it
often requires more space.
 Compilation: A compiler takes as input a program in some language, and translates that program into some other
language, which may serve as input to another interpreter or another compiler. The language translates is called a source
language. The process of compilation takes place in several phases.

Notice that a compiler does not directly execute the program. Ultimately, in order to execute a program via compilation, it must be
translated into a form that can serve as input to an interpreter.

When a piece of computer hardware can interpret a programming language directly, that language is called machine code. A so-
called native code compiler is one that compiles a program into machine code. Actual compilation is often separated into multiple
passes, like code generation (often in for of assembler language), assembling (generating native code), linking, loading and
execution.

If compiler of given high level language produces another high level language it is called translator (source to source translation),
which is often useful to add extensions to existing languages or to exploit good and portable implementation of other language
(for example C), simplifying development.

Many combinations of interpretation and compilation are possible, and many modern programming language implementations
include elements of both. For example, the Smalltalk programming language is conventionally implemented by compilation
into byte code, which is then either interpreted or compiled by a virtual machine (most popular ways is to use JIT or AOT
compiler compilation). This implementation strategy has been copied by many languages since Smalltalk pioneered it in the
1970s and

Programming Environment:
A programming environment is the collection of tools used in the development of software. This collection may consist of only a
file system, a text editor, a linker, and a compiler. Or it may include a large collection of integrated tools, each accessed through a
uniform user interface. In the latter case, the development and maintenance of software is greatly enhanced. We now briefly
described several programming environments.

UNIX is an older programming environment, first distributed in the middle 1970’s, built around a portable time sharing
operating systems,. It provides a wide array of powerful support tools for software production and maintenance in a variety of
languages. In the past, the most important feature of UNIX is absent was a uniform interface among its tools. This made it more
difficult to learn and to use. However, UNIX is now often used through a graphical interface that runs on top of UNIX. One
example of such a graphical interface is the common desktop environment.

Borland c++ is a programing environment that runs on ibm pc microcomputer systems and compatible clones. It provides
an integrated compiler, editor, debugger, and file system, where all for are accessed through a graphical interface .one
convenient feature of this kind of environment is that when the complier encounters a syntax error ,it stops and switches to the
editor ,leaving the cursor at this point in the source program where the error was detected.

Small talk is a language and an integrated programming environment but the small talk programming environment is more
elaborate than Borland c++, Smalltalk was the first system to make use of a windowing system and a mouse pointing device to
provide the user with a uniform interface to all the tools .Smalltalk is discussed in chapter 12.

The latest step in the evolution of software development environments is represented by Microsoft visual c++.this is a large and
elaborate collection of software development tools ,all used through a windowed interface. This system, along with other similar
systems such as visual basic, Delphi and Borland’s builder, provide simple ways of constructing graphical user interfaces to
programs.

It is clear that most software development, at least in the near future, will make use of powerful programming environments .this
will undoubtedly increase software productivity and perhaps also raise the quality of the software produced.

Issues in Language Translation:

1) Syntax:

Programming language's surface form is known as its syntax. Most programming languages are purely textual; they
use sequences of text including words, numbers, and punctuation, much like written natural languages. On the other
hand, there are some programming languages which are more graphical in nature, using visual relationships between
symbols to specify a program.

The syntax of a language describes the possible combinations of symbols that form a syntactically correct program.
The meaning given to a combination of symbols is handled by semantics (either formal or hard-coded in a reference
implementation). Since most languages are textual, this article discusses textual syntax.

Programming language syntax is usually defined using a combination of regular expressions (for lexical structure) and
Backus (for grammatical structure).
2) Semantics:
The semantics of programming languages are rarely defined formally. Where the syntax is defined using formal
grammars, at best the semantics are described in a carefully written English document, and at worst defined only by
a reference implementation, where the semantics are defined as the behavior of one implementation of the
language, bugs and all. The semantics of languages such as C and Java are defined by documentation, where
languages such as Perl and Ruby have a reference implementation.

The static semantics defines restrictions on the structure of valid texts that are hard or impossible to express in standard syntactic
formalisms.[1] For compiled languages, static semantics essentially include those semantic rules that can be checked at compile
time. Examples include checking that every identifier is declared before it is used (in languages that require such declarations) or
that the labels on the arms of a case statement are distinct.[28] Many important restrictions of this type, like checking that
identifiers are used in the appropriate context (e.g. not adding a integer to a function name), or that subroutine calls have the
appropriate number and type of arguments can be enforced by defining them as rules in a logic called a type system. Other forms
of static analyses like data flow analysis may also be part of static semantics. Newer programming languages
like Java and C# have definite assignment analysis, a form of data flow analysis, as part of their static semantics.

Syntax versus semantics


The syntax of a language describes the form of a valid program, but does not provide any information about the meaning of the
program or the results of executing that program. The meaning given to a combination of symbols is handled by semantics
(either formal or hard-coded in a reference implementation). Not all syntactically correct programs are semantically correct.
Many syntactically correct programs are nonetheless ill-formed, per the language's rules; and may (depending on the language
specification and the soundness of the implementation) result in an error on translation or execution. In some cases, such
programs may exhibit undefined behavior. Even when a program is well-defined within a language, it may still have a
meaning that is not intended by the person who wrote it.

Using natural language as an example, it may not be possible to assign a meaning to a grammatically correct sentence or the
sentence may be false:

 "Colorless green ideas sleep furiously." is grammatically well-formed but has no generally accepted meaning.
 "John is a married bachelor." is grammatically well-formed but expresses a meaning that cannot be true.

The following C language fragment is syntactically correct, but performs an operation that is not semantically defined
(because p is a null pointer, the operations p->real and p->im have no meaning):

Backus Naur Form: A landmark paper describing


In computer science, Backus–Naur Form (BNF) is a metasyntax used to express context-free grammars: that is, a formal way to
describe formal languages. John Backus and Peter Naur developed a context free grammar to define the syntax of a
programming language by using two sets of rules: i.e., lexical rules and syntactic rules.

BNF is widely used as a notation for the grammars of computer programming languages, instruction sets and communication


protocols, as well as a notation for representing parts of natural grammars. Many textbooks for programming language theory
and/or semantics document the programming language in BNF.

A BNF specification is a set of derivation rules, written as


<symbol> ::= __expression__

Context free grammar:

n formal language theory, a context-free grammar (CFG), sometimes also called a phrase structure grammar is a grammar which
naturally generates a formal language in which clauses can be nested inside clauses arbitrarily deeply, but where grammatical
structures are not allowed to overlap.

n a context free grammar the left hand side of a production rule is always a single nonterminal symbol. In a general grammar, it
could be a string of terminal and/or nonterminal symbols. The term "context-free" means that the rules by which nonterminal are
rewritten do not depend on the surrounding symbols, the context.

Context-free languages are exactly those which can be understood by a finite state computer with a single infinite stack. In order
to keep track of nested units, one pushes the current parsing state at the start of the unit, and one recovers it at the end.

Context-free grammars play a central role in the description and design of programming languages and compilers. They are also
used for analyzing the syntax of natural languages. Noam Chomsky has posited that all human languages are based on context
free grammars at their core, with additional processes that can manipulate the output of the context free component (the
transformations of early Chomskyan theory).
Parse Tree:

A concrete syntax tree or parse tree is an (ordered, rooted) tree that represents the syntactic structure of


a string according to some formal grammar. In a parse tree, the nodes are labeled by non-terminals of the grammar,
while the leaf nodes are labeled by terminals of the grammar. Parse trees may be generated for sentences in natural
languages (see natural language processing), as well as during processing of computer languages, such
as programming languages. Parse trees are distinct from abstract syntax trees (also known simply as syntax trees), in
that their structure and elements more concretely reflect the syntax of the input language.
In a parse tree, each node is either a root node, a branch node, or a leaf node. In the example to the right, S is a root
node, NP and VP are branch nodes, while John, hit, the, and ball are all leaf nodes.

A node can also be referred to as parent node or a child node. A parent node is one that has at least one other node
linked by a branch under it.

You might also like