B.tech CS S8 Principles of Programming Languages Notes Module 1

  • View
    171

  • Download
    2

Embed Size (px)

DESCRIPTION

B.tech CS S8 Principles of Programming Languages Notes Module 1

Text of B.tech CS S8 Principles of Programming Languages Notes Module 1

MODULE IIntroduction Role of programming languages - Effects of Environments on languages Language Design issues - Virtual computers and binding times, Language Paradigms.

LANGUAGE DESIGN ISSUESA programming language is a notation for the description of algorithms and data structures. WHY STUDY PROGRAMMING LANGUAGES? There are six primary reasons: 1. To improve your ability to develop effective algorithms Many languages provide features, that when used properly, are of benefit to the programmer but, when used improperly, may waste large amounts of computer time or lead the programmer into time-consuming logical errors. Even a programmer who has used a language for years may not understand all of its features. A typical example is recursion a handy programming feature that, when properly used, allows the direct implementation of elegant and efficient algorithms. When used improperly, it may cause an excessive increase in execution time. 2. To improve your use of your existing programming language By understanding how features in your language are implemented, you greatly increase your ability to write efficient programs. For example, understanding how data such as arrays, strings, lists, or records are created and manipulated by your language, knowing the implementation details of recursion, or understanding how object classes are built allows you to build more efficient programs consisting of such components. 3. To increase your vocabulary of useful programming constructs By studying the constructs provided by a wide range of languages, a programmer increases his programming vocabulary. The understanding of implementation techniques is particularly important because, to use a construct while programming in a language that does not provide it directly, the programmer must provide an implementation of the construct in terms of the primitive elements actually provided by the language. For example, the subprogram control structure known as a coroutine is useful in many programs, but few languages provide a coroutine feature directly.1

4. To allow a better choice of programming language Knowledge of a variety of languages may allow the choice of just the right language for a particular project, thereby reducing the required coding effort. Knowledge of the basic features of each languages strengths and weaknesses gives the programmer a broader choice of alternatives. Applications requiring numerical calculations can be easily designed in languages like C, FORTRAN or Ada. Developing applications useful in decision making, such as in artificial intelligence applications, would be more easily written in LISP, ML, or Prolog. Internet applications are more readily designed using Perl and Java. 5. To make it easier to learn a new language A linguist, through a deep understanding of the underlying structure of natural languages, often can learn a new foreign language more quickly and easily than struggling novices who understand little of the structure even of their native tongue. Similarly, a thorough knowledge of a variety of programming language constructs and implementation techniques allows the programmer to learn a new programming language more easily when the need arises. 6. To make it easier to design a new language Many new languages are based on C or Pascal as implementation models. This aspect of program design is often simplified if the programmer is familiar with a variety of constructs and implementation methods from ordinary programming languages.

ROLE OF PROGRAMMING LANGUAGESFactors influencing the revision of language: 1. Computer capabilities Computers have evolved from the small, slow, and costly vacuum-tube machines of the 1950s to the supercomputers and microcomputers of today. At the same time, layers of operating system software have been inserted between the programming language and the underlying computer hardware. These factors have influenced both the structure and cost of using the features of high-level languages. 2. Applications Computer use has spread rapidly from the original concentration on military, scientific, business, and industrial applications in the 1950s, where the cost could be justified, to the computer games, PCs, Internet, and applications in every area of human activity seen

2

today. The requirements of these new application areas affect the designs of new languages and the revisions and extensions of older ones. 3. Programming methods Language designs have evolved to reflect our changing understanding of good methods for writing large and complex programs and to reflect the changing environment in which programming is done. 4. Implementation methods The development of better implementation methods has affected the choice of features to include in new language designs. 5. Theoretical studies Research into the conceptual foundation for language design and implementation, using formal mathematical methods, has deepened our understanding of the strengths and weaknesses of language features, which has influenced the inclusion of these features in new language designs. 6. Standardization The need for standard languages that can be implemented easily on a variety of computer systems, which allow programs to be transported from one computer to another, has provided a strong conservative influence on the evolution of language designs.

1. WHAT MAKES A GOOD LANGUAGE Attributes of a Good Language 1. Clarity, simplicity, and unity A programming language provides both a conceptual framework for thinking about algorithms and a means of expressing those algorithms. The language should be an aid to the programmer long before the actual coding stage. It should provide a clear, simple, and unified set of concepts that can be used as primitives in developing algorithms. To this end, it is desirable to have a minimum number of different concepts, with the rules for their combination being as simple and regular as possible. We call this attribute conceptual integrity. The syntax of a language affects the ease with which a program may be written, tested, and later understood and modified. The readability of programs in a language is a3

central issue here. A syntax that is particularly terse of cryptic often makes a program easy to write but difficult to read when the program must be modified later. Many languages contain syntactic constructs that encourage misreading by making two almost identical statements actually mean radically different things. For example, the presence of a blank character, which is an operator, in a SNOBOL4 statement may entirely alter its meaning. A language should have the property in which constructs that mean different things look different; that is, semantic differences should be mirrored in the language syntax. 2. Orthogonality The term orthogonality refers to the attribute of being able to combine various features of a language in all possible combinations, with every combination being meaningful. For example, suppose a language provides for an expression that can produce a value, and it also provides for a conditional statement that evaluates an expression to get a true or false value. These two features of the language, expression and conditional statement, are orthogonal if any expression can be used (and evaluated) within the conditional statement. When the features of a language are orthogonal, the language is easier to learn and programs are easier to write because there are fewer exceptions and special cases to remember. The negative aspect of orthogonality is that a program will often compile without errors even though it contains a combination of features that are logically incoherent or extremely inefficient to execute. 3. Naturalness for the application A language needs a syntax that, when properly used, allows the program structure to reflect the underlying logical structure of the algorithm. Ideally, it should be possible to translate such a program design directly into appropriate program statements that reflect the structure of the algorithm. Sequential algorithms, concurrent algorithms, logic algorithms, and others all have differing natural structures that are represented by programs in those languages. The language should provide appropriate data structures, operations, control structures, and a natural syntax for the problem to be solved. 4. Support for abstraction Many times languages fail to implement many real life problems into programs. There is always a gap between abstract data structures and operations. Even most natural programming language fails to bridge the gap. For example: Consider a situation where a4

scheduling is to be done for college student for attending a lecture in a class section, teacher. Suppose the requirement is to assign a student a section lecture and teacher to attend, which are common task for natural application, but are not provided by C. The need of point is to design an appropriate abstraction for the problems solution and then implementing these abstraction using most primitive features of a language. Ideally, the language should provide the data structures, data types and operations to maintain such abstractions. C++ is one of the most used language, that provide such facilities. 5. Ease of program verification The reliability of programs written in a language is always a central problem. There are many techniques for verifying that a program correctly performs its required function. A program may be proved correct by a formal verification method, it may be informally proved correct by desk checking (reading and visually checking the program text), it may be tested by executing it with test input data and checking the output results against the specifications, and so on. For large programs, some combination of all these methods is often used. Simplicity of semantic structure is a primary aspect that tends to simplify program verification. 6. Pr