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

Lecture # 2 - Grammar & Language

gramer and engish subjects as o the dfa

Uploaded by

khhasnain303
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 views19 pages

Lecture # 2 - Grammar & Language

gramer and engish subjects as o the dfa

Uploaded by

khhasnain303
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/ 19

Welcome to !

Theory Of Automata

By Fatima Aslam

1
Introduction to Grammar

 Grammar is a mechanism to describe the languages.


 A grammar (G) is defined as a quadruple G = (V, T, S, P)
where
 V = Finite set of objects called VARIABLES
 T = Finite set of objects called TERMINAL SYMBOLS
 S ∈ V = Start variables
 P = Finite set of Productions.
 A production rule P is of the form
 X --> y

2
Example

 Given a Grammar G = ({S } , {a ,b }, S ,


P) with P defined as
 S → aSb
S → , λ
 (i) Obtain a sentence in language
generated by G and the sentential form
(form contains variables and terminals)
 (ii) Obtain the language L(G).

3
Solution

 S ⇒ aSb
S ⇒ aaSbb
 S ⇒ aabb
 Therefore we have S* ⇒ aabb.
 (i) Sentence in the language generated by
G = aabb. Sentential form = aaSbb.
 (ii) The rule S → aSb is recursive.

4
Solution continued….

 All sentential forms will have the forms


 = S
 Applying the production rule S → aSb , we
get
 S ⇒ S
 This is true for all i.
 In order to get a sentence we apply S → λ.
 Therefore we get S * ⇒ S ⇒
 Therefore L (G) = { ; n= ≥ 0}
5
Finite Automata

 Some Applications
 Software for designing and checking the
behavior of digital circuits
 Lexical analyzer of a typical compiler
 Software for scanning large bodies of text
(e.g., web pages) for pattern finding
 Software for verifying systems of all types that
have a finite number of states (e.g., stock
market transaction, communication/network
protocol)

6
Let’s begin: Finite
Automata
1
1
0
Finite Automata – Formal Definition

A finite automaton is a 5-tuple (Q, Σ, sigma, qo, F, ))

8
Finite Automata : Examples
action
 On/Off switch
state

 Modeling recognition
 of the word “then”

Start state Transition Intermediate Final state


state
9
Structural expressions

 Grammars
 Regular expressions

Start with a letter


A string of other
letters (possibly Should end w/ 2-letter state code
empty)

Other space delimited words


(part of city name) 10
Finite Automaton (FA)

 Informally, a state diagram that comprehensively


captures all possible states and transitions that a
machine can take while responding to a stream
or sequence of input symbols
 Recognizer for “Regular Languages”

 Deterministic Finite Automata (DFA)


 The machine can exist in only one state at any given
time
 Non-deterministic Finite Automata (NFA)
 The machine can exist in multiple states at the same
time

11
Deterministic Finite Automata -
Definition

 A Deterministic Finite Automaton (DFA)


consists of:
 Q ==> a finite set of states
 ∑ ==> a finite set of input symbols (alphabet)
 q0 ==> a start state
 F ==> set of accepting states
 δ ==> a transition function, which is a
mapping between Q x ∑ ==> Q
 A DFA is defined by the 5-tuple:
 {Q, ∑ , q0,F, δ }

12
What does a DFA do on reading an
input string?

 Input: a word w in ∑*
 Question: Is w acceptable by the DFA?
 Steps:
 Start at the “start state” q0
 For every input symbol in the sequence w do
 Compute the next state from the current state, given
the current input symbol in w and the transition
function
 If after all symbols in w are consumed, the
current state is one of the accepting states (F)
then accept w;
 Otherwise, reject w.
13
Example #1

 Build a DFA for the following language:


 L = {w | w is a binary string that contains 01 as a
substring}
 Steps for building a DFA to recognize L:
 ∑ = {0,1}
 Decide on the states: Q
 Designate start state and final state(s)
 δ: Decide on the transitions:
 “Final” states == same as “accepting states”
 Other states == same as “non-accepting states”

14
Input: finite string
Output: Accept or Reject

Computation process: Begin at start state,


read input symbols, follow corresponding transitions,
Accept if end with accept state, Reject if not.
 Examples: 0110 → Accept
 00101 → Reject
𝑀1 accepts exactly those strings in 𝐴

𝐴 = {𝑤| 𝑤 contains substring 11}.


where

Say that 𝐴 is the language of 𝑀1 and


15
16
Regular Languages –
Examples

𝐿 ( 𝑀1) = {𝑤| 𝑤 contains substring 11} = 𝐴

Therefore 𝐴 is regular

Goal: Understand the regular languages


9

17
 consecutive 11
 Alphabets 0,1
 Acceptance String
 011
 11
 0110
 111
 Rejection strings
 010
18
 Consecutive 11 {0,1} /bb {a,b} (3
states)
 Start a {a,b} (ab,aa, a, aaa) (b, ba, bb)
(2 state)
 End b {a,b} (2 states)

19

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy