0% found this document useful (0 votes)
4 views21 pages

Lecture # 01-02

The document outlines the syllabus for a Theory of Programming Languages course, covering topics such as models of computation, syntax and semantics, and programming paradigms. It emphasizes the need for structured communication with machines through formal languages and provides definitions for symbols, alphabets, strings, and languages. Additionally, it discusses basic operations on strings, including length, concatenation, and substrings.

Uploaded by

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

Lecture # 01-02

The document outlines the syllabus for a Theory of Programming Languages course, covering topics such as models of computation, syntax and semantics, and programming paradigms. It emphasizes the need for structured communication with machines through formal languages and provides definitions for symbols, alphabets, strings, and languages. Additionally, it discusses basic operations on strings, including length, concatenation, and substrings.

Uploaded by

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

Theory of Programming Languages

(CSC-161)
Mr. Faizan Ali (Teaching Assistant)

Department of Computer Systems Engineering,


BS in (Computer Science)
Mehran University of Engineering and Technology, Jamshoro.
Syllabus:

• Introduction: Models of Computation, Syntax and Semantics, Pragmatics, Language Design


Principles. Syntax and Semantics: Context-Free Grammars, Regular Expressions, Attribute
Grammars and Static Semantics, Algebraic Semantics, Axiomatic Semantics, Denotational
Semantics.
• BNF grammars and Syntax, Operational Equivalence, Abstraction and Generalization, Expressions,
Assignment Statement, and Control Structures, Functional Programming:
• The Lambda Calculus, Operational Semantics, Reduction Order, Recursive Functions, Logic
Programming, Inference Engine, Concurrency.
RECOMMENDED BOOKS:

• Concepts of Programming Languages, Robert W. Sebesta, latest edition.


• Scott, Michael L., Programming Language Pragmatics, latest edition.
• Theory Introduction to Programming Languages, by Anthony A. Aaby, latest adition.
• Principles of Programming Languages by Mike Grant Zachary Palmer Scott Smith, John Hopkins
University, latest edition.
Lecture # 01-02
(Introduction of TPL and Requirement of TPL)
Introduction to Theory of Programming Languages

• As the name suggests, TPL focuses on the study of mathematical models and computational
machine or systems, commonly referred to as automata.
• It explores computational problems, analyzing which problems can be solved using these systems
and determining the extent of their solvability on a computer.
• The Theory of Programming Languages encompasses the study of various computational models
in computer science, evaluating both problem-solving capabilities and efficiency in execution.

• Problem Statement
• In today's world, digital, analog, and mechanical machines play a crucial role in human
development.
• To interact with these machines effectively, a structured communication mechanism is
required, which is achieved through programming languages and computational models.
Solution

• A language is required to effectively communicate with machines.


• Natural languages are highly complex and not suitable for direct machine interaction, as
machines require simpler, more structured languages.
• Languages are categorized into two types:
• Formal Languages (used for computation and programming)
• Informal Languages (used for human communication)
• We will focus on formal languages.
• Informally, a language can be defined as a system of symbols used to represent and manipulate
ideas, facts, or concepts.

Computer
Mathematical Definition of language

• What is Symbol, Alphabet, String and Language


•Symbol: A mark, sign, or character representing an idea,
object, or concept. Symbols serve as visual shorthand,
facilitating communication through shared understanding.
•Symbol: A mark, sign, or word that conveys meaning and
represents an idea, object, or concept.

Everyday Examples of Symbols:


Traffic Signs Logos
Cont.…

• Transition to Alphabets
•An alphabet is a finite, non-empty set of symbols, where
each language has its own unique alphabet. In TPL, we
use the symbol ∑ to represent an alphabet.

•Example:
•For binary representation: ∑ = {0,1}
•For the English language: ∑ = {a, b, c, ..., z}
(In English, an alphabet consists of letters, which
collectively form a structured language system.)
Cont.…

• Examples:
• Total set of alphabets {A,B,C,D,…. Z}
• ∑ (a, b, c)
• ∑ (1 + 2 + 3) = 6 → This means adding the numbers together.

• As a Symbol:
• Mathematics & Statistics:
• ∑ (Capital Sigma) → Represents summation (sum of a series).
• Example: ∑ (1 + 2 + 3) = 6
Cont.…

• String
• A string is a sequence of symbols that belong to a given alphabet set.

• Example:
• If ∑ = {a, b}, possible strings include aabb, aa, bb, cc, dd, etc.
• In English, strings are commonly referred to as words.

• Language
•A language is defined as a set of strings.
•In natural language, it consists of a predefined set of words and follows grammar rules,
forming structured sentences.
•In programming, a program can be considered a string, and its constructs/tokens (such as
keywords, operators, and data types) function like letters or symbols in a language.
Methods to Define Language

• In natural language, we define a list of words in a dictionary because they are finite and
predefined. However, we cannot list all the possible sentences that can be formed using these
words, as the combinations are infinite.

• To manage this, we use a mechanism called grammar, which consists of rules that help determine
whether a sentence is valid or invalid.
Basic Operations on Strings

So, before we proceed further, let's do a task on strings, which will help us throughout the subject.

Length of a string: It is defined as the number of symbols in the string. It is denoted as |A|.

•Example: The length of the string |110101001| = 9.

• Now, calculate the length for the following strings:

•|aabbbcc| =

•|110011| =
Concatenation of String

Concatenation of a string: Let x and y be two strings. The concatenation of x and y is the string
formed by appending a copy of y after a copy of x.

String concatenation is not commutative, meaning wx ≠ xw in general.

Example: Let w = "code", and z = "logic"


•wz = "codelogic"
•zw = "logiccode“

If w = w₁, w₂, w₃, …, wₘ and z = z₁, z₂, z₃, …, z ₙ, then:


•|wz| = |w| + |z|
Reverse of a String

Reverse of a string: If there is a string w then reverse of a string a denoted by wr it is just the same
string but written in reverse order.

• w = w1,w2,w3 ………. wn

• wr = solution?

• |w| = |wr

• ∣w∣=∣wr∣ (The length of w and wr remains the same)


Empty/Null String

Empty/Null String- The string with zero occurrence of symbols. It is denoted by ∈,|∈|=0. If there is a
string w, then wn stands for the strings obtained by repeating w, n times.

• w3 = www

• w2 = ww

• w1 = w

• w0 =

• w∈ = ∈w =
Substring

• Substring- Any string of consecutive symbols in some string ‘w’ can be collectively said as
substring. E.g. w= abab its substrings can be ab, a, ba…etc.

S u b s t r i n g
• utg
• sbr
• rts
• str
• sub
• ∈
Examples:

• Q Consider a string ‘FINE’ find the total number of substring possible?

Substring of Substring of Substring of Substring of Substring of


length 0 length 1 length 2 length 3 length 4
Number of
string possible
SUBSTRINGS
Cont.…

• Q Consider a sting ‘TAKE’ find the total number of substring possible?

Substring of Substring of Substring of Substring of Substring of


length 0 length 1 length 2 length 3 length 4
Number of
string possible
SUBSTRINGS
Prefix and Suffix

A prefix is the beginning part of a string, while a suffix is the ending part of a string.

• Example:
• Let the string be “Hello"
• Prefixes: "", “h", “he", “hel", “hell", “hello"
• Suffixes: "", “o", “lo", “llo", “ello", “hello“

Here, "" (empty string) is always a prefix and suffix of any string.
Prefix and Suffix

• Q Consider a sting ‘HOPE’ find the total number of prefix and suffix possible?

• Prefix(HOPE) =

• Suffix(HOPE) =

You might also like