Principles of programming languages, Study Guides, Projects, Research of Computer Science

UNIT 1. PRELIMINARY CONCEPTS 1.1 Reasons for Studying Concepts of Programming Languages 1.2 Programming Domains, Language Evaluation Criteria 1.3 Influences on Language Design, Language Categories 1.4 Programming Paradigms-Imperative , Functional Programming language 1.5 Language Implementation-compilation and interpretation 1.6 Programming environments

Typology: Study Guides, Projects, Research

2025/2026

Available from 06/19/2026

EXAM-I-NATION
EXAM-I-NATION 🇺🇸

541 documents

1 / 93

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
1
CONTENTS
UNIT 1. PRELIMINARY CONCEPTS
1.1
Reasons for Studying Concepts of Programming Languages
1.2
Programming Domains, Language Evaluation Criteria
1.3
Influences on Language Design, Language Categories
1.4
Programming Paradigms-Imperative , Functional Programming language
1.5
Language Implementation-compilation and interpretation
1.6
Programming environments
SYNTAX AND SEMANTICS
1.7
The General Problems of Describing Syntax and semantics
1.8
BNF
1.9
EBNF for common programming language features
1.10
Ambiguous Grammar
UNIT 2. DATA TYPES AND VARIABLES
2.1
Introduction to Primitive Data Types
2.2
User-Defined Data Types and Array Types
2.3
Record, Union and Pointer and Reference types
2.4
Names, Variables, The Concept of Binding
2.5
Type Checking, Type Compatibility
2.6
Strong Types, Named Constants, variable initialization
EXPRESSIONS AND STATEMENTS & CONTROL STRUCTURES
2.7
Expression: [Arithmetic, Relational and Boolean Expressions]
2.8
Short-Circuit Evaluation
2.9
Assignment Statements, Mixed-Mode Assignment [Referential Transparency &
Functional Programming]
2.10
Control Structures [statement Level Control Structures, Compound
statements]
2.11
Selection Statements, Iterative Statements, Unconditional Branching,
Guarded Commands
UNIT 3. SUBPROGRAMS AND BLOCKS
3.1
Fundamentals of Subprograms
3.2
Design Issues for Subprograms
3.3
Parameter Passing Methods
3.4
Parameters Subprograms as parameters
3.5
Overloaded Subprograms & Operations
3.6
Generic Subprograms, separately compiled modules
3.7
Co-
Routines
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19
pf1a
pf1b
pf1c
pf1d
pf1e
pf1f
pf20
pf21
pf22
pf23
pf24
pf25
pf26
pf27
pf28
pf29
pf2a
pf2b
pf2c
pf2d
pf2e
pf2f
pf30
pf31
pf32
pf33
pf34
pf35
pf36
pf37
pf38
pf39
pf3a
pf3b
pf3c
pf3d
pf3e
pf3f
pf40
pf41
pf42
pf43
pf44
pf45
pf46
pf47
pf48
pf49
pf4a
pf4b
pf4c
pf4d
pf4e
pf4f
pf50
pf51
pf52
pf53
pf54
pf55
pf56
pf57
pf58
pf59
pf5a
pf5b
pf5c
pf5d

Partial preview of the text

Download Principles of programming languages and more Study Guides, Projects, Research Computer Science in PDF only on Docsity!

CONTENTS

UNIT 1. PRELIMINARY CONCEPTS

