0% found this document useful (0 votes)
33 views13 pages

Introduction and RE

Uploaded by

izharboys campus
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)
33 views13 pages

Introduction and RE

Uploaded by

izharboys campus
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/ 13

Advanced TOC

What does automata mean?


It is the plural of automaton, and it means “something that works
automatically”
Introduction to languages
There are two types of languages
Formal Languages (Syntactic languages)
Informal Languages (Semantic languages)
Alphabets
A finite non-empty set of symbols (called letters), is called an alphabet. It is
denoted by Σ ( Greek letter sigma).
Example Σ = {a,b} Σ = {0,1} (important as this is the language which the
computer understands.) Σ = {i,j,k}
Note Certain version of language ALGOL has 113 letters. Σ (alphabet) includes letters, digits and a
variety of operators including sequential operators such as GOTO and IF
Strings
Concatenation of finite number of letters from the alphabet is called a string.
Example If Σ = {a,b} then a, abab, aaabb, ababababababababab

Empty string or null string


Sometimes a string with no symbol at all is used, denoted by (Small Greek letter
Lambda) λ or (Capital Greek letter Lambda) Λ, is called an empty string or null string.
The capital lambda will mostly be used to denote the empty string, in further discussion.

Words
Words are strings belonging to some language.
Example If Σ= {x} then a language L can be defined as L={xn : n=1,2,3,…..} or L={x,xx,xxx,
….} Here x,xx,… are the words of L
All words are strings, but not all strings are words.
Valid/In-valid alphabets
While defining an alphabet, an alphabet may contain letters consisting of group of
symbols
for example Σ1= {B, aB, bab, d}.
Now consider an alphabet Σ2= {B, Ba, bab, d} and a string BababB.
This string can be tokenized in two different ways (Ba), (bab), (B) (B), (abab), (B) Which
shows that the second group cannot be identified as a string, defined over Σ = {a, b}. As
when this string is scanned by the compiler (Lexical Analyzer), first symbol B is identified
as a letter belonging to Σ, while for the second letter the lexical analyzer would not be
able to identify, so while defining an alphabet it should be kept in mind that ambiguity
should not be created.
While defining an alphabet of letters consisting of more than one symbols, no letter
should be started with the letter of the same alphabet i.e. one letter should not be the
prefix of another. However, a letter may be ended in a letter of same alphabet.
Length of Strings
The length of string s, denoted by |s|, is the number of letters in the
string.
Example Σ={a,b} s=ababa |s|=5
Example Σ= {B, aB, bab, d}
s=BaBbabBd Tokenizing=(B), (aB), (bab), (B), (d) |s|=5
Reverse of a String
The reverse of a string s denoted by Rev(s) or sr , is obtained by writing
the letters of s in reverse order.
Example If s=abc is a string defined over Σ={a,b,c} then Rev(s) or sr =
cba
Example Σ= {B, aB, bab, d}
s=BaBbabBd
Rev(s)=dBbabaBB
Defining Languages
The languages can be defined in different ways , such as Descriptive
definition, Recursive definition, using Regular Expressions(RE) and using
Finite Automaton(FA) etc.
Kleene Star Closure
Given Σ, then the Kleene Star Closure of the alphabet Σ, denoted by
Σ* , is the collection of all strings defined over Σ, including Λ. It is to be
noted that Kleene Star Closure can be defined over any set of strings.
Examples If Σ = {x} Then Σ* = {Λ, x, xx, xxx, xxxx, ….}
If Σ = {0,1} Then Σ* = {Λ, 0, 1, 00, 01, 10, 11, ….} If Σ = {aaB, c} Then Σ* =
{Λ, aaB, c, aaBaaB, aaBc, caaB, cc, ….}
Note Languages generated by Kleene Star Closure of set of strings, are
infinite languages. (By infinite language, it is supposed that the
language contains infinite many words, each of finite length).
PLUS Operation (+ )
Plus Operation is same as Kleene Star Closure except that it does not
generate Λ (null string), automatically.
Example If Σ = {0,1} Then Σ+ = {0, 1, 00, 01, 10, 11, ….} If Σ = {aab, c}
Then Σ+ = {aab, c, aabaab, aabc, caab, cc, ….}
Remark It is to be noted that Kleene Star can also be operated on any
string i.e. a * can be considered to be all possible strings defined over
{a}, which shows that a* generates Λ, a, aa, aaa, … It may also be noted
that a+ can be considered to be all possible non empty strings defined
over {a}, which shows that a+ generates a, aa, aaa, aaaa, …
Regular Expression As discussed earlier that a* generates Λ, a, aa, aaa,
… and a+ generates a, aa, aaa, aaaa, …, so the language L1 = {Λ, a, aa,
aaa, …} and L2 = {a, aa, aaa, aaaa, …} can simply be expressed by a *
and a+ , respectively. a * and a+ are called the regular expressions (RE)
for L1 and L2 respectively.
Recursive definition of Regular Expression(RE)
Step 1: Every letter of Σ including Λ is a regular expression.
Step 2: If r1 and r2 are regular expressions then (r1) r1 r2 r1 + r2 and
r1* are also regular expressions.
Step 3: Nothing else is a regular expressio
Write RE that accept all words start with “a”. Σ = {a,b}
a(a + b)*

Write RE that accept all words ends with “11”. Σ = {0,1}


(0 + 1)* 11

Write RE that accept all words must have substring“101”. Σ = {0,1}

(0 + 1)* 101 (0 + 1)*


Write RE for following
1. Even length words ( (a + b) (a + b) )*
2. Odd Length (a + b) ( (a + b) (a + b) )*
3. Length must be multiple of 3 ( (a + b) (a + b) (a + b) )*
4. Having at least 3 b’s. (a + b)*b (a + b)*b (a + b)*b (a + b)*
5. Having at most 2 b’s. λ + a* + a*b a* + a*b a*b a*
6. Having exactly 2 b’s. a*b a*b a*
7. Not have substring aa. (λ + a) (b + ba)*
8. Not ends with ba. ( a + b )* (ab + aa + bb) + λ + a + b
Some practice questions
Language 1. The language of all strings over {a, b} such that the a’s and b’s are strictly alternating.
Examples of strings in the language: ε, a, b, ab, ba, aba, bab, abab, baba
Examples of strings not in the language: bb, aa, abba
Language 2 The language of all strings over {a, b} that begin with “aba” and end with “bb”.
Language 3. The language of all strings over {a, b} which start with “a” and which do not contain the
substring “bb”.
Language 4. The language of all strings over {a, b} such that the number of as is even and the number of bs
is odd.
Examples of strings in the language: b, aab, baa, aba, aaaba, aababab
Examples of strings not in the language: ε, aa, abba, abbbabab
Language 5 Defining the language L, of strings beginning and ending in same letters , defined over Σ={a, b}
Language 6 Design RE for the following Language on the alphabet {0,1 } that have at most one “1”.
Language 7 Design RE for the following Language on the alphabet {0,1 } that have 2nd letter 0.

You might also like