0% found this document useful (0 votes)
4 views

Programming Langauages

The document outlines the objectives and content of a programming languages module, emphasizing key concepts such as language design, compilation processes, and type systems. It covers various units including control flow, data types, procedural abstraction, object-oriented programming, and other paradigms like functional and logic programming. Additionally, it addresses concurrency issues and provides foundational knowledge necessary for understanding and implementing programming languages.

Uploaded by

findyandx
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views

Programming Langauages

The document outlines the objectives and content of a programming languages module, emphasizing key concepts such as language design, compilation processes, and type systems. It covers various units including control flow, data types, procedural abstraction, object-oriented programming, and other paradigms like functional and logic programming. Additionally, it addresses concurrency issues and provides foundational knowledge necessary for understanding and implementing programming languages.

Uploaded by

findyandx
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 7

Programming Languages

By end of the Module students must be able to:

1. explain the basic concepts of language design


2. understand and write about language-design issues and the relative merits of various
approaches to them
3. have a basis for choosing an appropriate language for an application
4. apply concepts of language design to learning a new language
5. Be exposed to diverse programming languages and paradigms
6. understand the design choices in current programming languages
7. Distinguish between the “essence” and the “arbitrary concepts” of programming
languages.

Unit 1
General overview and history
Compilation and interpretation
https://stackoverflow.com/questions/3265357/compiled-vs-interpreted-languages

The process of translating the entire source code of a program into machine code (binary
executable) before execution.

Overview of compilation Scanners and parsers

https://courses.cs.washington.edu/courses/cse390b/22wi/readings/
compiler_scanner_parser.html

A scanner is a program that takes a sequence of characters (the source file of the program)
and produces a sequence of tokens that will be used to feed the compiler's parser.
A Scanner simply turns an input String (say a file) into a list of tokens. These tokens
represent things like identifiers, parentheses, operators etc.

A parser converts this list of tokens into a Tree-like object to represent how the tokens fit
together to form a cohesive whole (sometimes referred to as a sentence).

In terms of programming language parsers, the output is usually referred to as an


Abstract Syntax Tree (AST). Each node in the AST represents a different construct of
the language, e.g. an IF statement would be a node with 2 or 3 sub nodes, a
CONDITION node, a THEN node and potentially an ELSE node.

A parser does not give the nodes any meaning beyond structural cohesion. The next
thing to do is extract meaning from this structure (sometimes called contextual analysis).

Parsing (in a general sense) is about turning the symbols (characters, digits, left parens,
etc) into sentences of your grammar.

The lexical analyzer (the "lexer") parses individual symbols from the source code file into
tokens. From there, the "parser" proper turns those whole tokens into sentences of your
grammar.

Put another way, the lexer combines symbols into tokens, and the parser combines
tokens to form sentences.

Compilation involves several stages, each handling different aspects of translating the
source code into a form that can be executed by the machine. The main stages are:

1. Lexical Analysis (Scanning): The source code is converted into tokens, which
are the smallest units of meaningful text.
2. Syntax Analysis (Parsing): The sequence of tokens is analyzed against the
grammar of the language to form a parse tree, which represents the syntactic
structure of the program.
3. Semantic Analysis: Checks for semantic errors (like type mismatches) and
performs variable declarations and type-checking.
4. Optimization: The intermediate code is optimized for performance.
5. Code Generation: The optimized intermediate representation is translated into
machine code.
6. Code Linking: The compiled code is linked with other libraries or modules to
produce an executable.

Unit 2: Names, Scopes, and Bindings


Binding
Lifetime Static scope
Encapsulation and modules
Dynamic scope
https://www.cs.iusb.edu/~danav/teach/c311/c311_3_scope.html
- Programming languages often require specifying the data type for each data object (e.g.,
variables, function parameters).
- Common data types include:
- Integer: Whole numbers without a fractional part (e.g., 3, -5).
- Floating-Point: Numbers with a decimal point (e.g., 3.14, -0.001).
- Character (Text): Represents readable text, typically implemented using character
encodings like ASCII or Unicode.

Purpose of Types in Programming Languages**