1.1 Reasons for Studying Concepts of Programming Languages 1.2 Programming Domains, Language Evaluation Criteria 1.3 Influences on Language Design, Language Categories 1.4 Programming Paradigms-Imperative , Functional Programming language 1.5 Language Implementation-compilation and interpretation 1.6 Programming environments SYNTAX AND SEMANTICS 1.7 The General Problems of Describing Syntax and semantics 1.8 BNF 1.9 EBNF for common programming language features 1.10 Ambiguous Grammar UNIT 2. DATA TYPES AND VARIABLES 2.1 Introduction to Primitive Data Types 2.2 User-Defined Data Types and Array Types 2.3 Record, Union and Pointer and Reference types 2.4 Names, Variables, The Concept of Binding 2.5 Type Checking, Type Compatibility 2.6 Strong Types, Named Constants, variable initialization EXPRESSIONS AND STATEMENTS & CONTROL STRUCTURES 2.7 Expression: [Arithmetic, Relational and Boolean Expressions] 2.8 Short-Circuit Evaluation 2.9 Assignment Statements, Mixed-Mode Assignment [Referential Transparency & Functional Programming] 2.10 Control Structures [statement Level Control Structures, Compound statements] 2.11 Selection Statements, Iterative Statements, Unconditional Branching, Guarded Commands UNIT 3. SUBPROGRAMS AND BLOCKS 3.1 Fundamentals of Subprograms 3.2 Design Issues for Subprograms 3.3 Parameter Passing Methods 3.4 Parameters Subprograms as parameters 3.5 Overloaded Subprograms & Operations 3.6 Generic Subprograms, separately compiled modules 3.7 Co-Routines

UNIT IV. ABSTRACT DATA TYPES

4.1 Abstract - data types [Abstraction & Encapsulation] 4.2 Introduction to Data Abstraction, Design Issues 4.3 Language Examples 4.4 C++ Parameterized Abstract Data Types 4.5 Data Types 4.6 Object-Oriented Programming in Smalltalk 4.7 Object-Oriented Programming in C++ 4.8 Object-Oriented Programming in Java 4.9 Object-Oriented Programming in C# 4.10 Object-Oriented Programming in Ada 95 EXCEPTION HANDLING & LOGIC PROGRAMMING 4.11 Exception Handling: Exceptions, Exception Propagation 4.12 Exception Handler in Ada 4.13 C++ and Java 4.14 Logic Programming Language : Introduction An Overview of Logic Programming 4.15 The Basic Elements of PROLOG 4.16 Applications of Logic Programming UNIT-V. FUNCTIONAL PROGRAMMING LANGUAGES & SCRIPTING LANGUAGE 5.1 Functional Programming Language Introduction 5.2 Fundamentals of Functional Programming Languages, LISP Programming 5.3 Fundamentals of ML, examples 5.4 Fundamentals of Haskell, function syntax and examples 5.5 Applications of Functional Programing language and Comparison of Functional and Imperative Languages

1.2 Language Evaluation Criteria – CO1, CO

  • Readability : the ease with which programs can be read and understood
  • Writability : the ease with which a language can be used to create programs
  • Reliability : conformance to specifications (i.e., performs to its specifications)
  • Cost : the ultimate total cost Readability
  • Overall simplicity
  • A manageable set of features and constructs
  • Few feature multiplicity (means of doing the same operation)
  • Minimal operator overloading
  • Orthogonality
  • A relatively small set of primitive constructs can be combined in a relatively small number of ways
  • Every possible combination is legal
  • Control statements
  • The presence of well-known control structures ( e.g. , while statement)
  • Data types and structures
  • The presence of adequate facilities for defining data structures
  • Syntax considerations
  • Identifier forms: flexible composition
  • Special words and methods of forming compound statements
  • Form and meaning: self-descriptive constructs, meaningful keywords Writability
  • Simplicity and Orthogonality
  • Few constructs, a small number of primitives, a small set of rules for combining them
  • Support for abstraction
  • The ability to define and use complex structures or operations in ways that allow details to be ignored
  • Expressivity
  • A set of relatively convenient ways of specifying operations
  • Example: the inclusion of for statement in many modern languages Reliability
  • Type checking
  • Testing for type errors
  • Exception handling
  • Intercept run-time errors and take corrective measures
  • Aliasing
  • Presence of two or more distinct referencing methods for the same memory location
  • Readability and writability
  • A language that does not support “natural” ways of expressing an algorithm will necessarily use “unnatural” approaches, and hence reduced reliability Cost
  • Training programmers to use language
  • Writing programs (closeness to particular applications)
  • Compiling programs
  • Executing programs
  • Language implementation system: availability of free compilers
  • Reliability: poor reliability leads to high costs
  • Maintaining programs Others
  • Portability
  • The ease with which programs can be moved from one implementation to another
  • Generality
  • The applicability to a wide range of applications
  • Well-definedness
  • The completeness and precision of the language‘s official definition

