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

Survey of Programming Languages

Organization of programming languages

Uploaded by

marynaty667
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

Survey of Programming Languages

Organization of programming languages

Uploaded by

marynaty667
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 14

Lesson 1

Lesson Note: Introduction to Programming Languages

What is a Programming Language?


A programming language is a formal language comprising a set of instructions used to
produce various kinds of output, such as software applications, websites, and systems.
It allows humans to communicate with computers.
Purpose of Programming Languages
• To instruct computers to perform specific tasks.
• To solve problems efficiently through algorithms and logic.
• To build software that interacts with users, devices, and networks.
Categories of Programming Languages
Low-Level Languages
o Machine Language (Binary code: 0s and 1s)
o Assembly Language (human-readable mnemonics)
High-Level Languages
o Easy to read and write (e.g., Python, Java, C++)
Very High-Level Languages
o Closer to natural language (e.g., SQL, MATLAB)
Types of Programming Languages by Paradigm
• Imperative Languages: Describe how a program operates (e.g., C, Python).
• Declarative Languages: Describe what the program should accomplish (e.g., SQL, Prolog).
• Object-Oriented Languages: Use objects and classes (e.g., Java, C++, Python).
• Functional Languages: Use mathematical functions (e.g., Haskell, Lisp).
• Procedural Languages: Use procedures or routines (e.g., Pascal, C).
• Scripting Languages: Used for automating tasks (e.g., JavaScript, Bash).
Compiled vs. Interpreted Languages
• Compiled: Translates the entire code to machine language before execution (e.g., C, C++,
java).
• Interpreted: Translates code line-by-line during execution (e.g., Python, JavaScript).
Features of a Good Programming Language
• Readability
• Simplicity
• Efficiency
• Portability
• Robust error handling
• Maintainability
Evolution of Programming Languages
• 1st Gen: Machine Language
• 2nd Gen: Assembly Language
• 3rd Gen: High-level Languages (C, FORTRAN)
• 4th Gen: Very High-Level Languages (SQL)
• 5th Gen: AI-oriented Languages (Prolog)
Examples of Common Programming Languages
• Python: Easy to learn, widely used in web development, data science.
• Java: Used for enterprise applications, Android development.
• C: Powerful system programming language.
• C++: Extension of C with object-oriented features.
• JavaScript: Used for web interactivity.
• Ruby: Known for its elegant syntax.
Applications Areas of Programming Languages
• Web Development (HTML, CSS, JavaScript)
• Mobile App Development (Kotlin, Swift)
• Data Science and AI (Python, R)
• Game Development (C++, C#)
• System Programming (C, Rust)
In Conclusion
Programming languages are essential tools in computing. Understanding their types, characteristics,
and applications is key to becoming an effective developer.

Lesson 2
Lesson Note: Programming Paradigms
What Are Programming Paradigms?
A programming paradigm is a style or way of programming that provides a structure for writing
and organizing code. Different paradigms support different approaches to solving problems and
structuring programs.

Importance of Programming Paradigms


• Helps programmers choose the right tools and techniques for solving specific problems.
• Influences program structure, readability, and maintainability.
• Encourages best practices and efficient software design.

Major Types of Programming Paradigms

a. Imperative Paradigm
• Focus: How to achieve a result.
• Programs are written as a sequence of commands for the computer to perform.
• Key Concepts: Statements, variables, loops, and conditionals.
• Examples: C, Python, Java (partly).

b. Declarative Paradigm
• Focus: What result is desired, not how to achieve it.
• Tells the computer what the program should accomplish.
• Key Concepts: Facts and rules (logic programming), queries.
• Examples: SQL, Prolog, HTML (declarative structure).

c. Procedural Paradigm
• Subset of imperative programming.
• Organizes code into reusable procedures or functions.
• Key Concepts: Function calls, modularity, scope.
• Examples: C, Pascal.

d. Object-Oriented Paradigm (OOP)


• Organizes software around objects, which contain data and methods.
• Promotes reusability, modularity, and encapsulation.
• Key Concepts: Classes, objects, inheritance, polymorphism.
• Examples: Java, C++, Python, Ruby.

e. Functional Paradigm
• Based on mathematical functions and immutability.
• Avoids side effects; supports higher-order functions.
• Key Concepts: Pure functions, recursion, first-class functions.
• Examples: Haskell, Lisp, Scala, Elixir.

f. Scripting Paradigm
• Used for automating repetitive tasks or enhancing web applications.
• Typically interpreted and lightweight.
• Key Concepts: Script files, shell commands, rapid development.
• Examples: JavaScript, Bash, Python, Perl.

Comparison of Paradigms

Paradigm Focus Common Use Cases Examples

Imperative How to do it System programming, general use C, Python

Declarative What to do Databases, AI, HTML layout SQL, Prolog

Procedural Function-based Step-by-step programs C, Pascal

OOP Objects & data Large software, UI apps Java, C++, Python

Functional Pure functions Data processing, academic use Haskell, Lisp

Scripting Automation Web dev, system scripts JavaScript, Bash

Lesson 3
Syntax and Semantics of Programming Languages

Introduction
In the study of programming languages, two fundamental concepts are syntax and semantics:
• Syntax: The structure or form of expressions, statements, and program units.
• Semantics: The meaning of those expressions, statements, and program units.

Syntax of Programming Languages

Syntax refers to the rules that define the correct combinations of symbols in a programming language.
Types of Syntax
1. Concrete Syntax
o How programs are written by humans.
o Includes symbols, keywords, operators, punctuation (e.g., {}, ;, if, while).
2. Abstract Syntax
o A simplified, structural version that removes unnecessary symbols and focuses on the
program's logical structure (e.g., abstract syntax trees).
Grammar
• Programming languages are usually defined by formal grammar (e.g., Backus-Naur Form -
BNF or Extended BNF).
• Grammar rules define how valid statements and expressions are formed.
Syntax Errors
• Occur when code does not follow the defined syntax.
• Detected at compile-time or during interpretation.
Semantics of Programming Languages
Definition
Semantics defines the meaning behind syntactically correct statements.
Types of Semantics
Static Semantics
o Concerns rules that can be checked without executing the program (e.g., type
checking, scope rules).
o Violations usually result in compile-time errors.
Dynamic Semantics
o Describes what the program does when executed (runtime behavior).
o Includes evaluation of expressions, control flow, and memory manipulation.
Approaches to Defining Semantics
Operational Semantics
o Describes how a program executes step-by-step on an abstract machine.
o Used in interpreters.
Denotational Semantics
o Maps language constructs to mathematical objects.
o Used for formal reasoning and proving correctness.
Axiomatic Semantics
o Uses logical assertions to reason about program behavior.
o Foundation for program verification (e.g., Hoare Logic).

Syntax vs. Semantics

Feature Syntax Semantics

Definition Structure or form of code Meaning or behavior of code

Concerned With Grammar, symbols, format Logic, evaluation, effect

Checked During Compilation or parsing Execution or formal analysis

Error Type Syntax errors Semantic errors

Example Missing semicolon (;) Dividing by zero or type mismatch

Importance of Syntax and Semantics


• Syntax ensures code can be parsed and understood by the compiler/interpreter.
• Semantics ensures that the code performs the intended tasks correctly.
• Together, they define the correctness and functionality of a program.

Examples
Example 1: Syntax Error (python)
print("Hello World" # Missing closing parenthesis
Example 2: Semantic Error (python)
x = 10 / 0 # Division by zero

Tools for Working with Syntax and Semantics


• Lexers and Parsers: Used for analyzing syntax (e.g., ANTLR, Flex/Yacc)
• Type Checkers and Static Analyzers: Used for static semantic checks
• Formal Verification Tools: Used to prove semantic correctness

Data Types and Data Structure


In programming, data types and data structures are fundamental concepts that determine how data is
stored, manipulated, and organized.
• Data Type: A classification that specifies which type of value a variable can hold.
• Data Structure: A specialized format for organizing and storing data.

Data Types
Primitive Data Types
These are the most basic data types provided by a programming language:

Data Type Description Example

Integer Whole numbers int x = 10

Float Decimal numbers float y = 3.14

Char Single character char c = 'A'

Boolean True or False bool flag = true

Non-Primitive Data Types


These include more complex data types:
• Strings: Sequence of characters ("Hello")
• Arrays: Collection of elements of the same type
• Objects: Instances of classes in object-oriented programming

Type Systems
• Static Typing: Types are declared at compile time (e.g., Java, C++)
• Dynamic Typing: Types are determined at runtime (e.g., Python, JavaScript)
• Strong Typing: Prevents implicit type conversion
• Weak Typing: Allows more flexibility in type conversion

Data Structures
Data structures are used to organize and manage data efficiently for various operations such as
searching, sorting, insertion, and deletion.
Linear Data Structures
Array
o Fixed-size collection of elements.
o Example: int arr[5] = {1, 2, 3, 4, 5};
Linked List
o Each element (node) contains data and a reference to the next node.
o Types: Singly, Doubly, Circular
Stack
o Follows Last-In-First-Out (LIFO) principle.
o Operations: push(), pop()
Queue
o Follows First-In-First-Out (FIFO) principle.
o Types: Simple, Circular, Priority Queue
Non-Linear Data Structures
Tree
o Hierarchical structure with nodes and edges.
o Special types: Binary Tree, Binary Search Tree (BST)
Graph
o Set of nodes (vertices) connected by edges.
o Types: Directed, Undirected, Weighted
Hash Table
• Stores data in key-value pairs.
• Allows fast access, insertion, and deletion.
• Used in dictionaries/maps.

Abstract Data Types (ADTs)


ADTs are theoretical models of data structures that define behavior but not implementation.
Common ADTs include:
• List
• Stack
• Queue
• Map
• Set
Importance of Data Types and Structures
• Ensure correct and efficient use of memory
• Improve performance of programs
• Provide modularity and code reusability
• Help solve complex computational problems

Choosing the Right Data Structure


When choosing a data structure, consider:
• The type of data being stored
• The operations to be performed (e.g., search, insert)
• Time and space complexity
• Flexibility and scalability

Variables, Scope, and Lifetime in Programming


Understanding variables, their scope, and lifetime is fundamental to writing efficient and bug-free
programs. These concepts determine where a variable can be accessed, how long it exists in memory,
and how it behaves in different parts of a program.

Variables
• A variable is a symbolic name that refers to a memory location where data is stored.
• It allows the programmer to store, retrieve, and manipulate data during program execution.
Example (Python):
python
x = 10
name = "Alice"
Scope
• Scope defines the visibility or accessibility of a variable within different parts of a program.
• There are typically three main types of scope:
a. Local Scope
• Variables declared within a function or block.
• Only accessible within that function or block.
python
def greet():
message = "Hello"
print(message) # 'message' is local to greet()
b. Global Scope
• Declared outside all functions.
• Accessible from anywhere in the program (unless shadowed).
python
name = "Alice"

def greet():
print(name) # Can access global variable 'name'
c. Nonlocal (Enclosed) Scope
• Applies to nested functions.
• Variables declared in the outer function are accessible to the inner function.
python
def outer():
count = 5
def inner():
print(count) # Accesses 'count' from the enclosing scope
inner()

Lifetime
• Lifetime refers to the duration a variable exists in memory during program execution.
a. Local Variable Lifetime
• Exists only during the execution of the function/block.
• Memory is released once the function exits.
b. Global Variable Lifetime
• Exists throughout the program's execution.
• Created when the program starts and destroyed when it ends.

In summary

Concept Definition Example

Variable Named storage for data x=5

Scope Region where a variable is accessible Local, Global, Nonlocal

Lifetime Duration a variable exists in memory Temporary (local) or full program (global)

Importance in Programming
• Prevents naming conflicts and unintended side effects.
• Helps in memory management.
• Encourages modular and bug-free code.

Control Structures in Programming


Control structures are fundamental components in programming languages that dictate the flow of
execution within a program. They allow developers to make decisions, repeat actions, and control
how and when parts of the code are executed.

What Are Control Structures?


Control structures are programming constructs that manage the order in which statements are
executed. They are essential for implementing logic and behavior in programs.

Types of Control Structures


a. Sequential Structure
• Default flow where statements are executed one after another from top to bottom.
• No decision-making or repetition.
python
x = 10
y = 20
z=x+y
print(z)

b. Selection (Decision-Making) Structure


Used to make choices between different paths in a program.
i. if statement
Executes a block only if a condition is true.
python
if x > 10:
print("x is greater than 10")
ii. if-else statement
Adds an alternative block if the condition is false.
python
if x > 10:
print("x is greater")
else:
print("x is smaller or equal")
iii. if-elif-else statement
Checks multiple conditions.
python
if x > 10:
print("x is greater")
elif x == 10:
print("x is equal to 10")
else:
print("x is smaller")
iv. switch/case statement (In some languages like C, Java, JavaScript)
Useful for checking multiple discrete values.
c
switch (x) {
case 1: printf("One"); break;
case 2: printf("Two"); break;
default: printf("Other");
}

c. Repetition (Looping) Structure


Used to repeat actions until a condition is met.
i. while loop
Executes while the condition is true.
python
i=0
while i < 5:
print(i)
i += 1
ii. for loop
Executes a block for a fixed number of iterations.
python
for i in range(5):
print(i)
iii. do-while loop (In some languages like C, Java)
Executes the loop body at least once.
c
int i = 0;
do {
printf("%d", i);
i++;
} while (i < 5);

d. Jump/Branching Statements
Used to alter the normal flow of control.
• break: Exits the current loop.
• continue: Skips the rest of the current iteration and starts the next.
• return: Exits from a function and optionally returns a value.
python
for i in range(10):
if i == 5:
break
print(i)

Importance of Control Structures


• Allow decision-making, repetition, and modular code.
• Enable programmers to implement logic and flow control.
• Help create interactive and dynamic applications.

You might also like