- Types provide context for operations without explicitly specifying it each time.
- Example: In C, `a + b` uses integer addition if `a` and `b` are integers, and floating-point
addition if they are `double`.
- They help enforce correct usage of variables, enabling compilers to catch errors early.
#### **3. Type Systems**
- **Type System:** A mechanism defining types and rules for type equivalence, compatibility,
and inference.
- **Type Equivalence:** Determines when two values have the same type.
- **Type Compatibility:** Determines when a value can be used in a specific context.
- **Type Inference:** Allows a language to infer types based on usage.

#### **4. Type Checking**


- Ensures a program follows type compatibility rules.
- **Type Clash:** A violation of these rules.
- **Strongly Typed Languages:** Enforce type rules strictly (e.g., Ada).
- **Statically Typed Languages:** Perform type checking at compile time.
- Example: Ada performs static type checking, whereas Pascal does most type checking at
compile time but has some loopholes.

#### **5. Understanding "Type"**


- **Denotational Perspective:** A type is a set of values (e.g., integers, characters).
- **Constructive Perspective:** Types are built from primitive types (e.g., integer, character)
or constructed using type constructors (e.g., arrays, records).
- **Abstraction-Based Perspective:** Types are defined by a set of operations and semantics
(e.g., abstract data types).

#### **6. Classification of Types**


- **Numeric Types:** Include integers, floating-point, and complex numbers. Differences in
precision across systems can affect portability.
- **Discrete Types:** Integers, Booleans, and characters.
- **Scalar Types:** Include discrete, rational, real, and complex types.
- **Enumeration Types:** Consist of named elements (e.g., days of the week in Pascal).
Useful for readability and error-checking.
- **Subrange Types:** Define a range within a base type (e.g., `0..100` for test scores).
- **Composite Types:** Constructed from simpler types (e.g., arrays, records, sets).

#### **7. Composite Types and Operations**


- **Records (Structures):** Group fields of different types together (e.g., in C).
- **Variant Records:** Allow different fields to be active at different times.
- **Arrays:** Homogeneous collections of elements, typically accessed via an index.
- **Sets:** Unordered collections of unique values, often implemented using bit vectors.
- **Pointers:** References to memory locations, commonly used for dynamic data structures.

#### **8. Type Conversions and Casting**


- Type conversions allow values of one type to be used in contexts expecting another.
- **Explicit Conversion (Cast):** When a programmer specifies the conversion.
- **Implicit Conversion (Coercion):** When the language automatically converts types.
- **Non-Converting Type Casts:** In low-level programming, a cast changes the
interpretation of bits without altering them (e.g., using `void*` in C).

#### **9. Type Compatibility and Coercion**


- Compatibility rules determine whether two types can interact in a given context.
- **Overloading:** Multiple functions with the same name can have different behaviors
depending on argument types.
- **Universal Reference Types:** Allow generic programming by using a type like `void*` in C
or `Object` in Java to reference any type.

#### **10. Reference and Value Models**


- **Reference Types:** Use pointers or references to access data. Common in languages
like Java.
- **Value Types:** Directly represent the data (e.g., primitive types in C).
- **Garbage Collection:** Automatic memory management that reclaims unused objects,
avoiding memory leaks.

#### **11. Lists, Strings, and Files**


- **Lists:** Can be homogeneous (e.g., ML) or heterogeneous (e.g., Lisp), often
implemented as linked structures.
- **Strings:** Typically represented as arrays of characters, but may have special language
support for operations.
- **Files:** Used for persistent data storage, with operations for reading, writing, and
managing file data.

These notes provide a foundational understanding of various data type concepts, crucial for
designing and implementing programs across different programming languages.

Unit 3 :Control Flow


Expressions and Assignment Structure
Sequencing
Selection
Iteration
Recursion

Unit 4 :Data Types


Type systems
Type checking
Records
Arrays
Strings
Pointers and recursive types
Files

Unit 5: Procedural Abstraction


Stacks and calling sequences
Parameters
Generics
Exceptions
Unit 6 : Data Abstraction and Object Orientation
Object-oriented programming
Encapsulation and inheritance
Initialization and finalisation
Dynamic binding
Multiple inheritance

Unit 7: Other Paradigms


Scripting Languages
Functional programming
Logic programming

Unit 8: Concurrency
Terminology Issues
Thread creation
Synchronisation

You might also like