1.4 Language Categories – CO

  • Imperative
    • Central features are variables, assignment statements, and iteration
    • Examples: C, Pascal
  • Functional
    • Main means of making computations is by applying functions to given parameters
    • Examples: LISP, Scheme
  • Logic
    • Rule-based (rules are specified in no particular order)
    • Example: Prolog
  • Object-oriented
    • Data abstraction, inheritance, late binding
    • Examples: Java, C++
  • Markup
    • New; not a programming per se, but used to specify the layout of information in Web documents
    • Examples: XHTML, XML

Language Design Trade-Offs

  • Reliability vs. cost of execution
    • Conflicting criteria
    • Example: Java demands all references to array elements be checked for proper indexing but that leads to increased execution costs
  • Readability vs. writability
    • Another conflicting criteria
    • Example: APL provides many powerful operators (and a large number of new symbols), allowing complex computations to be written in a compact program but at the cost of poor readability
  • Writability (flexibility) vs. reliability
    • Another conflicting criteria
    • Example: C++ pointers are powerful and very flexible but not reliably used

1.5 Implementation Methods - CO

  • Compilation
    • Programs are translated into machine language
  • Pure Interpretation
    • Programs are interpreted by another program known as an interpreter
  • Hybrid Implementation Systems
    • A compromise between compilers and pure interpreters Compilation
  • Translate high-level program (source language) into machine code (machine language)
  • Slow translation, fast execution
  • Compilation process has several phases:
  • lexical analysis: converts characters in the source program into lexical units
  • syntax analysis: transforms lexical units into parse trees which represent the syntactic structure of program
  • Semantics analysis: generate intermediate code
  • code generation: machine code is generated

Figure 1.2 Layered View of Computer: The operating system and language implementation are layered over Machine interface of a computer Figure^ 1.3^ The^ Compilation^ Process Additional Compilation Terminologies

  • Load module (executable image): the user and system code together
  • Linking and loading: the process of collecting system program and linking them to user program Execution of Machine Code
  • Fetch-execute-cycle (on a von Neumann architecture) initialize the program counter repeat forever fetch the instruction pointed by the counter increment the counter decode the instruction execute the instruction end repeat Von Neumann Bottleneck
  • Connection speed between a computer‘s memory and its processor determines the speed of a computer
  • Program instructions often can be executed a lot faster than the above connection speed; the connection speed thus results in a bottleneck
  • Known as von Neumann bottleneck; it is the primary limiting factor in the speed of computers Pure Interpretation
  • No translation
  • Easier implementation of programs (run-time errors can easily and immediately displayed)
  • Slower execution (10 to 100 times slower than compiled programs)
  • Often requires more space
  • Becoming rare on high-level languages

Syntax and Semantics

Introduction

  • Syntax: the form or structure of the expressions, statements, and program units
  • Semantics: the meaning of the expressions, statements, and program units
  • Syntax and semantics provide a language‘s definition
    • Users of a language definition
    • Other language designers
    • Implementers
    • Programmers (the users of the language)

1.7 The General Problem of Describing Syntax – CO

  • A sentence is a string of characters over some alphabet
  • A language is a set of sentences
  • A lexeme is the lowest level syntactic unit of a language ( e.g. , *, sum, begin)
  • A token is a category of lexemes ( e.g. , identifier)
  • Languages Recognizers
    • A recognition device reads input strings of the language and decides whether the input strings belong to the language
    • Example: syntax analysis part of a compiler
  • Languages Generators
    • A device that generates sentences of a language
    • One can determine if the syntax of a particular sentence is correct by comparing it to the structure of the generator

