CCS358/PRINCIPLES OF PROGRAMMING LANGUAGES - STUDY NOTES

CCS358/PRINCIPLES OF PROGRAMMING LANGUAGES

UNIT I SYNTAX AND SEMANTICS

Evolution of Programming Languages
  • Describing Syntax

    • Context-Free Grammars (CFGs)

    • Attribute Grammars

  • Describing Semantics

  • Lexical Analysis

  • Parsing

    • Recursive-Descent Parsing

    • Bottom-Up Parsing

1.1 Reasons for Studying Concepts of Programming Languages
  • Increased Ability to Express Ideas

    • The depth of thought is influenced by the expressive power of the language.

    • Difficulties in conceptualizing structures that cannot be described verbally or in writing.

    • Software development is limited by the language used to develop it (control structures, data structures).

    • Awareness of diverse programming language features can lower limitations in software development.

  • Improved Background for Choosing Appropriate Languages

    • Programmers often choose familiar languages even if they are poorly suited for new projects.

    • Familiarity with multiple languages enhances informed language choices.

  • Greater Ability to Learn New Languages

    • Continuous evolution of programming languages necessitates ongoing learning.

    • Understanding core programming concepts eases learning of new languages (like Java).

  • Understanding the Significance of Implementation

    • Understanding implementation issues helps comprehend language design rationales, leading to more effective usage.

  • Ability to Design New Languages

    • Expertise in multiple languages enhances understanding of programming concepts.

  • Overall Advancement of Computing

    • Language adoption can hinge on familiarity rather than suitability (e.g. ALGOL 60 vs. Fortran).

1.2 Programming Domains
  • Scientific Applications

    • Early 1940s, first applications required numerous floating-point calculations.

    • Fortran: First language developed specifically for scientific applications.

    • ALGOL 60 aimed for the same purposes.

  • Business Applications

    • COBOL: The first successful language for business applications emphasizing report generation, decimal arithmetic, and character manipulation.

    • The advent of PCs transformed business computing, leading to spreadsheets and databases.

  • Artificial Intelligence (AI)

    • Focuses on symbolic rather than numeric computation.

    • LISP emerged as the first widely used AI programming language.

  • Systems Programming

    • Involves system software that supports OS and development tools.

    • Efficiency is critical due to continual use.

  • Scripting Languages

    • Command scripts executed in files (e.g., PHP, which is embedded in HTML documents).

  • Special-Purpose Languages

1.3 Language Evaluation Criteria
  • Readability: Ease of reading and understanding programs.

  • Writability: Simplicity in writing and creating programs.

  • Reliability: Conformance to specifications and overall performance consistency.

  • Cost: Ultimate total cost of software development.

Additional Factors:

  • Overall Simplicity: A manageable feature set with minimal multiplicity.

  • Orthogonality: A small set of primitive constructs combined in a limited number of lawful ways.

  • Control Statements: Presence of familiar control structures (e.g. while statements).

  • Data Types and Structures: Adequate provisions for defining data structures.

  • Syntax Considerations:

    • Identifiers: Flexibility in names.

    • Self-descriptiveness: Meaningful keywords and constructs.

    • Simplicity and Orthogonality: Few constructs with limited rules.

1.4 Influences on Language Design
  • Computer Architecture:

    • Programming languages evolve around common architectures—most commonly, the von Neumann architecture.

    • Characteristics of imperative languages stem from the separation of memory for data and instructions.

  • Programming Methodologies: New methodologies have led to the emergence of new languages. Understanding historical paradigms helps inform design and choice.

1.5 Language Categories
  • Imperative: Features variables, assignment statements, and iterations.

    • Examples: C, Pascal.

  • Functional: Computation achieved by applying functions.

    • Examples: LISP, Scheme.

  • Logic: Based on rules.

    • Example: Prolog.

  • Object-oriented: Focuses on data abstraction and inheritance.

    • Examples: Java, C++.

  • Markup Languages: Specify document layout, not programming per se.

    • Examples: XHTML, XML.

Language Design Trade-Offs
  • Reliability vs. Cost of Execution: Ensuring all array references are checked increases reliability but can raise execution costs.

  • Readability vs. Writability: Powerful operators can compromise readability; for example, APL's extensive symbols lead to compact, yet hard to read programs.

  • Writability vs. Reliability: Flexible constructs like C++ pointers can be misused, affecting reliability.

1.6 Evolution of Programming Languages

1. Plankalkul

  • First language developed in 1945 by Zuse; it featured advanced data structures but was never implemented.

2. Pseudocode

  • Invented in 1949 to overcome the limitations of machine codes, enhancing readability and modifiability.

3. FORTRAN

  • Developed for scientific applications, becoming widely utilized due to its design addressing specific computational challenges.

4. LISP

  • Described as a symbolic computation language designed for AI, emphasizing list processing.

5. ALGOL 60

  • Established many foundational programming concepts but faced challenges leading to limited adoption.

6. COBOL

  • Focused on business applications, emphasizing readability to broaden usability for non-programmers.

1.7 Key Concepts in Programming Languages
  • Names: Identifiers for program elements, influenced by character length, connector usage, case sensitivity, and reserved words.

Lexical Analysis
  • Definition: A front-end system (lexer) matching character patterns, producing tokens from lexemes.

  • Functionality: Skips irrelevant whitespace and comments, recognizes lexemes, assigns token types, and integrates with syntax analysis.

Building a Lexical Analyzer
  • Approaches include utilizing regular expressions for pattern descriptions, designing state transition diagrams, or table-driven implementations.

Parsing and Syntax Analysis
  • Parsing is implemented via top-down or bottom-up approaches, focusing on constructing parse trees based on input syntax. Different parsing follow specific grammar rules to categorize and build these structures.

Recursive-Descent Parsing
  • A method reflecting programming languages' recursive structures, typically aligning with EBNF grammar specifications, generating code relevant to the structured programming practices.

1.8 Describing Meanings and Semantics
  • Emphasis on operational, axiomatic, and denotational semantics, each presenting various approaches to mapping program constructs to meaning and behavior, important for verification and language design.