1.8 Formal Methods of Describing Syntax – CO1,CO2 20 - NOV- 25

  • Backus-Naur Form and Context-Free Grammars
    • Most widely known method for describing programming language syntax
  • Extended BNF
    • Improves readability and writability of BNF
  • Grammars and Recognizers Backus-Naur Form and Context-Free Grammars
  • Context-Free Grammars
  • Developed by Noam Chomsky in the mid-1950s
  • Language generators, meant to describe the syntax of natural languages
  • Define a class of languages called context-free languages Backus-Naur Form (BNF)
  • Backus-Naur Form (1959)
  • Invented by John Backus to describe ALGOL 58
  • BNF is equivalent to context-free grammars
  • BNF is a metalanguage used to describe another language
  • In BNF, abstractions are used to represent classes of syntactic structures-- they act like syntactic variables (also called nonterminal symbols ) BNF Fundamentals
  • Non-terminals: BNF abstractions
  • Terminals: lexemes and tokens
  • Grammar: a collection of rules
  • Examples of BNF rules:

_ → identifier | identifer, →_ if __ then __ BNF Rules

  • A rule has a left-hand side (LHS) and a right-hand side (RHS), and consists of terminal and nonterminal symbols
  • A grammar is a finite nonempty set of rules
  • An abstraction (or nonterminal symbol) can have more than one RHS _ → _ | begin __ end Describing Lists
  • Syntactic lists are described using recursion _ → ident | ident, _
  • A derivation is a repeated application of rules, starting with the start symbol and ending with a sentence (all terminal symbols) An Example Grammar _ → → | ; → = → a | b | c | d → + | - → | const_ Parse Tree A hierarchical representation of a derivation An example derivation    =  a=  a=+  a=+  a=b+  a=b+const Figure 2.1 Parse Tree Derivation
  • Every string of symbols in the derivation is a sentential form
  • A sentence is a sentential form that has only terminal symbols
  • A leftmost derivation is one in which the leftmost nonterminal in each sentential form is the one that is expanded
  • A derivation may be neither leftmost nor rightmost Ambiguity in Grammars
  • A grammar is ambiguous iff it generates a sentential form that has two or more distinct parse trees An Unambiguous Expression Grammar If we use the parse tree to indicate precedence levels of the operators, we cannot have ambiguity _ → - | → / const|const_
  • Each rule has a set of functions that define certain attributes of the nonterminals in the rule
  • Each rule has a (possibly empty) set of predicates to check for attribute consistency
  • Let X0 X1 ... Xn be a rule
  • Functions of the form S(X0) = f(A(X1), ... , A(Xn)) define synthesized attributes
  • Functions of the form I(Xj) = f(A(X0), ... , A(Xn)), for i <= j <= n, define inherited attributes
  • Initially, there are intrinsic attributes on the leaves Example
  • Syntax _ → = → + | → A | B | C_
  • actual_type: synthesized for __ and __
  • expected_type: inherited for __
  • Syntax rule : _ → [1] + [2]_ Semantic rules : .actual_type → [1].actual_type Predicate : [1].actual_type == [2].actual_type .expected_type == .actual_type
  • Syntax rule : _ → id_ Semantic rule : .actual_typelookup (.string)
  • How are attribute values computed?
  • If all attributes were inherited, the tree could be decorated in top-down order.
  • If all attributes were synthesized, the tree could be decorated in bottom-up order.
  • In many cases, both kinds of attributes are used, and it is some combination of top-down and bottom-up that must be used. .expected_typeinherited from parent [1].actual_typelookup (A) [2].actual_typelookup (B) [1].actual_type =? [2].actual_type .actual_type[1].actual_type .actual_type =? .expected_type

Describing the Meanings of Programs: Dynamic Semantics

  • There is no single widely acceptable notation or formalism for describing semantics
  • Operational Semantics
    • Describe the meaning of a program by executing its statements on a machine, either simulated or actual. The change in the state of the machine (memory, registers, etc.) defines the meaning of the statement
  • To use operational semantics for a high-level language, a virtual machine is needed
  • A hardware pure interpreter would be too expensive
  • A software pure interpreter also has problems:
    • The detailed characteristics of the particular computer would make actions difficult to understand
    • Such a semantic definition would be machine- dependent

Operational Semantics

  • A better alternative: A complete computer simulation
  • The process:
    • Build a translator (translates source code to the machine code of an idealized computer)
    • Build a simulator for the idealized computer
  • Evaluation of operational semantics:
    • Good if used informally (language manuals, etc.)
    • Extremely complex if used formally ( e.g. , VDL), it was used for describing semantics of PL/I.
  • Axiomatic Semantics
    • Based on formal logic (predicate calculus)
    • Original purpose: formal program verification
    • Approach: Define axioms or inference rules for each statement type in the language (to allow transformations of expressions to other expressions)
    • The expressions are called assertions Axiomatic Semantics
  • An assertion before a statement (a precondition) states the relationships and constraints among variables that are true at that point in execution
  • An assertion following a statement is a postcondition
  • A weakest precondition is the least restrictive precondition that will guarantee the postcondition
  • Pre-post form: {P} statement {Q}
  • An example: a = b + 1 {a > 1}
  • One possible precondition: {b > 10}
  • Weakest precondition: {b > 0}
  • Program proof process: The postcondition for the whole program is the desired result. Work back through the program to the first statement. If the precondition on the first statement is the same as the program spec, the program is correct.
  • An axiom for assignment statements (x = E): {Qx->E} x = E {Q}
  • An inference rule for sequences
  • For a sequence S1;S2:
  • {P1} S1 {P2}
  • {P2} S2 {P3}
  • An inference rule for logical pretest loops For the loop construct: {P} while B do S end {Q} Characteristics of the loop invariant I must meet the following conditions:
  • P => I (the loop invariant must be true initially)
  • {I} B {I} (evaluation of the Boolean must not change the validity of I)
  • {I and B} S {I} (I is not changed by executing the body of the loop)
  • (I and (not B)) => Q (if I is true and B is false, Q is implied)
  • The loop terminates (this can be difficult to prove)
  • The loop invariant I is a weakened version of the loop postcondition, and it is also a precondition.
  • The meaning of the loop is the value of the program variables after the statements in the loop have been executed the prescribed number of times, assuming there have been no errors
  • In essence, the loop has been converted from iteration to recursion, where the recursive control is mathematically defined by other recursive state mapping functions
  • Recursion, when compared to iteration, is easier to describe with mathematical rigor
  • Evaluation of denotational semantics
    • Can be used to prove the correctness of programs
    • Provides a rigorous way to think about programs
    • Can be an aid to language design
    • Has been used in compiler generation systems
    • Because of its complexity, they are of little use to language users Summary
  • BNF and context-free grammars are equivalent meta-languages
  • Well-suited for describing the syntax of programming languages
  • An attribute grammar is a descriptive formalism that can describe both the syntax and the semantics of a language
  • Three primary methods of semantics description
  • Operation, axiomatic, denotational

UNIT- 2

Data Types and Variables

Introduction

  • A data type defines a collection of data objects and a set of predefined operations on those objects
  • A descriptor is the collection of the attributes of a variable
  • An object represents an instance of a user-defined (abstract data) type
  • One design issue for all data types: What operations are defined and how are they specified?

2.1 Primitive Data Types – CO

  • Almost all programming languages provide a set of primitive data types
  • Primitive data types: Those not defined in terms of other data types
  • Some primitive data types are merely reflections of the hardware
  • Others require only a little non-hardware support for their implementation Integer
  • Almost always an exact reflection of the hardware so the mapping is trivial
  • There may be as many as eight different integer types in a language
  • Java‘s signed integer sizes: byte, short, int, long Floating Point
  • Model real numbers, but only as approximations
  • Languages for scientific use support at least two floating-point types ( e.g. , float and double; sometimes more
  • Usually exactly like the hardware, but not always
  • IEEE Floating-Point Standard 754 Complex
  • Some languages support a complex type, e.g. , Fortran and Python
  • Each value consists of two floats, the real part and the imaginary part
  • Literal form (in Python): (7 + 3j), where 7 is the real part and 3 is the imaginary part Decimal
  • For business applications (money)
  • Essential to COBOL
  • C# offers a decimal data type
  • Store a fixed number of decimal digits, in coded form (BCD)
  • Advantage : accuracy
  • Disadvantages : limited range, wastes memory Boolean
  • Simplest of all
  • Range of values: two elements, one for “true” and one for “false”
  • Could be implemented as bits, but often as bytes
  • Advantage: readability Character
  • Stored as numeric coding
  • Most commonly used coding: ASCII
  • An alternative, 16 - bit coding: Unicode

2.2 User-Defined Ordinal Types - CO

  • An ordinal type is one in which the range of possible values can be easily associated with the set of positive integers
  • Examples of primitive ordinal types in Java
    • integer
    • char
    • boolean Enumeration Types
  • All possible values, which are named constants, are provided in the definition
  • C# example enum days {mon, tue, wed, thu, fri, sat, sun};
  • Design issues
  • Is an enumeration constant allowed to appear in more than one type definition, and if so, how is the type of an occurrence of that constant checked?
  • Are enumeration values coerced to integer?
  • Any other type coerced to an enumeration type? Evaluation of Enumerated Type
  • Aid to readability, e.g. , no need to code a color as a number
  • Aid to reliability, e.g. , compiler can check:
  • Operations (don‘t allow colors to be added)
  • No enumeration variable can be assigned a value outside its defined range
  • Ada, C#, and Java 5.0 provide better support for enumeration than C++ because enumeration type variables in these languages are not coerced into integer types Subrange Types
  • An ordered contiguous subsequence of an ordinal type
  • Example: 12..18 is a subrange of integer type
  • Ada‘s design type Days is (mon, tue, wed, thu, fri, sat, sun); subtype Weekdays is Days range mon..fri; subtype Index is Integer range 1..100; Day1: Days; Day2: Weekday; Day2 := Day1; Subrange Evaluation
  • Aid to readability
  • Make it clear to the readers that variables of subrange can store only certain range of values
  • Reliability
  • Assigning a value to a subrange variable that is outside the specified range is detected as an error Implementation
  • Enumeration types are implemented as integers
  • Subrange types are implemented like the parent types with code inserted (by the compiler) to restrict assignments to subrange variables

Array Types

  • An array is an aggregate of homogeneous data elements in which an individual element is identified by its position in the aggregate, relative to the first element. Array Design Issues
  • What types are legal for subscripts?
  • Are subscripting expressions in element references range checked?
  • When are subscript ranges bound?
  • When does allocation take place?
  • What is the maximum number of subscripts?
  • Can array objects be initialized?
  • Are any kind of slices supported? Array Indexing
  • Indexing (or subscripting) is a mapping from indices to elements array_name (index_value_list)an element
  • Index Syntax
  • FORTRAN, PL/I, Ada use parentheses
  • Ada explicitly uses parentheses to show uniformity between array references and function calls because both are mappings
  • Most other languages use brackets Arrays Index (Subscript) Types
  • FORTRAN, C: integer only
  • Ada: integer or enumeration (includes Boolean and char)
  • Java: integer types only
  • Index range checking
  • C, C++, Perl, and Fortran do not specify range checking
  • Java, ML, C# specify range checking
  • In Ada, the default is to require range checking, but it can be turned off Subscript Binding and Array Categories
  • Static : subscript ranges are statically bound and storage allocation is static (before run-time)
  • Advantage: efficiency (no dynamic allocation)
  • Fixed stack-dynamic : subscript ranges are statically bound, but the allocation is done at declaration time
  • Advantage: space efficiency
  • Stack-dynamic : subscript ranges are dynamically bound and the storage allocation is dynamic (done at run-time)
  • Advantage: flexibility (the size of an array need not be known until the array is to be used)
  • Fixed heap-dynamic : similar to fixed stack-dynamic: storage binding is dynamic but fixed after allocation (i.e., binding is done when requested and storage is allocated from heap, not stack)
  • Heap-dynamic: binding of subscript ranges and storage allocation is dynamic and can change any number of times
  • Advantage: flexibility (arrays can grow or shrink during program execution)
  • C and C++ arrays that include static modifier are static
  • C and C++ arrays without static modifier are fixed stack-dynamic
  • C and C++ provide fixed heap-dynamic arrays
  • C# includes a second array class ArrayList that provides fixed heap-dynamic
  • Perl, JavaScript, Python, and Ruby support heap-dynamic arrays